113 lines
5.0 KiB
Solidity
113 lines
5.0 KiB
Solidity
pragma solidity ^0.8.1;
|
|
|
|
import "@interfaces/IRelayerRegistry.sol";
|
|
import "@interfaces/IGovernance.sol";
|
|
import "@interfaces/IERC20.sol";
|
|
|
|
import "@proprietary/Parameters.sol";
|
|
import "@proprietary/Mock.sol";
|
|
|
|
import "@root/Proposal.sol";
|
|
import "@forge-std/Test.sol";
|
|
|
|
contract ProposalTest is Test, Parameters, Mock {
|
|
|
|
modifier conditionStateChecks() {
|
|
checkParameters();
|
|
_;
|
|
checkResults();
|
|
}
|
|
|
|
function testProposal()
|
|
conditionStateChecks
|
|
public {
|
|
uint256 proposalId = voteAndCreateProposal(address(new Proposal()));
|
|
|
|
IGovernance(_governanceAddress).execute(proposalId);
|
|
}
|
|
|
|
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);
|
|
|
|
uint256 proposalId = IGovernance(_governanceAddress).propose(proposalAddress, PROPOSAL_DESCRIPTION);
|
|
|
|
// TIME-TRAVEL
|
|
vm.warp(block.timestamp + 6 hours);
|
|
|
|
IGovernance(_governanceAddress).castVote(proposalId, true);
|
|
|
|
vm.stopPrank();
|
|
/* ------------------------------ */
|
|
|
|
/* -------------VOTER-------------*/
|
|
vm.startPrank(TEST_ADDRESS_TWO);
|
|
IGovernance(_governanceAddress).castVote(proposalId, true);
|
|
vm.stopPrank();
|
|
/* ------------------------------ */
|
|
|
|
// 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]));
|
|
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[10]));
|
|
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[11]));
|
|
require(IRelayerRegistry(_registryAddress).isRelayer(VIOLATING_RELAYERS[12]));
|
|
}
|
|
|
|
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);
|
|
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[10]) == 0);
|
|
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[11]) == 0);
|
|
require(IRelayerRegistry(_registryAddress).getRelayerBalance(VIOLATING_RELAYERS[12]) == 0);
|
|
}
|
|
}
|