Skip to content

Commit

Permalink
Voting: Use shared TimeHelpersMock for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Apr 12, 2019
1 parent 18a683e commit 4981de5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 2 additions & 6 deletions apps/voting/contracts/test/mocks/VotingMock.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
pragma solidity 0.4.24;

import "../../Voting.sol";
import "@aragon/test-helpers/contracts/TimeHelpersMock.sol";


contract VotingMock is Voting {
uint64 mockTime;

function mock_setTimestamp(uint64 i) public { mockTime = i; }
function getTimestamp64() internal view returns (uint64) { return mockTime; }

contract VotingMock is Voting, TimeHelpersMock {
/* Ugly hack to work around this issue:
* https://github.com/trufflesuite/truffle/issues/569
* https://github.com/trufflesuite/truffle/issues/737
Expand Down
16 changes: 7 additions & 9 deletions apps/voting/test/voting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const sha3 = require('solidity-sha3').default

const { assertRevert } = require('@aragon/test-helpers/assertThrow')
const getBlockNumber = require('@aragon/test-helpers/blockNumber')(web3)
const { encodeCallScript, EMPTY_SCRIPT } = require('@aragon/test-helpers/evmScript')
Expand Down Expand Up @@ -63,7 +61,7 @@ contract('Voting App', accounts => {

const receipt = await dao.newAppInstance('0x1234', votingBase.address, '0x', false, { from: root })
voting = Voting.at(receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy)
await voting.mock_setTimestamp(startTime)
await voting.mockSetTimestamp(startTime)

await acl.createPermission(ANY_ADDR, voting.address, CREATE_VOTES_ROLE, root, { from: root })
await acl.createPermission(ANY_ADDR, voting.address, MODIFY_SUPPORT_ROLE, root, { from: root })
Expand Down Expand Up @@ -252,7 +250,7 @@ contract('Voting App', accounts => {
await voting.vote(voteId, true, false, { from: holder51 })
await voting.vote(voteId, true, false, { from: holder20 })
await voting.vote(voteId, false, false, { from: holder29 })
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)

const state = await voting.getVote(voteId)
assert.equal(state[4].toString(), neededSupport.toString(), 'required support in vote should stay equal')
Expand All @@ -267,7 +265,7 @@ contract('Voting App', accounts => {
// it will succeed

await voting.vote(voteId, true, true, { from: holder29 })
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)

const state = await voting.getVote(voteId)
assert.equal(state[5].toString(), minimumAcceptanceQuorum.toString(), 'acceptance quorum in vote should stay equal')
Expand Down Expand Up @@ -310,7 +308,7 @@ contract('Voting App', accounts => {
})

it('throws when voting after voting closes', async () => {
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)
return assertRevert(async () => {
await voting.vote(voteId, true, true, { from: holder29 })
})
Expand All @@ -319,14 +317,14 @@ contract('Voting App', accounts => {
it('can execute if vote is approved with support and quorum', async () => {
await voting.vote(voteId, true, true, { from: holder29 })
await voting.vote(voteId, false, true, { from: holder20 })
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)
await voting.executeVote(voteId)
assert.equal(await executionTarget.counter(), 2, 'should have executed result')
})

it('cannot execute vote if not enough quorum met', async () => {
await voting.vote(voteId, true, true, { from: holder20 })
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)
return assertRevert(async () => {
await voting.executeVote(voteId)
})
Expand All @@ -335,7 +333,7 @@ contract('Voting App', accounts => {
it('cannot execute vote if not support met', async () => {
await voting.vote(voteId, false, true, { from: holder29 })
await voting.vote(voteId, false, true, { from: holder20 })
await voting.mock_setTimestamp(votingEnd)
await voting.mockSetTimestamp(votingEnd)
return assertRevert(async () => {
await voting.executeVote(voteId)
})
Expand Down

0 comments on commit 4981de5

Please sign in to comment.