registry-penalisation-confi.../test/Proposal.t.sol

113 lines
5.0 KiB
Solidity
Raw Permalink Normal View History

2023-04-09 08:25:37 -04:00
pragma solidity ^0.8.1;
2023-04-09 13:00:43 -04:00
import "@interfaces/IRelayerRegistry.sol";
import "@interfaces/IGovernance.sol";
import "@interfaces/IERC20.sol";
2023-04-09 08:25:37 -04:00
2023-04-09 13:00:43 -04:00
import "@proprietary/Parameters.sol";
import "@proprietary/Mock.sol";
2023-04-09 08:25:37 -04:00
2023-04-09 13:00:43 -04:00
import "@root/Proposal.sol";
import "@forge-std/Test.sol";
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
contract ProposalTest is Test, Parameters, Mock {
2023-04-09 08:25:37 -04:00
2023-04-09 11:29:03 -04:00
modifier conditionStateChecks() {
2023-04-09 11:23:53 -04:00
checkParameters();
2023-04-09 11:29:03 -04:00
_;
checkResults();
}
2023-04-09 08:25:37 -04:00
2023-04-09 11:29:03 -04:00
function testProposal()
conditionStateChecks
public {
2023-04-09 11:23:53 -04:00
uint256 proposalId = voteAndCreateProposal(address(new Proposal()));
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
IGovernance(_governanceAddress).execute(proposalId);
}
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
function voteAndCreateProposal(address proposalAddress) public returns (uint256) {
retrieveAndLockBalance(TEST_PRIVATE_KEY_ONE, TEST_ADDRESS_ONE, PROPOSAL_THRESHOLD);
retrieveAndLockBalance(TEST_PRIVATE_KEY_TWO, TEST_ADDRESS_TWO, 1 ether);
/* ----------PROPOSER------------ */
vm.startPrank(TEST_ADDRESS_ONE);
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
uint256 proposalId = IGovernance(_governanceAddress).propose(proposalAddress, PROPOSAL_DESCRIPTION);
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
// TIME-TRAVEL
vm.warp(block.timestamp + 6 hours);
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
IGovernance(_governanceAddress).castVote(proposalId, true);
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
vm.stopPrank();
/* ------------------------------ */
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
/* -------------VOTER-------------*/
vm.startPrank(TEST_ADDRESS_TWO);
IGovernance(_governanceAddress).castVote(proposalId, true);
vm.stopPrank();
/* ------------------------------ */
2023-04-09 08:25:37 -04:00
2023-04-09 11:23:53 -04:00
// TIME-TRAVEL
vm.warp(block.timestamp + PROPOSAL_DURATION);
return proposalId;
}
function retrieveAndLockBalance(uint256 privateKey, address voter, uint256 amount) internal {
uint256 lockTimestamp = block.timestamp + PROPOSAL_DURATION;
bytes32 messageHash = keccak256(abi.encodePacked(
PERMIT_FUNC_SELECTOR,
EIP712_DOMAIN,
keccak256(abi.encode(PERMIT_TYPEHASH, voter, _governanceAddress, amount, 0, lockTimestamp))
));
/* ----------GOVERNANCE------- */
vm.startPrank(_governanceAddress);
IERC20(_tokenAddress).transfer(voter, amount);
vm.stopPrank();
/* ----------------------------*/
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash);
/* ----------VOTER------------ */
vm.startPrank(voter);
IGovernance(_governanceAddress).lock(voter, amount, lockTimestamp, v, r, s);
vm.stopPrank();
/* ----------------------------*/
}
function checkParameters() internal {
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[0]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[1]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[2]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[3]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[4]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[5]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[6]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[7]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[8]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[9]));
2023-04-09 13:00:43 -04:00
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[10]));
2023-04-17 16:23:41 -04:00
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[11]));
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[12]));
2023-04-09 11:23:53 -04:00
}
function checkResults() internal {
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[0]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[1]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[2]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[3]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[4]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[5]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[6]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[7]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[8]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[9]) == 0);
2023-04-09 13:00:43 -04:00
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[10]) == 0);
2023-04-17 16:23:41 -04:00
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[11]) == 0);
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[12]) == 0);
2023-04-09 11:23:53 -04:00
}
2023-04-09 08:25:37 -04:00
}