Skip to content

Commit 3708a13

Browse files
committed
adds CurseCoin contract plus one test
1 parent 3fb3062 commit 3708a13

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "openzeppelin-solidity"]
2+
path = openzeppelin-solidity
3+
url = https://github.com/OpenZeppelin/openzeppelin-solidity

contracts/CurseCoin.sol

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
pragma solidity ^0.4.2;
22

3-
contract CurseCoin {
4-
3+
// SafeMath helps prevent integer overflows
4+
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
5+
// Ownable helps streamline contract inheritance
6+
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
7+
8+
// Initiates this address as the owner
9+
contract CurseCoin is Ownable {
10+
// adds SafeMath methods to uint256 types
11+
using SafeMath for uint256;
12+
13+
string public name;
14+
string public symbol;
15+
uint256 public curseCost;
16+
17+
// Events are small empty functions that can be called as a signal or log.
18+
event Curse(address _curser, address _accursed);
19+
event Nullify(address _blessed);
20+
21+
mapping(address => bool) public unfortunates;
22+
23+
constructor() public {
24+
name = "CurseCoin";
25+
symbol = "CC";
26+
curseCost = 1 ether;
27+
}
28+
29+
// curse allows msg.sender to curse a victim if they pay the curseCost
30+
function curse(address _victim) public payable {
31+
// checks that curser is sending correct amount for cursing
32+
require((msg.value > curseCost), "You gotta pay the troll toll");
33+
34+
// first check if curse's address
35+
require((unfortunates[_victim] == false), "Victim is already cursed");
36+
37+
unfortunates[_victim] = true;
38+
emit Curse(msg.sender, _victim);
39+
}
40+
41+
// nullify allows msg.sender to uncurse themself (if applicable) if they pay the curseCost
42+
function nullify() public payable {
43+
// checks that curser is sending correct amount for uncursing
44+
require((msg.value > curseCost), "You gotta pay the uncursing troll toll");
45+
46+
// first check if curse's address
47+
require((unfortunates[msg.sender] == true), "You're not even cursed 🤔");
48+
49+
unfortunates[msg.sender] = true;
50+
emit Nullify(msg.sender);
51+
}
52+
53+
// withdraw allows the brilliant contract writers to cash out
54+
function withdraw() public onlyOwner {
55+
msg.sender.transfer(address(this).balance);
56+
}
57+
58+
// amICursed allows msg.sender to check if they're cursed
59+
function amICursed() public view returns (bool) {
60+
return unfortunates[msg.sender];
61+
}
562
}

openzeppelin-solidity

Submodule openzeppelin-solidity added at f4eb51a

test/curseCoin.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
var CurseCoin = artifacts.require("./CurseCoin.sol");
22

33
contract("CurseCoin", function (accounts) {
4-
var curseCoinInstance;
4+
var ccInstance;
5+
var curser;
6+
var victim;
57

6-
})
8+
it("allows a curser to curse a victim", function () {
9+
return CurseCoin.deployed().then(function (instance) {
10+
ccInstance = instance;
11+
curser = accounts[0];
12+
victim = accounts[1];
13+
14+
return ccInstance.curse(victim, {
15+
from: curser, value: web3.toWei('2', 'ether')
16+
}).then(function (receipt) {
17+
return ccInstance.unfortunates(victim);
18+
}).then(function (cursed) {
19+
assert(cursed, "the victim was marked as cursed");
20+
return ccInstance.unfortunates(accounts[0]);
21+
});
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)