Skip to content

Instantly share code, notes, and snippets.

@atvanguard
Last active November 5, 2018 02:13
Show Gist options
  • Save atvanguard/3e604fdfdf25fcb04f15a8f00f75e7e7 to your computer and use it in GitHub Desktop.
Save atvanguard/3e604fdfdf25fcb04f15a8f00f75e7e7 to your computer and use it in GitHub Desktop.
const LiquidDemocracy = artifacts.require("LiquidDemocracy");
contract('LiquidDemocracy', function(accounts) {
it('propose-vote-delegate-2', async function() {
let instance = await LiquidDemocracy.deployed();
let txs = [
instance.newProposal('proposal 0'),
instance.newProposal('proposal 1'),
instance.newProposal('proposal 2')
];
for (let i = 1; i < 10; i++) {
txs.push(instance.addVoter(accounts[i]))
}
await Promise.all(txs);
// delegations
await instance.delegateTo(accounts[2], {from: accounts[3]})
await instance.delegateTo(accounts[5], {from: accounts[6]})
await instance.delegateTo(accounts[7], {from: accounts[8]})
// V7 delegates to V5 creating a super proxy
await instance.delegateTo(accounts[5], {from: accounts[7]})
// V5 delegates their combined voting power to V4
await instance.delegateTo(accounts[4], {from: accounts[5]})
// Voting begins
await instance.vote(0, {from: accounts[1]}) // Yes
await instance.vote(1, {from: accounts[2]}) // No
await instance.vote(2, {from: accounts[4]}) // Maybe
await instance.vote(2, {from: accounts[9]})
// Voter 8 changes their delegation
await instance.delegateTo(accounts[2], {from: accounts[8]})
let tx = await instance.findWinningProposal()
assert.equal('Winner', tx.logs[0].event);
assert.equal('2', tx.logs[0].args.proposal.toString()); // proposal number 2
assert.equal('5', tx.logs[0].args.votes.toString()); // numVotes on winner proposal
let p0 = await instance.proposals(0);
assert.equal('1', p0[1].toString()); // proposal 0 (Yes, build the status) has 1 vote - Wah! Modiji Wah!
let p1 = await instance.proposals(1);
assert.equal('3', p1[1].toString()); // proposal 1 has 3 votes (Voter 2, 3 and 8)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment