From 5169752df743b11beb28038dde2545275f979307 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Fri, 13 Oct 2023 16:36:34 -0300 Subject: [PATCH] test/fork: Write test for feeless-votes fix --- src/test/BondingVotesFeeLessVotesFix.sol | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/test/BondingVotesFeeLessVotesFix.sol diff --git a/src/test/BondingVotesFeeLessVotesFix.sol b/src/test/BondingVotesFeeLessVotesFix.sol new file mode 100644 index 00000000..72920527 --- /dev/null +++ b/src/test/BondingVotesFeeLessVotesFix.sol @@ -0,0 +1,68 @@ +pragma solidity ^0.8.9; + +import "ds-test/test.sol"; +import "./base/GovernorBaseTest.sol"; +import "contracts/Controller.sol"; +import "contracts/bonding/BondingVotes.sol"; +import "contracts/bonding/BondingManager.sol"; +import "contracts/snapshots/MerkleSnapshot.sol"; +import "./interfaces/ICheatCodes.sol"; +import "./interfaces/IL2Migrator.sol"; + +// forge test --match-contract BondingVotesFeeLessVotesFix --fork-url https://arbitrum-mainnet.infura.io/v3/$INFURA_KEY -vvv --fork-block-number 140314540 +contract BondingVotesFeeLessVotesFix is GovernorBaseTest { + bytes public constant arithmeticError = abi.encodeWithSignature("Panic(uint256)", 0x11); + + BondingManager public constant BONDING_MANAGER = BondingManager(0x35Bcf3c30594191d53231E4FF333E8A770453e40); + IBondingVotes public constant BONDING_VOTES = IBondingVotes(0x0B9C254837E72Ebe9Fe04960C43B69782E68169A); + + bytes32 public constant BONDING_VOTES_TARGET_ID = keccak256("BondingVotesTarget"); + + BondingVotes public newBondingVotesTarget; + + address public DELEGATOR = 0xdB18A9353139880d73616e4972a855d66C9B69f0; + + event Bond( + address indexed newDelegate, + address indexed oldDelegate, + address indexed delegator, + uint256 additionalAmount, + uint256 bondedAmount + ); + + function setUp() public { + newBondingVotesTarget = new BondingVotes(address(CONTROLLER)); + } + + function doUpgrade() internal { + (, gitCommitHash) = CONTROLLER.getContractInfo(BONDING_VOTES_TARGET_ID); + + stageAndExecuteOne( + address(CONTROLLER), + 0, + abi.encodeWithSelector( + CONTROLLER.setContractInfo.selector, + BONDING_VOTES_TARGET_ID, + address(newBondingVotesTarget), + gitCommitHash + ) + ); + + // Check that new BondingVotesTarget is registered + (address infoAddr, bytes20 infoGitCommitHash) = fetchContractInfo(BONDING_VOTES_TARGET_ID); + assertEq(infoAddr, address(newBondingVotesTarget)); + assertEq(infoGitCommitHash, gitCommitHash); + } + + function testBeforeUpgrade() public { + CHEATS.expectRevert(arithmeticError); + BONDING_VOTES.getVotes(DELEGATOR); + } + + function testAfterUpgrade() public { + doUpgrade(); + + uint256 votes = BONDING_VOTES.getVotes(DELEGATOR); + assertTrue(votes > 0); + } +}