-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployment.js
177 lines (163 loc) · 5.25 KB
/
deployment.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Alethea ERC20: Deployment Tests
// Zeppelin test helpers
const {
BN,
constants,
expectEvent,
expectRevert,
} = require("@openzeppelin/test-helpers");
const {
assert,
expect,
} = require("chai");
const {
ZERO_ADDRESS,
ZERO_BYTES32,
MAX_UINT256,
} = constants;
// enable chai-subset to allow containSubset, see https://www.chaijs.com/plugins/chai-subset/
require("chai").use(require("chai-subset"));
// token constants
const {TOTAL_SUPPLY: S0} = require("./include/ali_erc20_constants");
// ALI EIP712 helpers
const {eip712_cancel} = require("./include/ali_eip712");
// deployment routines in use
const {
ali_erc20_deploy_restricted,
} = require("./include/deployment_routines");
// helper functions in use
const {
expectEventInTransaction
} = require("../include/helper");
// run ERC20 deployment tests
contract("ERC20: Deployment tests", function(accounts) {
// extract accounts to be used:
// A0 – special default zero account accounts[0] used by Truffle, reserved
// a0 – deployment account having all the permissions, reserved
// H0 – initial token holder account
const [A0, a0, H0, a1] = accounts;
// define test suite
function test_suite(suite_name, deployment_fn) {
describe(suite_name, function() {
// deploy token
let token;
beforeEach(async function() {
token = await deployment_fn.call(this, a0, H0, S0);
});
function doesnt_deploy(a0, H0) {
it("deployment reverts", async function() {
await expectRevert(ali_erc20_deploy_restricted(a0, H0), "_initialHolder not set (zero address)");
});
}
function deploys(a0, H0, S0) {
it("initial token supply is S0", async function() {
expect(await token.totalSupply(), "incorrect S0").to.be.a.bignumber.that.equals(S0);
});
it("H0 gets the entire initial balance B0 = S0", async function() {
expect(await token.balanceOf(H0), "B0 ≠ S0").to.be.a.bignumber.that.equals(S0);
});
it("H0 doesn't have a delegate", async function() {
expect(await token.votingDelegates(H0)).to.equal(ZERO_ADDRESS);
});
it("initial H0 voting power is zero", async function() {
expect(await token.votingPowerOf(H0)).to.be.a.bignumber.that.equals('0');
});
it("votingPowerHistoryOf(H0) is empty", async function() {
expect(await token.votingPowerHistoryOf(H0)).to.be.an('array').that.is.empty;
});
it("entireSupplyHistory has single element", async function() {
expect((await token.entireSupplyHistory()).length).to.equal(1);
});
it("totalSupplyHistoryLength is one", async function() {
expect(await token.totalSupplyHistoryLength()).to.be.bignumber.that.equals('1');
});
it("emits Minted event", async function() {
await expectEvent.inConstruction(token, "Minted", {
by: a0,
to: H0,
value: S0
});
});
it("emits improved Transfer event (arXiv:1907.00903)", async function() {
await expectEventInTransaction(token.transactionHash, "Transfer", [{
type: "address",
name: "by",
indexed: true,
value: a0,
}, {
type: "address",
name: "from",
indexed: true,
value: ZERO_ADDRESS,
}, {
type: "address",
name: "to",
indexed: true,
value: H0,
}, {
type: "uint256",
name: "value",
value: S0,
}]);
});
it("emits ERC20 Transfer event", async function() {
await expectEventInTransaction(
token.transactionHash, "Transfer", [{
type: "address",
name: "from",
indexed: true,
value: ZERO_ADDRESS,
}, {
type: "address",
name: "to",
indexed: true,
value: H0,
}, {
type: "uint256",
name: "value",
value: S0,
}]);
});
// 2 tests just to improve test coverage
it("coverage: decreaseAllowance(0) fails", async function() {
await expectRevert(token.decreaseAllowance(a1, 0, {from: H0}), "zero value approval decrease");
});
it("", async function() {
const w = web3.eth.accounts.create();
const {v, r, s} = await eip712_cancel(token.address, H0, ZERO_BYTES32, w.privateKey);
await expectRevert(token.cancelAuthorization(H0, ZERO_ADDRESS, v, r, s, {from: H0}), "invalid signature");
});
}
describe("when deployment arguments are incorrect", function() {
describe("when initial holder H0 is not set (zero)", function() {
// noinspection UnnecessaryLocalVariableJS
const H0 = ZERO_ADDRESS;
doesnt_deploy(a0, H0);
});
});
describe("when deployment arguments are correct", function() {
describe("when H0 is not a deployment account a0", function() {
beforeEach(async function() {
token = await deployment_fn(a0, H0);
});
it("H0 doesn't have any permissions", async function() {
expect(await token.getRole(H0)).to.be.a.bignumber.that.equals('0');
});
deploys(a0, H0, S0);
});
describe("when H0 is a0", function() {
const a0 = H0;
beforeEach(async function() {
token = await deployment_fn(a0, H0);
});
it("H0 preservers full permissions bitmask", async function() {
expect(await token.getRole(H0)).to.be.a.bignumber.that.equals(MAX_UINT256);
});
deploys(a0, H0, S0);
});
});
});
}
// run test suite
test_suite("AliERC20v2", ali_erc20_deploy_restricted);
});