120 lines
5.3 KiB
Solidity
120 lines
5.3 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.6.12;
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
import { MockProposal } from "./MockProposal.sol";
|
|
import { Staker, ITornadoStakingRewards } from "@interfaces/ITornadoStakingRewards.sol";
|
|
|
|
import { Test } from "@forge-std/Test.sol";
|
|
import "@forge-std/console2.sol";
|
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
contract TestProposal is MockProposal {
|
|
ITornadoStakingRewards staking = ITornadoStakingRewards(_stakingAddress);
|
|
|
|
function testGovernanceBalance() internal {
|
|
IERC20 TORN = IERC20(_tokenAddress);
|
|
|
|
uint256 governanceBalanceBeforeExecution = TORN.balanceOf(_governanceAddress);
|
|
console2.log("Governance balance before proposal execution: %s TORN", governanceBalanceBeforeExecution / _tornDecimals);
|
|
|
|
createAndExecuteProposal();
|
|
|
|
uint256 governanceBalanceAfterExecution = TORN.balanceOf(_governanceAddress);
|
|
console2.log("Governance balance after proposal execution: %s TORN", governanceBalanceAfterExecution / _tornDecimals);
|
|
}
|
|
|
|
function testOtherUsersRewardUnchanged() public {
|
|
uint256 rewardsBeforeProposal = staking.checkReward(TEST_REAL_ADDRESS_WITH_BALANCE);
|
|
console2.log("Developer rewards before proposal execution: %s TORN", rewardsBeforeProposal);
|
|
|
|
createAndExecuteProposal();
|
|
|
|
uint256 rewardsAfterProposal = staking.checkReward(TEST_REAL_ADDRESS_WITH_BALANCE);
|
|
console2.log("Developer rewards after proposal execution: %s TORN", rewardsBeforeProposal);
|
|
|
|
require(rewardsAfterProposal == rewardsBeforeProposal, "Other stakers rewards changed");
|
|
}
|
|
|
|
function testCannotCallSetRewardsNotFromGovernance() public executeCurrentProposalBefore {
|
|
// Trying to set rewards to myself, expect error revert call
|
|
vm.startPrank(TEST_ADDRESS_ONE);
|
|
vm.expectRevert(bytes("only governance"));
|
|
staking.setReward(TEST_ADDRESS_ONE, 100_000 ether);
|
|
vm.stopPrank();
|
|
|
|
require(staking.checkReward(TEST_ADDRESS_ONE) == 0, "Rewards accrued without permissions (not from Governance call)");
|
|
|
|
vm.startPrank(_governanceAddress);
|
|
staking.setReward(TEST_ADDRESS_ONE, 100_000 ether);
|
|
vm.stopPrank();
|
|
|
|
require(staking.checkReward(TEST_ADDRESS_ONE) == 100_000 ether, "Rewards not accrued by Governance");
|
|
}
|
|
|
|
function getStakersRewardsSum(Staker[385] memory stakers) internal returns (uint256) {
|
|
uint256 rewardsSum = 0;
|
|
for (uint16 i = 0; i < stakers.length; i++) {
|
|
rewardsSum += staking.accumulatedRewards(stakers[i].addr);
|
|
}
|
|
|
|
return rewardsSum;
|
|
}
|
|
|
|
function testVerifyStakersAccrual() internal {
|
|
Staker[385] memory stakers = getOldStakers();
|
|
|
|
uint256[385] memory rewardsBefore;
|
|
uint256[385] memory rewardsAfter;
|
|
|
|
for (uint16 i = 0; i < stakers.length; i++) {
|
|
rewardsBefore[i] = staking.accumulatedRewards(stakers[i].addr);
|
|
}
|
|
|
|
createAndExecuteProposal();
|
|
|
|
for (uint16 i = 0; i < stakers.length; i++) {
|
|
rewardsAfter[i] = staking.accumulatedRewards(stakers[i].addr);
|
|
}
|
|
|
|
for (uint16 i = 0; i < stakers.length; i++) {
|
|
console2.log("\nStaker address: %s", stakers[i].addr);
|
|
console2.log("Rewards before: %s", rewardsBefore[i]);
|
|
console2.log("Rewards after: %s", rewardsAfter[i]);
|
|
console2.log("Real difference: %s", (rewardsAfter[i] - rewardsBefore[i]));
|
|
console2.log("Expected difference: %s", stakers[i].oldRewards);
|
|
require(rewardsAfter[i] - rewardsBefore[i] == stakers[i].oldRewards);
|
|
}
|
|
}
|
|
|
|
function testStakingContractReplenishedCorrect() public {
|
|
Staker[385] memory stakers = getOldStakers();
|
|
|
|
uint256 stakersRewardsSumBeforeExecution = getStakersRewardsSum(stakers);
|
|
console2.log("Old stakers rewards sum before proposal execution: %s TORN", stakersRewardsSumBeforeExecution / _tornDecimals);
|
|
|
|
uint256 stakingContractBalanceBeforeExecution = IERC20(_tokenAddress).balanceOf(_stakingAddress);
|
|
console2.log("Staking contract balance before proposal execution: %s TORN", stakingContractBalanceBeforeExecution / _tornDecimals);
|
|
|
|
createAndExecuteProposal();
|
|
|
|
uint256 stakersRewardsSumAfterExecution = getStakersRewardsSum(stakers);
|
|
console2.log("\nOld stakers rewards sum after proposal exectuion: %s TORN", stakersRewardsSumAfterExecution / _tornDecimals);
|
|
|
|
uint256 stakingContractBalanceAfterExecution = IERC20(_tokenAddress).balanceOf(_stakingAddress);
|
|
console2.log("Staking contract balance after proposal execution: %s TORN", stakingContractBalanceAfterExecution / _tornDecimals);
|
|
|
|
uint256 stakersRewardSumDifference = stakersRewardsSumAfterExecution - stakersRewardsSumBeforeExecution;
|
|
uint256 stakingContractBalanceDifference = stakingContractBalanceAfterExecution - stakingContractBalanceBeforeExecution;
|
|
|
|
console2.log("\nStaking contract replenish amount: %s TORN", stakingContractBalanceDifference / _tornDecimals);
|
|
console2.log("Stakers restored rewards sum: %s TORN", stakersRewardSumDifference / _tornDecimals);
|
|
|
|
require(
|
|
stakersRewardSumDifference == stakingContractBalanceDifference,
|
|
"Staking replenish sum doesn't match with stakers restored rewards sum"
|
|
);
|
|
}
|
|
}
|