Commit be59af3f6ee21c7ed8efecaa9e4a6fd406639da1
working tests
Joran committed on 12/8/2016, 2:37:49 AMParent: 03738da27a3168eab56fe13eac4f0c8be67cff78
Files changed
contracts/Entropy.sol | changed |
test/Entropy_token.js | changed |
contracts/Entropy.sol | ||
---|---|---|
@@ -49,19 +49,21 @@ | ||
49 | 49 … | } |
50 | 50 … | |
51 | 51 … | |
52 | 52 … | /** |
53 | - * Creates Entropy tokens | |
53 … | + * Creates Entropy tokens for whoever called this method | |
54 | 54 … | */ |
55 | 55 … | function buyTokens() payable returns (bool success) { |
56 | 56 … | var value = msg.value; |
57 | 57 … | var buyer = msg.sender; |
58 | 58 … | if (value == 0) throw; |
59 | 59 … | |
60 | 60 … | // safety cap |
61 | - //if (getTotalValue() + value > SAFETY_LIMIT) throw; | |
61 … | + // if (getTotalValue() + value > SAFETY_LIMIT) throw; | |
62 | 62 … | |
63 | 63 … | // 1 Ether === 1 Entropy Token |
64 … | + // Solidity will floor this by default, so sending 1.9 eth will result in | |
65 … | + // 1 token | |
64 | 66 … | uint tokens = value / 1 ether; |
65 | 67 … | |
66 | 68 … | totalSupply += tokens; |
67 | 69 … | balances[buyer] += tokens; |
@@ -110,8 +112,5 @@ | ||
110 | 112 … | */ |
111 | 113 … | |
112 | 114 … | // A new guardian has been elected |
113 | 115 … | event NewGuardian(address indexed _guardian, address indexed _creator); |
114 | - | |
115 | - // Entropy Token transer | |
116 | - event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
117 | 116 … | } |
test/Entropy_token.js | ||
---|---|---|
@@ -14,22 +14,24 @@ | ||
14 | 14 … | }) |
15 | 15 … | }) |
16 | 16 … | }); |
17 | 17 … | |
18 | - describe("Buying tokens", () => { | |
19 | - it("Lets you buy tokens", function(done) { | |
18 … | + describe("Buying Entropy tokens", () => { | |
19 … | + it("Lets you buy Entropy tokens", function(done) { | |
20 | 20 … | helpers.deployEntropyContract() |
21 | 21 … | .then((entropy) => { |
22 | 22 … | // Buy with 2 Eth worth of value |
23 | - entropy.buyTokens({ from: accounts[1], value: 2e16 }) | |
24 | - .then((tx) => { | |
25 | - return entropy.balanceOf(accounts[1]) | |
23 … | + entropy.buyTokens({ from: accounts[1], value: 2e18 }) | |
24 … | + .then(() => { | |
25 … | + entropy.balanceOf.call(accounts[1]) | |
26 … | + .then((balance) => { | |
27 … | + console.log("BALANCE:::::") | |
28 … | + console.log(balance) | |
29 … | + | |
30 … | + assert.equal(balance.valueOf(), 2); | |
31 … | + done(); | |
32 … | + }) | |
26 | 33 … | }) |
27 | - .then((balance) => { | |
28 | - // Should now hold tokens! | |
29 | - assert.equal(balance.valueOf(), 2); | |
30 | - done(); | |
31 | - }) | |
32 | 34 … | }) |
33 | 35 … | }) |
34 | 36 … | }) |
35 | 37 … | }) |
Built with git-ssb-web