From 5fbeaa7a72e10eb9050ef69f52a60cc5fcba7752 Mon Sep 17 00:00:00 2001 From: Theo Date: Sun, 28 May 2023 14:54:45 +0300 Subject: [PATCH] Move tests to forge subdirectory --- remappings.txt | 2 +- test/{ => forge}/Mock.sol | 0 test/{ => forge}/MockProposal.sol | 0 test/{ => forge}/ProposalUtils.sol | 0 test/{ => forge}/TestContractsState.sol | 0 test/forge/TestGovernanceProtection.sol | 47 +++++++++++++++++++++ test/{ => forge}/TestProxyUpdated.sol | 0 test/{ => forge}/TestRelayerBalance.sol | 0 test/{ => forge}/TestRewards.sol | 0 test/{ => forge}/interfaces/IGovernance.sol | 0 10 files changed, 48 insertions(+), 1 deletion(-) rename test/{ => forge}/Mock.sol (100%) rename test/{ => forge}/MockProposal.sol (100%) rename test/{ => forge}/ProposalUtils.sol (100%) rename test/{ => forge}/TestContractsState.sol (100%) create mode 100644 test/forge/TestGovernanceProtection.sol rename test/{ => forge}/TestProxyUpdated.sol (100%) rename test/{ => forge}/TestRelayerBalance.sol (100%) rename test/{ => forge}/TestRewards.sol (100%) rename test/{ => forge}/interfaces/IGovernance.sol (100%) diff --git a/remappings.txt b/remappings.txt index 7523b20..b550a9c 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,5 +1,5 @@ @proprietary/=src/proprietary/ -@interfaces/=test/interfaces/ +@interfaces/=test/forge/interfaces/ @root/=src/ @forge-std/=lib/forge-std/src/ diff --git a/test/Mock.sol b/test/forge/Mock.sol similarity index 100% rename from test/Mock.sol rename to test/forge/Mock.sol diff --git a/test/MockProposal.sol b/test/forge/MockProposal.sol similarity index 100% rename from test/MockProposal.sol rename to test/forge/MockProposal.sol diff --git a/test/ProposalUtils.sol b/test/forge/ProposalUtils.sol similarity index 100% rename from test/ProposalUtils.sol rename to test/forge/ProposalUtils.sol diff --git a/test/TestContractsState.sol b/test/forge/TestContractsState.sol similarity index 100% rename from test/TestContractsState.sol rename to test/forge/TestContractsState.sol diff --git a/test/forge/TestGovernanceProtection.sol b/test/forge/TestGovernanceProtection.sol new file mode 100644 index 0000000..9cd69e3 --- /dev/null +++ b/test/forge/TestGovernanceProtection.sol @@ -0,0 +1,47 @@ +// 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" + ); + } +} diff --git a/test/TestProxyUpdated.sol b/test/forge/TestProxyUpdated.sol similarity index 100% rename from test/TestProxyUpdated.sol rename to test/forge/TestProxyUpdated.sol diff --git a/test/TestRelayerBalance.sol b/test/forge/TestRelayerBalance.sol similarity index 100% rename from test/TestRelayerBalance.sol rename to test/forge/TestRelayerBalance.sol diff --git a/test/TestRewards.sol b/test/forge/TestRewards.sol similarity index 100% rename from test/TestRewards.sol rename to test/forge/TestRewards.sol diff --git a/test/interfaces/IGovernance.sol b/test/forge/interfaces/IGovernance.sol similarity index 100% rename from test/interfaces/IGovernance.sol rename to test/forge/interfaces/IGovernance.sol