93 lines
2.5 KiB
Solidity
93 lines
2.5 KiB
Solidity
|
pragma solidity ^0.8.1;
|
||
|
|
||
|
import "../src/interfaces/IGovernance.sol";
|
||
|
import "../src/interfaces/IERC20.sol";
|
||
|
|
||
|
import "../src/proprietary/Parameters.sol";
|
||
|
import "../src/proprietary/Mock.sol";
|
||
|
|
||
|
import "../src/Proposal.sol";
|
||
|
import "forge-std/Test.sol";
|
||
|
|
||
|
contract ProposalTest is Test, Mock, Parameters {
|
||
|
|
||
|
function testProposal() public {
|
||
|
checkParameters();
|
||
|
|
||
|
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 {}
|
||
|
|
||
|
function checkResults() internal {}
|
||
|
|
||
|
}
|