Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements: Add test for cycling voting delegation #128

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/unit/AjnaToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,52 @@ contract AjnaTokenTest is Test {
assertEq(_token.getVotes(address(3333)), 0);
assertEq(_token.getVotes(address(4444)), 2_000_000_000 * 1e18);
}

function testCyclingVotingDelegation() external {
// define actors and set their balances
address actor1 = makeAddr("actor1");
deal(address(_token), actor1, 1_000 * 1e18);

address actor2 = makeAddr("actor2");
deal(address(_token), actor2, 2_000 * 1e18);

address actor3 = makeAddr("actor3");
deal(address(_token), actor3, 5_000 * 1e18);

// actor1 delegates votes to actor2
changePrank(actor1);
_token.delegate(actor2);

// ensure actor2 has votes equals to actor1 balance
assertEq(_token.getVotes(actor1), 0);
assertEq(_token.getVotes(actor2), 1_000 * 1e18);
assertEq(_token.getVotes(actor3), 0);

// actor2 delegates votes to actor3
changePrank(actor2);
_token.delegate(actor3);

// ensure actor3 has votes equals to actor2 balance
assertEq(_token.getVotes(actor1), 0);
assertEq(_token.getVotes(actor2), 1_000 * 1e18);
assertEq(_token.getVotes(actor3), 2_000 * 1e18);

// actor3 delegates votes to actor1
changePrank(actor3);
_token.delegate(actor1);

// ensure actor1 has votes equals to actor3 balance
assertEq(_token.getVotes(actor1), 5_000 * 1e18);
assertEq(_token.getVotes(actor2), 1_000 * 1e18);
assertEq(_token.getVotes(actor3), 2_000 * 1e18);

// actor3 delegates votes to actor2
changePrank(actor3);
_token.delegate(actor2);

// ensure actor2 has votes equals to sum of actor3 and actor1 balance
assertEq(_token.getVotes(actor1), 0);
assertEq(_token.getVotes(actor2), 6_000 * 1e18);
assertEq(_token.getVotes(actor3), 2_000 * 1e18);
}
}
Loading