git ssb

0+

dangerousbeans / Entropy_contracts



Tree: add0bd87861d967eab275b060a95b4f5576f5d59

Files: add0bd87861d967eab275b060a95b4f5576f5d59 / test / Entropy_token.js

3252 bytesRaw
1const helpers = require('./helpers');
2
3contract('Entropy - Token', (accounts) => {
4 describe("Basic", () => {
5 it("Sets valid attributes", function(done) {
6 helpers.deployEntropyContract()
7 .then((entropy) => {
8 helpers.callAndCheck( entropy, 'name', 'Entropy', 'Wrong name!')
9 helpers.callAndCheck( entropy, 'symbol', 'ENT', 'Wrong symbol!')
10 helpers.callAndCheck( entropy, 'totalSupply', 1, 'Wrong total supply!')
11 .then(() => {
12 done();
13 })
14 })
15 })
16 });
17
18 describe("Buying Entropy tokens", () => {
19 it("Lets you buy Entropy tokens", function(done) {
20 helpers.deployEntropyContract()
21 .then((entropy) => {
22 // Buy with 2 Eth worth of tokens
23 entropy.buyTokens({ from: accounts[1], value: 2e18 })
24 .then(() => {
25 entropy.balanceOf(accounts[1])
26 .then((balance) => {
27 // Should have 2 tokens
28 assert.equal(balance.valueOf(), 2);
29 done();
30 })
31 })
32 })
33 })
34
35 it("handles non integer amounts (should floor)", function(done) {
36 helpers.deployEntropyContract()
37 .then((entropy) => {
38 // Buy with 3.5 Eth worth of tokens
39 entropy.buyTokens({ from: accounts[1], value: 2500000000000000000 })
40 .then(() => {
41 entropy.balanceOf(accounts[1])
42 .then((balance) => {
43 // Should have 2 tokens
44 assert.equal(balance.valueOf(), 2);
45 done();
46 })
47 })
48 })
49 })
50 })
51
52 describe("Safety Limit", () => {
53 it("is ok near the safety limit", function(done) {
54 helpers.deployEntropyContract()
55 .then((entropy) => {
56 // Send 299 Eth
57 entropy.buyTokens({ from: accounts[0], value: 299e18 })
58 .then(() => {
59 // Buy with 1 Eth worth of tokens
60 entropy.buyTokens({ from: accounts[1], value: 1e18 })
61 .then(() => {
62 entropy.balanceOf(accounts[1])
63 .then((balance) => {
64 // Should have 2 tokens
65 assert.equal(balance.valueOf(), 1);
66 done();
67 })
68 })
69 })
70 })
71 })
72
73 it("wont go over safety limit", function(done) {
74 helpers.deployEntropyContract()
75 .then((entropy) => {
76 // Send 300 Eth
77 entropy.buyTokens({ from: accounts[0], value: 300e18 })
78 .then(() => {
79 // Buy with 1 Eth worth of tokens - should throw
80 return helpers.expectedExceptionPromise(function () {
81 return entropy.buyTokens({ from: accounts[1], gas: 3000000 });
82 }, 3000000);
83 })
84 .then(() => {
85 done();
86 })
87 })
88 })
89
90 it("lets guardians change safety limit", (done) => {
91 helpers.deployEntropyContract()
92 .then((entropy) => {
93 entropy.changeSafeyLimit(500e18)
94 .then(() => {
95 // Buy with 399 Eth worth of tokens
96 entropy.buyTokens({ value: 399e18 })
97 .then(() => {
98 entropy.balanceOf(accounts[0])
99 .then((balance) => {
100 // Should have 2 tokens
101 assert.equal(balance.valueOf(), 400);
102 done();
103 })
104 })
105 })
106 })
107 })
108 })
109})
110

Built with git-ssb-web