2023-06-10 03:14:20 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
pragma solidity ^0.6.12;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
2023-06-10 20:39:07 +03:00
|
|
|
import { IGovernance, Proposal, ProposalState } from "common/interfaces/IGovernance.sol";
|
2023-06-10 03:14:20 +03:00
|
|
|
|
|
|
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
|
|
|
|
import { Test } from "forge-std/Test.sol";
|
|
|
|
|
|
|
|
import { TornadoAddresses } from "common/TornadoAddresses.sol";
|
|
|
|
|
|
|
|
contract TornadoProposalTest is Test, TornadoAddresses {
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PERMIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
bytes32 public constant PERMIT_TYPEHASH =
|
|
|
|
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
|
|
|
|
|
|
|
|
bytes32 public 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 public constant PERMIT_FUNC_SELECTOR = uint16(0x1901);
|
|
|
|
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST DUMMIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
address public constant TEST_REAL_ADDRESS_WITH_BALANCE = 0x9Ff3C1Bea9ffB56a78824FE29f457F066257DD58;
|
|
|
|
|
|
|
|
address public constant TEST_RELAYER_ADDRESS = 0x30F96AEF199B399B722F8819c9b0723016CEAe6C; // moon-relayer.eth
|
|
|
|
// (just for testing)
|
|
|
|
|
|
|
|
uint256 public constant TEST_PRIVATE_KEY_ONE =
|
|
|
|
0x66ddbd7cbe4a566df405f6ded0b908c669f88cdb1656380c050e3a457bd21df0;
|
|
|
|
uint256 public constant TEST_PRIVATE_KEY_TWO =
|
|
|
|
0xa4c8c98120e77741a87a116074a2df4ddb20d1149069290fd4a3d7ee65c55064;
|
|
|
|
|
|
|
|
address public constant TEST_ADDRESS_ONE = 0x118251976c65AFAf291f5255450ddb5b6A4d8B88;
|
|
|
|
address public constant TEST_ADDRESS_TWO = 0x63aE7d90Eb37ca39FC62dD9991DbEfeE70673a20;
|
|
|
|
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ADDRESSES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
address public constant VERIFIER_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
|
|
|
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GOVERNANCE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
string public constant PROPOSAL_DESCRIPTION = "{title:'Some proposal',description:''}";
|
|
|
|
|
|
|
|
uint256 public EXECUTION_DELAY;
|
|
|
|
uint256 public EXECUTION_EXPIRATION;
|
|
|
|
uint256 public QUORUM_VOTES;
|
|
|
|
uint256 public PROPOSAL_THRESHOLD;
|
|
|
|
uint256 public VOTING_DELAY;
|
|
|
|
uint256 public VOTING_PERIOD;
|
|
|
|
uint256 public CLOSING_PERIOD;
|
|
|
|
uint256 public VOTE_EXTEND_TIME;
|
|
|
|
|
|
|
|
IGovernance public immutable governance = IGovernance(getGovernanceProxyAddress());
|
|
|
|
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST UTILS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
function setUp() public virtual {
|
|
|
|
vm.createSelectFork(vm.envString("MAINNET_RPC_URL"));
|
|
|
|
_fetchConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELPERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
function waitUntilExecutable(uint256 proposalId) internal {
|
|
|
|
uint256 proposalExecutableTime = getProposalExecutableTime(proposalId);
|
|
|
|
require(block.timestamp < proposalExecutableTime, "Too late to execute proposal");
|
|
|
|
vm.warp(proposalExecutableTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
function easyPropose(address proposalAddress) public returns (uint256) {
|
|
|
|
retrieveAndLockBalance(TEST_PRIVATE_KEY_ONE, TEST_ADDRESS_ONE, QUORUM_VOTES);
|
|
|
|
retrieveAndLockBalance(TEST_PRIVATE_KEY_TWO, TEST_ADDRESS_TWO, 1 ether);
|
|
|
|
|
|
|
|
/* ----------PROPOSER------------ */
|
|
|
|
vm.startPrank(TEST_ADDRESS_ONE);
|
|
|
|
|
|
|
|
uint256 proposalId = governance.propose(proposalAddress, PROPOSAL_DESCRIPTION);
|
|
|
|
|
|
|
|
// TIME-TRAVEL
|
|
|
|
vm.warp(block.timestamp + 6 hours);
|
|
|
|
|
|
|
|
governance.castVote(proposalId, true);
|
|
|
|
|
|
|
|
vm.stopPrank();
|
|
|
|
/* ------------------------------ */
|
|
|
|
|
|
|
|
/* -------------VOTER-------------*/
|
|
|
|
vm.startPrank(TEST_ADDRESS_TWO);
|
|
|
|
governance.castVote(proposalId, true);
|
|
|
|
vm.stopPrank();
|
|
|
|
/* ------------------------------ */
|
|
|
|
|
|
|
|
return proposalId;
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieveAndLockBalance(uint256, address voter, uint256 amount) internal {
|
|
|
|
/* ----------GOVERNANCE------- */
|
|
|
|
vm.startPrank(getGovernanceProxyAddress());
|
|
|
|
IERC20(getTornTokenAddress()).transfer(voter, amount);
|
|
|
|
vm.stopPrank();
|
|
|
|
/* ----------------------------*/
|
|
|
|
|
|
|
|
/* ----------VOTER------------ */
|
|
|
|
vm.startPrank(voter);
|
|
|
|
IERC20(getTornTokenAddress()).approve(address(governance), amount);
|
|
|
|
governance.lockWithApproval(amount);
|
|
|
|
vm.stopPrank();
|
|
|
|
/* ----------------------------*/
|
|
|
|
}
|
|
|
|
|
2023-06-21 00:04:29 +03:00
|
|
|
function giveTorn(address voter, uint256 amount) internal {
|
|
|
|
/* ----------GOVERNANCE------- */
|
|
|
|
vm.startPrank(getGovernanceProxyAddress());
|
|
|
|
IERC20(getTornTokenAddress()).transfer(voter, amount);
|
|
|
|
vm.stopPrank();
|
|
|
|
/* ----------------------------*/
|
|
|
|
}
|
|
|
|
|
2023-06-10 03:14:20 +03:00
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
function getProposalExecutableTime(uint256 proposalId) internal view returns (uint256) {
|
|
|
|
Proposal memory proposal = IGovernance(getGovernanceProxyAddress()).proposals(proposalId);
|
|
|
|
return proposal.endTime + EXECUTION_DELAY + 1 hours;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _fetchConfiguration() internal {
|
|
|
|
EXECUTION_DELAY = governance.EXECUTION_DELAY();
|
|
|
|
EXECUTION_EXPIRATION = governance.EXECUTION_EXPIRATION();
|
|
|
|
QUORUM_VOTES = governance.QUORUM_VOTES();
|
|
|
|
PROPOSAL_THRESHOLD = governance.PROPOSAL_THRESHOLD();
|
|
|
|
VOTING_DELAY = governance.VOTING_DELAY();
|
|
|
|
VOTING_PERIOD = governance.VOTING_PERIOD();
|
|
|
|
CLOSING_PERIOD = governance.CLOSING_PERIOD();
|
|
|
|
VOTE_EXTEND_TIME = governance.VOTE_EXTEND_TIME();
|
|
|
|
}
|
|
|
|
}
|