-
Notifications
You must be signed in to change notification settings - Fork 13
/
MintableToken.js
111 lines (85 loc) · 3.87 KB
/
MintableToken.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
const assertJump = require('./helpers/assertJump');
var MintableToken = artifacts.require('../contracts/token/MintableToken.sol');
contract('Mintable', function (accounts) {
let initialSupply = 79000000;
let firstIterationMaxSupply = 350000;
let totalSupplyLimit = 100000000;
let token;
beforeEach(async function () {
token = await MintableToken.new(
accounts[0],
initialSupply,
firstIterationMaxSupply,
totalSupplyLimit,
0,
[accounts[1], accounts[2]],
2
);
});
it('should start with a totalSupplyLimit', async function () {
assert.equal(await token.totalSupplyLimit(), totalSupplyLimit);
});
it('should start with a totalSupply', async function () {
assert.equal(await token.totalSupply(), initialSupply);
});
it('should start with a correct balance', async function () {
assert.equal(await token.balanceOf(accounts[0]), initialSupply);
});
it('should start with a correct step blocks parameter', async function () {
assert.equal(await token.numberOfBlocksBetweenSupplies(), 0);
});
it('should start with a correct current iteration', async function () {
assert.equal(await token.currentIteration(), 1);
});
it('should start with a correct next mint after block > 0', async function () {
assert.isTrue((await token.nextSupplyAfterBlock()) > 0);
});
it('should create mint failed not owner', async function () {
try {
await token.mint(accounts[0], 100, {from: accounts[6]});
} catch (error) {
return assertJump(error);
}
assert.fail('should have thrown before');
});
it('should create mint operation', async function () {
await token.mint(accounts[0], 100, {from: accounts[0]});
assert.equal(await token.totalSupply(), initialSupply);
assert.equal(await token.balanceOf(accounts[0]), initialSupply);
});
it('should create minting and confirm all owners', async function () {
await token.mint(accounts[0], 100, {from: accounts[1]});
await token.mint(accounts[0], 100, {from: accounts[2]});
assert.equal(await token.totalSupply(), initialSupply + 100);
assert.equal(await token.balanceOf(accounts[0]), initialSupply + 100);
assert.equal(await token.currentIteration(), 2);
});
it('should correct amount of supply at each iteration', async function () {
let currentySupply = firstIterationMaxSupply;
let totalSupply = initialSupply;
for (let iteration = 1; iteration < 107; iteration++) {
if (currentySupply > (totalSupplyLimit - totalSupply)) {
currentySupply = totalSupplyLimit - totalSupply;
}
assert.equal((await token.currentIterationSupplyLimit()).valueOf(), currentySupply);
await token.mint(accounts[0], currentySupply, {from: accounts[1]});
await token.mint(accounts[0], currentySupply, {from: accounts[2]});
totalSupply += currentySupply;
assert.equal((await token.totalSupply()).valueOf(), totalSupply);
assert.equal((await token.balanceOf(accounts[0])).valueOf(), totalSupply);
currentySupply = Math.floor((currentySupply * 9881653713) / 10000000000);
}
assert.equal((await token.totalSupply()).valueOf(), totalSupplyLimit);
assert.equal((await token.balanceOf(accounts[0])).valueOf(), totalSupplyLimit);
});
it('should mint failed amount of supply > max amount at iteration', async function () {
let currentySupply = 500010e18;
try {
await token.mint(accounts[0], currentySupply, {from: accounts[0]});
} catch (error) {
return assertJump(error);
}
assert.fail('should have thrown before');
});
});