Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thurendous committed Sep 10, 2024
1 parent b13b0b3 commit bbba28b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/VotingPowerExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ contract VotingPowerExchange is AccessControl, EIP712 {
return result;
}

// TODO: test this function
/**
* @notice Calculate the incremented burning amount based on the incremented voting power
* @dev This function calculates the incremented burning amount based on the incremented voting power
Expand Down
35 changes: 34 additions & 1 deletion test/integration/VotingPowerExchange.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ contract VotingPwoerExchangeTest is Test {
(bytes memory signature,) = helper.generateSignatureFromPrivateKey(
dc.DEFAULT_ANVIL_KEY2(), 1_100 * 1e18, nonce, expirationTime, address(votingPowerExchange)
);
// exchanger is exchanging the token on behalf of participant2
vm.startPrank(exchanger);
// when you exchange 1_100 utility token, you will get 11 voting power
vm.expectEmit();
Expand Down Expand Up @@ -466,7 +467,7 @@ contract VotingPwoerExchangeTest is Test {
);
}

function testExchangeHumongousAmountSuccessCase() public {
function testExchangeVotingPowerCapSuccessCase() public {
vm.prank(minter);
// user has already got 10_000 utility token
utilityToken.mint(participant2, 65_300 * 1e18);
Expand All @@ -489,6 +490,38 @@ contract VotingPwoerExchangeTest is Test {
checkExchangeResult(participant2, 99 * 1e18, 60 * 1e18, 75_240 * 1e18, participant, 0, nonce, true);
}

function testExchangeTwiceToGetToVotingPowerCapSuccessCase() public {
vm.prank(minter);
// user has already got 10_000 utility token
utilityToken.mint(participant2, 75_240 * 1e18);
bytes32 nonce = bytes32(0);
uint256 expirationTime = 3600;
(bytes memory signature,) = helper.generateSignatureFromPrivateKey(
dc.DEFAULT_ANVIL_KEY2(), 2_200 * 1e18, nonce, expirationTime, address(votingPowerExchange)
);
// exchanger is exchanging the token on behalf of participant2
vm.startPrank(exchanger);
// when you exchange 2200 utility token, you will get 16 voting power
vm.expectEmit();
emit VotingPowerExchange.VotingPowerReceived(participant2, 2_200 * 1e18, 16 * 1e18);
votingPowerExchange.exchange(participant2, 2_200 * 1e18, nonce, expirationTime, signature);
vm.stopPrank();
// check result for once
checkExchangeResult(participant2, 16 * 1e18, 85_240 * 1e18 - 2_200 * 1e18, 2_200 * 1e18, participant, 0, nonce, true);

nonce = keccak256("1");
// when you exchange 73_040 utility token, you will get 98 voting power
(bytes memory signature2,) = helper.generateSignatureFromPrivateKey(
dc.DEFAULT_ANVIL_KEY2(), 73_040 * 1e18, nonce, expirationTime, address(votingPowerExchange)
);
vm.startPrank(exchanger);
vm.expectEmit();
emit VotingPowerExchange.VotingPowerReceived(participant2, 73_040 * 1e18, 83 * 1e18);
votingPowerExchange.exchange(participant2, 73_040 * 1e18, nonce, expirationTime, signature2);
vm.stopPrank();
checkExchangeResult(participant2, 99 * 1e18, 85_240 * 1e18 - 75_240 * 1e18, 75_240 * 1e18, participant, 0, nonce, true);
}

////// test failure cases //////
function testExchangeFailsWhenSenderIsZeroAddress() public {
bytes32 nonce = bytes32(0);
Expand Down

0 comments on commit bbba28b

Please sign in to comment.