-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproposal-voting.js
114 lines (97 loc) · 3.64 KB
/
proposal-voting.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
const { expectRevert, time } = require('@openzeppelin/test-helpers');
const { BN } = require('./helpers/helper.js');
const {
proposalMinDeposit,
proposalDebatingPeriod,
lockedWaitingTime,
} = require('./helpers/constants.js');
const Treasury = artifacts.require('TestTreasury');
const votingStake = new BN(10);
let treasuryInstance;
contract(
'Treasury: proposal voting',
([
gitcoinAddress,
newClient,
proposalCreator,
voterWithFundsAvailable,
voterWithNoFundsAvailable,
]) => {
describe('GIVEN no proposals', function () {
before(async function () {
treasuryInstance = await Treasury.new(gitcoinAddress, []);
});
describe('WHEN attempting voting for a proposal', function () {
it('THEN it should fail', async function () {
await expectRevert.assertion(
treasuryInstance.vote(0, true, { from: voterWithFundsAvailable })
);
});
});
});
describe('GIVEN a proposal for a new client', function () {
const proposalID = 0;
beforeEach(async function () {
treasuryInstance = await Treasury.new(gitcoinAddress, []);
await treasuryInstance.lockFunds({ value: votingStake, from: voterWithFundsAvailable });
await time.increase(lockedWaitingTime);
await treasuryInstance.proposeAddClient(newClient, {
from: proposalCreator,
value: proposalMinDeposit,
});
});
describe('WHEN voting in favor', function () {
beforeEach(async function () {
await treasuryInstance.vote(proposalID, true, { from: voterWithFundsAvailable });
});
it('THEN it should reflected it on the status', async function () {
const proposalState = await treasuryInstance.getProposalState.call(proposalID);
const approvalVotes = votingStake.add(proposalMinDeposit);
proposalState.approvalVotes.should.be.bignumber.equal(approvalVotes);
});
});
describe('WHEN unvoting', function () {
beforeEach(async function () {
await treasuryInstance.vote(proposalID, true, { from: voterWithFundsAvailable });
await treasuryInstance.unvote(proposalID, { from: voterWithFundsAvailable });
});
it('THEN it should reflected it on the status', async function () {
const proposalState = await treasuryInstance.getProposalState.call(proposalID);
proposalState.approvalVotes.should.be.bignumber.equal(proposalMinDeposit);
});
});
describe('WHEN debating period has ended', function () {
beforeEach(async function () {
await time.increase(2 * proposalDebatingPeriod);
});
it('THEN voting should fail', async function () {
await expectRevert(
treasuryInstance.vote(proposalID, true, {
from: voterWithFundsAvailable,
}),
'Debating period ended'
);
});
it('THEN unvoting should fail', async function () {
await expectRevert(
treasuryInstance.unvote(proposalID, {
from: voterWithFundsAvailable,
}),
'Debating period ended'
);
});
});
describe('WHEN not enough funds are locked', function () {
it('THEN voting should fail', async function () {
await treasuryInstance.lockFunds({ value: votingStake, from: voterWithNoFundsAvailable });
await expectRevert(
treasuryInstance.vote(proposalID, true, {
from: voterWithNoFundsAvailable,
}),
'No unlocked funds available for usage'
);
});
});
});
}
);