gov test env & remove old module

This commit is contained in:
gozzy 2023-04-09 17:10:49 +00:00
parent 5b13dfe581
commit 860b9d4111
5 changed files with 134 additions and 5 deletions

4
.gitmodules vendored
View File

@ -2,10 +2,6 @@
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.5.1
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/paulRBerg/prb-math
branch = v3
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts

@ -1 +0,0 @@
Subproject commit 9febcdd219f08f7fb70fdf0e156f1be4103c42dd

35
src/proprietary/Mock.sol Normal file
View File

@ -0,0 +1,35 @@
pragma solidity ^0.8.1;
contract Mock {
uint256 constant TEST_PRIVATE_KEY_ONE = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
uint256 constant TEST_PRIVATE_KEY_TWO = 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d;
address constant TEST_ADDRESS_ONE = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
address constant TEST_ADDRESS_TWO = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8;
uint256 constant PROPOSAL_DURATION = 7 days;
uint256 constant PROPOSAL_THRESHOLD = 25000 ether;
string constant PROPOSAL_DESCRIPTION = "Proposal #15: Renumeration and accounting";
address constant VERIFIER_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
bytes32 constant PERMIT_TYPEHASH = keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
bytes32 constant EIP712_DOMAIN = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes("TornadoCash")),
keccak256(bytes("1")),
1,
VERIFIER_ADDRESS
)
);
uint16 constant PERMIT_FUNC_SELECTOR = uint16(0x1901);
address constant _tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
address constant _governanceAddress = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
}

View File

@ -0,0 +1,14 @@
pragma solidity ^0.8.1;
contract Parameters {
uint256 VESTING_PERIOD = 10 weeks;
uint256 AUCTION_START_TS = block.timestamp;
uint256 AUCTION_END_TS = AUCTION_START_TS + 1 weeks;
uint256 AUCTION_ORIGIN_PRICE = 4172000 gwei;
uint256 AUCTION_RESERVE_AMOUNT = 100000 ether;
uint256 AUCTION_PROVISION_AMOUNT = 100000 ether;
uint256 AUCTION_MINIMUM_AMOUNT = 1 ether;
uint256 AUCTION_WINDOW_LENGTH = 8 hours;
}

85
test/Proposal.t.sol Normal file
View File

@ -0,0 +1,85 @@
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 { }
function checkResults() internal { }
}