-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-simple-voter.js
49 lines (37 loc) · 1.49 KB
/
test-simple-voter.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
const SimpleVoter = artifacts.require('SimpleVoter.sol');
contract ('SimpleVoter contract', (accounts) => {
let simpleVoter;
// Reset state before each run
beforeEach('create a new contract for each test', async () => {
simpleVoter = await SimpleVoter.new();
})
describe('Simple Voter', () => {
it('no votes to begin with', async () => {
let result;
result = await simpleVoter.yeses();
assert.equal(result, "0", 'should be zero YES votes');
result = await simpleVoter.nos();
assert.equal(result, "0", 'should be zero NO votes');
});
it('Should vote successfully', async () => {
let result;
result = await simpleVoter.castVote(true);
result = await simpleVoter.yeses();
assert.equal(result, 1, 'one yes vote');
result = await simpleVoter.nos();
assert.equal(result, 0, 'zero no votes');
});
it('Should not allow multiple votes', async () => {
let result;
try {
result = await simpleVoter.castVote(true);
result = await simpleVoter.castVote(true);
} catch (err) {
// assert that we caught an exception
assert(true, err.toString().includes('revert'), 'expected second vote to revert');
return;
}
assert(false, 'did not catch expected exception');
});
});
});