From 9995638a1ce9cb7a6676d3e8a1ab85629798fb28 Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 27 May 2023 14:31:22 +0300 Subject: [PATCH] Added tests to verify that updated contracts have the correct internal state --- test/TestContractsState.sol | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/TestContractsState.sol diff --git a/test/TestContractsState.sol b/test/TestContractsState.sol new file mode 100644 index 0000000..b57f583 --- /dev/null +++ b/test/TestContractsState.sol @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +import { MockProposal } from "./MockProposal.sol"; +import { console2 } from "@forge-std/console2.sol"; +import { GovernancePatchUpgrade } from "@root/v4-patch/GovernancePatchUpgrade.sol"; +import { RelayerRegistry } from "@root/v4-patch/RelayerRegistry.sol"; +import { TornadoStakingRewards } from "@root/v4-patch/TornadoStakingRewards.sol"; + +contract TestContractsState is MockProposal { + function testLockedBalanceSaved() public { + uint256 lockedBalanceBeforeExecution = governance.lockedBalance(TEST_REAL_ADDRESS_WITH_BALANCE); + console2.log("User locked balance before execution: %s TORN", lockedBalanceBeforeExecution / 10 ** 18); + + createAndExecuteProposal(); + + uint256 lockedBalanceAfterExecution = governance.lockedBalance(TEST_REAL_ADDRESS_WITH_BALANCE); + console2.log("User locked balance before execution: %s TORN", lockedBalanceAfterExecution / 10 ** 18); + + require(lockedBalanceBeforeExecution == lockedBalanceAfterExecution, "Wrong locked balance after execution"); + } + + function testGovernanceStakingStateChanged() public { + TornadoStakingRewards oldStaking = TornadoStakingRewards(getStakingProxyAddress()); + uint256 accumulatedRewardsBeforeExecution = oldStaking.checkReward(TEST_REAL_ADDRESS_WITH_BALANCE); + console2.log("User rewards balance (bugged) before execution: %s TORN", accumulatedRewardsBeforeExecution / 10 ** 18); + console2.log("Bugged value of accumulated rewards per TORN: %s", oldStaking.accumulatedRewardPerTorn()); + + createAndExecuteProposal(); + + TornadoStakingRewards newStaking = TornadoStakingRewards(getStakingProxyAddress()); + uint256 accumulatedRewardsPerTORNAfterExecution = newStaking.accumulatedRewardPerTorn(); + uint256 accumulatedRewardsAfterExecution = newStaking.checkReward(TEST_REAL_ADDRESS_WITH_BALANCE); + + console2.log("User rewards balance before execution: %s TORN", accumulatedRewardsAfterExecution / 10 ** 18); + console2.log("Value of accumulated rewards per TORN after contract redeployment: %s", accumulatedRewardsPerTORNAfterExecution); + + require(accumulatedRewardsBeforeExecution >= accumulatedRewardsAfterExecution, "Wtf"); + require(accumulatedRewardsAfterExecution == 0, "Accumulated rewards isn't nullified"); + require(accumulatedRewardsPerTORNAfterExecution == 0, "Accumulated rewards per TORN isn't nullified"); + } + + function testRelayerRegistryStateSaved() public { + RelayerRegistry registry = RelayerRegistry(getRelayerRegistryProxyAddress()); + + bool isRelayerRegisteredBeforeExecution = registry.isRelayer(TEST_RELAYER_ADDRESS); + uint256 relayerStakedBalanceBeforeExecution = registry.getRelayerBalance(TEST_RELAYER_ADDRESS); + console2.log( + "Relayer balance in relayer registry contract before proposal execution: %s TORN", + relayerStakedBalanceBeforeExecution / 10 ** 18 + ); + + require(isRelayerRegisteredBeforeExecution, "Relayer not registered"); + + createAndExecuteProposal(); + + bool isRelayerRegisteredAfterExecution = registry.isRelayer(TEST_RELAYER_ADDRESS); + uint256 relayerStakedBalanceAfterExecution = registry.getRelayerBalance(TEST_RELAYER_ADDRESS); + + console2.log( + "Relayer balance in relayer registry contract after proposal execution: %s TORN", relayerStakedBalanceAfterExecution / 10 ** 18 + ); + + require(isRelayerRegisteredAfterExecution, "Relayer isn't registered after proposal execution"); + require(relayerStakedBalanceBeforeExecution == relayerStakedBalanceAfterExecution, "Relayer stake balance differs after execution"); + } +}