Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic contract #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions TCI examples/Magic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Magic
[![Node version](https://img.shields.io/badge/node-10.16.3-blue.svg?style=popout&maxAge=3600)](https://nodejs.org/en/)
[![NPM version](https://img.shields.io/badge/npm-6.9.0-orange.svg?style=popout&maxAge=3600)](https://nodejs.org/en/)
[![Solidity version](https://img.shields.io/badge/Solidity-v0.5.8-ff69b4.svg?style=popout&maxAge=3600)](https://solidity.readthedocs.io/en/v0.4.24/installing-solidity.html)

### Install
```
npm install --save-dev solidity-coverage
```

### Run
```
sudo npx solidity-coverage
```

### Result
![inheritance graph](https://github.com/hannnnk1231/TCI/blob/master/Magic/test%20coverage.png)
2,953 changes: 2,953 additions & 0 deletions TCI examples/Magic/build/contracts/Magic.json

Large diffs are not rendered by default.

1,293 changes: 1,293 additions & 0 deletions TCI examples/Magic/build/contracts/MagicAct.json

Large diffs are not rendered by default.

1,392 changes: 1,392 additions & 0 deletions TCI examples/Magic/build/contracts/Migrations.json

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions TCI examples/Magic/contracts/Magic.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
pragma solidity >=0.4.24 <0.6.0;

contract Magic {

address payable public magician;
uint cooldownTime = 1 days;

struct Audiences {
uint donation;
uint32 [4] cooldown;
}

mapping (address=>Audiences) public audience;

constructor() payable public {
magician = msg.sender;
}

modifier checkEnoughDonation(uint _price) {
require(audience[msg.sender].donation >= _price);
_;
}

modifier checkCoolDown(uint _type) {
require(audience[msg.sender].cooldown[_type] <= now);
_;
}

function donate() payable public {
audience[msg.sender].donation+=msg.value;
}

function getMagician() public view returns(address) {
return magician;
}

function getDonation(address _audience) public view returns(uint){
return audience[_audience].donation;
}

function getCooldownTime(uint _type) public view returns(uint32){
return audience[msg.sender].cooldown[_type];
}

function _triggerCooldown(uint _type) internal {
audience[msg.sender].cooldown[_type] += uint32(now + cooldownTime);
}
}
26 changes: 26 additions & 0 deletions TCI examples/Magic/contracts/MagicAct.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pragma solidity >=0.4.24 <0.6.0;

import "./Magic.sol";

contract MagicAct is Magic {

event Act(uint _type);

// type 1: Card trick, 2:Party show, 3: Stage magic, 4: Illution
function act(uint _type) public checkEnoughDonation(_type*100) checkCoolDown(_type) {
_triggerCooldown(_type);
payMagician(_type);
emit Act(_type);
}

function freeAct(uint _type) public checkCoolDown(_type) {
_triggerCooldown(_type);
emit Act(_type);
}

function payMagician(uint _type) public payable{
uint charge=_type*100 finney;
magician.transfer(charge);
audience[msg.sender].donation-=charge;
}
}
23 changes: 23 additions & 0 deletions TCI examples/Magic/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity >=0.4.21 <0.6.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
1 change: 1 addition & 0 deletions TCI examples/Magic/coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contracts/Magic.sol":{"l":{"16":8,"20":2,"21":1,"25":3,"26":2,"30":2,"34":6,"38":4,"42":1,"46":2},"path":"/Users/hank/Desktop/CS/Blockchain/TCI/Magic/contracts/Magic.sol","s":{"1":8,"2":2,"3":3,"4":2,"5":6,"6":4,"7":1,"8":2},"b":{"1":[1,1],"2":[2,1]},"f":{"1":8,"2":2,"3":3,"4":2,"5":6,"6":4,"7":1,"8":2},"fnMap":{"1":{"name":"constructor","line":15,"loc":{"start":{"line":15,"column":1},"end":{"line":15,"column":30}}},"2":{"name":"checkEnoughDonation","line":19,"loc":{"start":{"line":19,"column":1},"end":{"line":19,"column":43}}},"3":{"name":"checkCoolDown","line":24,"loc":{"start":{"line":24,"column":1},"end":{"line":24,"column":36}}},"4":{"name":"donate","line":29,"loc":{"start":{"line":29,"column":1},"end":{"line":29,"column":34}}},"5":{"name":"getMagician","line":33,"loc":{"start":{"line":33,"column":3},"end":{"line":33,"column":53}}},"6":{"name":"getDonation","line":37,"loc":{"start":{"line":37,"column":3},"end":{"line":37,"column":66}}},"7":{"name":"getCooldownTime","line":41,"loc":{"start":{"line":41,"column":3},"end":{"line":41,"column":65}}},"8":{"name":"_triggerCooldown","line":45,"loc":{"start":{"line":45,"column":3},"end":{"line":45,"column":48}}}},"statementMap":{"1":{"start":{"line":16,"column":2},"end":{"line":16,"column":22}},"2":{"start":{"line":20,"column":2},"end":{"line":20,"column":49}},"3":{"start":{"line":25,"column":2},"end":{"line":25,"column":53}},"4":{"start":{"line":30,"column":7},"end":{"line":30,"column":46}},"5":{"start":{"line":34,"column":2},"end":{"line":34,"column":17}},"6":{"start":{"line":38,"column":4},"end":{"line":38,"column":39}},"7":{"start":{"line":42,"column":2},"end":{"line":42,"column":45}},"8":{"start":{"line":46,"column":4},"end":{"line":46,"column":69}}},"branchMap":{"1":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":2},"end":{"line":20,"column":2}},{"start":{"line":20,"column":2},"end":{"line":20,"column":2}}]},"2":{"line":25,"type":"if","locations":[{"start":{"line":25,"column":2},"end":{"line":25,"column":2}},{"start":{"line":25,"column":2},"end":{"line":25,"column":2}}]}}},"contracts/MagicAct.sol":{"l":{"11":1,"12":1,"13":1,"17":1,"18":1,"22":2,"23":2,"24":2},"path":"/Users/hank/Desktop/CS/Blockchain/TCI/Magic/contracts/MagicAct.sol","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":2,"7":2,"8":2},"b":{},"f":{"1":1,"2":1,"3":2},"fnMap":{"1":{"name":"act","line":10,"loc":{"start":{"line":10,"column":1},"end":{"line":10,"column":85}}},"2":{"name":"freeAct","line":16,"loc":{"start":{"line":16,"column":1},"end":{"line":16,"column":58}}},"3":{"name":"payMagician","line":21,"loc":{"start":{"line":21,"column":3},"end":{"line":21,"column":48}}}},"statementMap":{"1":{"start":{"line":11,"column":2},"end":{"line":11,"column":24}},"2":{"start":{"line":12,"column":2},"end":{"line":12,"column":19}},"3":{"start":{"line":13,"column":2},"end":{"line":13,"column":17}},"4":{"start":{"line":17,"column":2},"end":{"line":17,"column":24}},"5":{"start":{"line":18,"column":2},"end":{"line":18,"column":17}},"6":{"start":{"line":22,"column":4},"end":{"line":22,"column":32}},"7":{"start":{"line":23,"column":4},"end":{"line":23,"column":28}},"8":{"start":{"line":24,"column":4},"end":{"line":24,"column":40}}},"branchMap":{}}}
213 changes: 213 additions & 0 deletions TCI examples/Magic/coverage/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
body, html {
margin:0; padding: 0;
height: 100%;
}
body {
font-family: Helvetica Neue, Helvetica, Arial;
font-size: 14px;
color:#333;
}
.small { font-size: 12px; }
*, *:after, *:before {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
h1 { font-size: 20px; margin: 0;}
h2 { font-size: 14px; }
pre {
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
margin: 0;
padding: 0;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
a { color:#0074D9; text-decoration:none; }
a:hover { text-decoration:underline; }
.strong { font-weight: bold; }
.space-top1 { padding: 10px 0 0 0; }
.pad2y { padding: 20px 0; }
.pad1y { padding: 10px 0; }
.pad2x { padding: 0 20px; }
.pad2 { padding: 20px; }
.pad1 { padding: 10px; }
.space-left2 { padding-left:55px; }
.space-right2 { padding-right:20px; }
.center { text-align:center; }
.clearfix { display:block; }
.clearfix:after {
content:'';
display:block;
height:0;
clear:both;
visibility:hidden;
}
.fl { float: left; }
@media only screen and (max-width:640px) {
.col3 { width:100%; max-width:100%; }
.hide-mobile { display:none!important; }
}

.quiet {
color: #7f7f7f;
color: rgba(0,0,0,0.5);
}
.quiet a { opacity: 0.7; }

.fraction {
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-size: 10px;
color: #555;
background: #E8E8E8;
padding: 4px 5px;
border-radius: 3px;
vertical-align: middle;
}

div.path a:link, div.path a:visited { color: #333; }
table.coverage {
border-collapse: collapse;
margin: 10px 0 0 0;
padding: 0;
}

table.coverage td {
margin: 0;
padding: 0;
vertical-align: top;
}
table.coverage td.line-count {
text-align: right;
padding: 0 5px 0 20px;
}
table.coverage td.line-coverage {
text-align: right;
padding-right: 10px;
min-width:20px;
}

table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 100%;
}
.missing-if-branch {
display: inline-block;
margin-right: 5px;
border-radius: 3px;
position: relative;
padding: 0 4px;
background: #333;
color: yellow;
}

.skip-if-branch {
display: none;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: #ccc;
color: white;
}
.missing-if-branch .typ, .skip-if-branch .typ {
color: inherit !important;
}
.coverage-summary {
border-collapse: collapse;
width: 100%;
}
.coverage-summary tr { border-bottom: 1px solid #bbb; }
.keyline-all { border: 1px solid #ddd; }
.coverage-summary td, .coverage-summary th { padding: 10px; }
.coverage-summary tbody { border: 1px solid #bbb; }
.coverage-summary td { border-right: 1px solid #bbb; }
.coverage-summary td:last-child { border-right: none; }
.coverage-summary th {
text-align: left;
font-weight: normal;
white-space: nowrap;
}
.coverage-summary th.file { border-right: none !important; }
.coverage-summary th.pct { }
.coverage-summary th.pic,
.coverage-summary th.abs,
.coverage-summary td.pct,
.coverage-summary td.abs { text-align: right; }
.coverage-summary td.file { white-space: nowrap; }
.coverage-summary td.pic { min-width: 120px !important; }
.coverage-summary tfoot td { }

.coverage-summary .sorter {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
}
.coverage-summary .sorted .sorter {
background-position: 0 -20px;
}
.coverage-summary .sorted-desc .sorter {
background-position: 0 -10px;
}
.status-line { height: 10px; }
/* dark red */
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
.low .chart { border:1px solid #C21F39 }
/* medium red */
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
/* light red */
.low, .cline-no { background:#FCE1E5 }
/* light green */
.high, .cline-yes { background:rgb(230,245,208) }
/* medium green */
.cstat-yes { background:rgb(161,215,106) }
/* dark green */
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
.high .chart { border:1px solid rgb(77,146,33) }
/* dark yellow (gold) */
.medium .chart { border:1px solid #f9cd0b; }
.status-line.medium, .medium .cover-fill { background: #f9cd0b; }
/* light yellow */
.medium { background: #fff4c2; }
/* light gray */
span.cline-neutral { background: #eaeaea; }

.cbranch-no { background: yellow !important; color: #111; }

.cstat-skip { background: #ddd; color: #111; }
.fstat-skip { background: #ddd; color: #111 !important; }
.cbranch-skip { background: #ddd !important; color: #111; }


.cover-fill, .cover-empty {
display:inline-block;
height: 12px;
}
.chart {
line-height: 0;
}
.cover-empty {
background: white;
}
.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
.ignore-none { color: #999; font-weight: normal; }

.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -48px;
}
.footer, .push {
height: 48px;
}
Loading