48 lines
2.0 KiB
Solidity
48 lines
2.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.6.12;
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
import { console2 } from "@forge-std/console2.sol";
|
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
import { MockProposal } from "./MockProposal.sol";
|
|
import { Mock } from "./Mock.sol";
|
|
import { Parameters } from "@proprietary/Parameters.sol";
|
|
import { GovernancePatchUpgrade } from "@root/v4-patch/GovernancePatchUpgrade.sol";
|
|
|
|
contract DummyProposal is Parameters, Mock {
|
|
address private fundingAddress;
|
|
uint256 private fundingAmount;
|
|
|
|
constructor(address _fundingAddress, uint256 _fundingAmount) public {
|
|
fundingAddress = _fundingAddress;
|
|
fundingAmount = _fundingAmount;
|
|
}
|
|
|
|
function executeProposal() public {
|
|
// Easy-to-check after execution
|
|
IERC20(_tokenAddress).transfer(TEST_ADDRESS_ONE, 1_000_000 ether);
|
|
}
|
|
}
|
|
|
|
contract TestGovernanceProtection is MockProposal {
|
|
function testNewDummyProposal() public executeAttackerProposalBefore executeCurrentProposalBefore {
|
|
IERC20 TORN = IERC20(_tokenAddress);
|
|
|
|
uint256 amountToTransfer = 1_000_000 ether;
|
|
|
|
uint256 testAccountBalanceBeforeDummyProposal = TORN.balanceOf(TEST_ADDRESS_ONE);
|
|
console2.log("Account balance before dummy proposal exectuion: %s TORN", testAccountBalanceBeforeDummyProposal / _tornDecimals);
|
|
|
|
vm.warp(block.timestamp + PROPOSAL_EXECUTION_MAX_DURATION);
|
|
proposeAndExecute(address(new DummyProposal(TEST_ADDRESS_ONE, amountToTransfer)));
|
|
|
|
uint256 testAccountBalanceAfterDummyProposal = TORN.balanceOf(TEST_ADDRESS_ONE);
|
|
console2.log("Account balance after dummy proposal exectuion: %s TORN", testAccountBalanceAfterDummyProposal / _tornDecimals);
|
|
|
|
require(
|
|
testAccountBalanceAfterDummyProposal - testAccountBalanceBeforeDummyProposal == amountToTransfer,
|
|
"Dummy proposal executed incorrectly"
|
|
);
|
|
}
|
|
}
|