Skip to content

Commit

Permalink
Add voting happy path test
Browse files Browse the repository at this point in the history
  • Loading branch information
elenadimitrova committed Jan 23, 2023
1 parent 0ca0268 commit 9ea5310
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions contracts/governance/test/ZeroExGovernor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,51 @@ import "../src/ZeroExTimelock.sol";
import "../src/ZeroExGovernor.sol";
import "../src/ZRXWrappedToken.sol";
import "@openzeppelin/token/ERC20/ERC20.sol";
import "@openzeppelin/mocks/CallReceiverMock.sol";

contract ZeroExGovernorTest is BaseTest {
IERC20 public token;
ZRXWrappedToken public wToken;
ZeroExTimelock public timelock;
ZeroExGovernor public governor;
ZRXWrappedToken internal wToken;
ZeroExTimelock internal timelock;
ZeroExGovernor internal governor;
CallReceiverMock internal callReceiverMock;

function setUp() public {
vm.startPrank(account1);
token = IERC20(createZRXToken());
token.transfer(account2, 100e18);
token.transfer(account3, 200e18);
token.transfer(account4, 50e18);

wToken = new ZRXWrappedToken(token);
vm.stopPrank();

// Setup accounts 2,3 and 4 to vote
vm.startPrank(account2);
token.approve(address(wToken), 100e18);
wToken.depositFor(account2, 100e18);
wToken.delegate(account2);
vm.stopPrank();

vm.startPrank(account3);
token.approve(address(wToken), 200e18);
wToken.depositFor(account3, 200e18);
wToken.delegate(account3);
vm.stopPrank();

vm.startPrank(account4);
token.approve(address(wToken), 50e18);
wToken.depositFor(account4, 50e18);
wToken.delegate(account4);
vm.stopPrank();

address[] memory proposers = new address[](0);
address[] memory executors = new address[](0);
timelock = new ZeroExTimelock(7 days, proposers, executors);

governor = new ZeroExGovernor(wToken, timelock);
vm.stopPrank();

callReceiverMock = new CallReceiverMock();
}

function testShouldReturnCorrectName() public {
Expand Down Expand Up @@ -73,4 +97,41 @@ contract ZeroExGovernorTest is BaseTest {
function testShouldReturnCorrectTimelock() public {
assertEq(address(governor.timelock()), address(timelock));
}

function testShouldBeAbleToSubmitAProposal() public {
// Create a proposal
address[] memory targets = new address[](1);
targets[0] = address(callReceiverMock);

uint256[] memory values = new uint256[](1);
values[0] = 0;

bytes[] memory calldatas = new bytes[](1);
calldatas[0] = abi.encodeWithSignature("mockFunction()");

uint256 proposalId = governor.propose(targets, values, calldatas, "<proposal description>");

// Fast forward to after vote start
vm.roll(governor.proposalSnapshot(proposalId) + 1);

// Vote
vm.prank(account2);
governor.castVote(proposalId, 0); // Vote "against"
vm.stopPrank();
vm.prank(account3);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
vm.prank(account4);
governor.castVote(proposalId, 2); // Vote "abstain"
vm.stopPrank();

// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId));

// Get vote results
(uint256 votesAgainst, uint256 votesFor, uint256 votesAbstain) = governor.proposalVotes(proposalId);
assertEq(votesAgainst, 100e18);
assertEq(votesFor, 200e18);
assertEq(votesAbstain, 50e18);
}
}

0 comments on commit 9ea5310

Please sign in to comment.