From 06c241b4fbeea06b0e6dcc581a9101c876431ae1 Mon Sep 17 00:00:00 2001 From: keating Date: Tue, 2 Jan 2024 10:58:31 -0500 Subject: [PATCH] Fix tests --- script/WormholeL2FlexibleVotingDeploy.s.sol | 3 ++- src/L2GovernorMetadata.sol | 2 +- src/L2VoteAggregator.sol | 5 ++--- src/WormholeL2VoteAggregator.sol | 5 +++-- .../WormholeL2GovernorMetadataOptimized.sol | 4 ++-- .../WormholeL2VoteAggregatorCalldataCompressor.sol | 6 ++++-- test/L2VoteAggregator.t.sol | 3 ++- test/WormholeL1GovernorMetadataBridge.t.sol | 5 +++-- test/WormholeL1VotePool.t.sol | 3 ++- test/WormholeL2GovernorMetadata.t.sol | 7 ++++--- test/WormholeL2VoteAggregator.t.sol | 6 ++++-- test/harness/WormholeL2VoteAggregatorHarness.sol | 6 ++++-- .../WormholeL2GovernorMetadataOptimizedHarness.sol | 2 +- test/mock/GovernorMetadataMock.sol | 6 ++++-- .../WormholeL2VoteAggregatorCalldataCompressor.t.sol | 12 ++++++++---- 15 files changed, 46 insertions(+), 29 deletions(-) diff --git a/script/WormholeL2FlexibleVotingDeploy.s.sol b/script/WormholeL2FlexibleVotingDeploy.s.sol index db7022e3..0088d855 100644 --- a/script/WormholeL2FlexibleVotingDeploy.s.sol +++ b/script/WormholeL2FlexibleVotingDeploy.s.sol @@ -113,7 +113,8 @@ contract WormholeL2FlexibleVotingDeploy is Script, ScriptConstants { l1BlockAddress, L2_CHAIN.wormholeChainId, L1_CHAIN.wormholeChainId, - vm.envOr("CONTRACT_OWNER", msg.sender) + vm.envOr("CONTRACT_OWNER", msg.sender), + uint32(vm.envOr("CAST_WINDOW", uint256(1200))) ); vm.broadcast(); diff --git a/src/L2GovernorMetadata.sol b/src/L2GovernorMetadata.sol index c46d67a3..65301052 100644 --- a/src/L2GovernorMetadata.sol +++ b/src/L2GovernorMetadata.sol @@ -57,7 +57,7 @@ abstract contract L2GovernorMetadata { /// @param _l1BlockAddress The address of the L1Block contract. constructor(address _l1BlockAddress, uint32 castWindow) { L1_BLOCK = IL1Block(_l1BlockAddress); - CAST_VOTE_WINDOW = castWindow; + CAST_VOTE_WINDOW = castWindow; } /// @notice Add proposal to internal storage. diff --git a/src/L2VoteAggregator.sol b/src/L2VoteAggregator.sol index b205c50c..94299f2a 100644 --- a/src/L2VoteAggregator.sol +++ b/src/L2VoteAggregator.sol @@ -276,8 +276,7 @@ abstract contract L2VoteAggregator is EIP712, L2GovernorMetadata, L2CountingFrac function proposalL1VoteActive(uint256 proposalId) public view returns (bool active) { L2GovernorMetadata.Proposal memory proposal = getProposal(proposalId); - return L1_BLOCK.number() <= proposal.voteEnd - && L1_BLOCK.number() >= proposal.voteStart && !proposal.isCanceled; + return L1_BLOCK.number() <= proposal.voteEnd && L1_BLOCK.number() >= proposal.voteStart + && !proposal.isCanceled; } - } diff --git a/src/WormholeL2VoteAggregator.sol b/src/WormholeL2VoteAggregator.sol index 82ac51c8..08ac7e0e 100644 --- a/src/WormholeL2VoteAggregator.sol +++ b/src/WormholeL2VoteAggregator.sol @@ -20,11 +20,12 @@ contract WormholeL2VoteAggregator is WormholeSender, L2VoteAggregator, WormholeL address _l1BlockAddress, uint16 _sourceChain, uint16 _targetChain, - address _owner + address _owner, + uint32 castWindow ) L2VoteAggregator(_votingToken) WormholeSender(_sourceChain, _targetChain) - WormholeL2GovernorMetadata(_relayer, _owner, _l1BlockAddress) + WormholeL2GovernorMetadata(_relayer, _owner, _l1BlockAddress, castWindow) {} /// @notice Wormhole-specific implementation of `_bridgeVote`. diff --git a/src/optimized/WormholeL2GovernorMetadataOptimized.sol b/src/optimized/WormholeL2GovernorMetadataOptimized.sol index 124c82e9..cf01cbe2 100644 --- a/src/optimized/WormholeL2GovernorMetadataOptimized.sol +++ b/src/optimized/WormholeL2GovernorMetadataOptimized.sol @@ -11,8 +11,8 @@ contract WormholeL2GovernorMetadataOptimized is WormholeL2GovernorMetadata { /// @notice The ID of the proposal mapped to an internal proposal ID. mapping(uint256 governorProposalId => uint16) public optimizedProposalIds; - constructor(address _relayer, address _owner, address _l1BlockAddress) - WormholeL2GovernorMetadata(_relayer, _owner, _l1BlockAddress) + constructor(address _relayer, address _owner, address _l1BlockAddress, uint32 castWindow) + WormholeL2GovernorMetadata(_relayer, _owner, _l1BlockAddress, castWindow) {} /// @inheritdoc L2GovernorMetadata diff --git a/src/optimized/WormholeL2VoteAggregatorCalldataCompressor.sol b/src/optimized/WormholeL2VoteAggregatorCalldataCompressor.sol index feb823d5..0e076b07 100644 --- a/src/optimized/WormholeL2VoteAggregatorCalldataCompressor.sol +++ b/src/optimized/WormholeL2VoteAggregatorCalldataCompressor.sol @@ -32,7 +32,8 @@ contract WormholeL2VoteAggregatorCalldataCompressor is WormholeL2VoteAggregator address _l1BlockAddress, uint16 _sourceChain, uint16 _targetChain, - address _owner + address _owner, + uint32 castWindow ) WormholeL2VoteAggregator( _votingToken, @@ -40,7 +41,8 @@ contract WormholeL2VoteAggregatorCalldataCompressor is WormholeL2VoteAggregator _l1BlockAddress, _sourceChain, _targetChain, - _owner + _owner, + castWindow ) {} diff --git a/test/L2VoteAggregator.t.sol b/test/L2VoteAggregator.t.sol index d116f86b..cee8237a 100644 --- a/test/L2VoteAggregator.t.sol +++ b/test/L2VoteAggregator.t.sol @@ -549,7 +549,8 @@ contract CastVoteWithReasonAndParams is L2VoteAggregatorTest { uint128 amount = uint128(againstVotes) + forVotes + abstainVotes; vm.assume(againstVotes != 0); vm.assume(abstainVotes != 0); - bytes memory firstVoteData = abi.encodePacked(uint128(againstVotes), uint128(forVotes), uint128(0)); + bytes memory firstVoteData = + abi.encodePacked(uint128(againstVotes), uint128(forVotes), uint128(0)); bytes memory secondVoteData = abi.encodePacked(uint128(0), uint128(0), uint128(abstainVotes)); l2Erc20.mint(address(this), amount); diff --git a/test/WormholeL1GovernorMetadataBridge.t.sol b/test/WormholeL1GovernorMetadataBridge.t.sol index d0d938e0..0f0ab721 100644 --- a/test/WormholeL1GovernorMetadataBridge.t.sol +++ b/test/WormholeL1GovernorMetadataBridge.t.sol @@ -58,8 +58,9 @@ contract L1GovernorMetadataBridgeTest is TestConstants, WormholeRelayerBasicTest function setUpTarget() public override { L1BlockMock _mockL1Block = new L1BlockMock(); - l2GovernorMetadata = - new WormholeL2GovernorMetadata(L2_CHAIN.wormholeRelayer, msg.sender, address(_mockL1Block)); + l2GovernorMetadata = new WormholeL2GovernorMetadata( + L2_CHAIN.wormholeRelayer, msg.sender, address(_mockL1Block), 1200 + ); vm.prank(l2GovernorMetadata.owner()); l2GovernorMetadata.setRegisteredSender( L1_CHAIN.wormholeChainId, bytes32(uint256(uint160(address(l1GovernorMetadataBridge)))) diff --git a/test/WormholeL1VotePool.t.sol b/test/WormholeL1VotePool.t.sol index ecccbbcb..7dd5f692 100644 --- a/test/WormholeL1VotePool.t.sol +++ b/test/WormholeL1VotePool.t.sol @@ -46,7 +46,8 @@ contract WormholeL1VotePoolTest is TestConstants, WormholeRelayerBasicTest { L2_CHAIN.wormholeRelayer, address(l1Block), L2_CHAIN.wormholeChainId, - L1_CHAIN.wormholeChainId + L1_CHAIN.wormholeChainId, + 1200 ); } diff --git a/test/WormholeL2GovernorMetadata.t.sol b/test/WormholeL2GovernorMetadata.t.sol index 917a24fa..84b37158 100644 --- a/test/WormholeL2GovernorMetadata.t.sol +++ b/test/WormholeL2GovernorMetadata.t.sol @@ -30,8 +30,9 @@ contract L2GovernorMetadataTest is TestConstants { function setUp() public { mockL1Block = new L1BlockMock(); - l2GovernorMetadata = - new WormholeL2GovernorMetadata(L2_CHAIN.wormholeRelayer, msg.sender, address(mockL1Block)); + l2GovernorMetadata = new WormholeL2GovernorMetadata( + L2_CHAIN.wormholeRelayer, msg.sender, address(mockL1Block), 1200 + ); vm.prank(l2GovernorMetadata.owner()); l2GovernorMetadata.setRegisteredSender( L1_CHAIN.wormholeChainId, MOCK_WORMHOLE_SERIALIZED_ADDRESS @@ -65,7 +66,7 @@ contract L2GovernorMetadataTest is TestConstants { contract Constructor is L2GovernorMetadataTest { function testFuzz_CorrectlySetsAllArgs(address wormholeCore) public { - new WormholeL2GovernorMetadata(wormholeCore, msg.sender, address(ARBITRARY_ADDRESS)); + new WormholeL2GovernorMetadata(wormholeCore, msg.sender, address(ARBITRARY_ADDRESS), 1200); // nothing to assert as there are no constructor args set } } diff --git a/test/WormholeL2VoteAggregator.t.sol b/test/WormholeL2VoteAggregator.t.sol index 33df0efe..f6ef0b25 100644 --- a/test/WormholeL2VoteAggregator.t.sol +++ b/test/WormholeL2VoteAggregator.t.sol @@ -51,7 +51,8 @@ contract L2VoteAggregatorTest is TestConstants, WormholeRelayerBasicTest { L2_CHAIN.wormholeRelayer, address(l1Block), L2_CHAIN.wormholeChainId, - L1_CHAIN.wormholeChainId + L1_CHAIN.wormholeChainId, + 1200 ); } @@ -73,7 +74,8 @@ contract Constructor is L2VoteAggregatorTest { L2_CHAIN.wormholeRelayer, address(l1Block), L2_CHAIN.wormholeChainId, - L1_CHAIN.wormholeChainId + L1_CHAIN.wormholeChainId, + 1200 ); assertEq(address(l1Block), address(l2VoteAggregator.L1_BLOCK())); diff --git a/test/harness/WormholeL2VoteAggregatorHarness.sol b/test/harness/WormholeL2VoteAggregatorHarness.sol index 42cfc12e..2df4cb69 100644 --- a/test/harness/WormholeL2VoteAggregatorHarness.sol +++ b/test/harness/WormholeL2VoteAggregatorHarness.sol @@ -11,7 +11,8 @@ contract WormholeL2VoteAggregatorHarness is WormholeL2VoteAggregator, GovernorMe address _relayer, address _l1BlockAddress, uint16 _sourceChain, - uint16 _targetChain + uint16 _targetChain, + uint32 _castWindow ) WormholeL2VoteAggregator( _votingToken, @@ -19,7 +20,8 @@ contract WormholeL2VoteAggregatorHarness is WormholeL2VoteAggregator, GovernorMe _l1BlockAddress, _sourceChain, _targetChain, - msg.sender + msg.sender, + _castWindow ) {} diff --git a/test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol b/test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol index 3bf424e6..fbb146f6 100644 --- a/test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol +++ b/test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol @@ -6,7 +6,7 @@ import {WormholeL2GovernorMetadataOptimized} from contract WormholeL2GovernorMetadataOptimizedHarness is WormholeL2GovernorMetadataOptimized { constructor(address _core, address _owner, address _l1BlockAddress) - WormholeL2GovernorMetadataOptimized(_core, _owner, _l1BlockAddress) + WormholeL2GovernorMetadataOptimized(_core, _owner, _l1BlockAddress, 1200) {} function exposed_addProposal( diff --git a/test/mock/GovernorMetadataMock.sol b/test/mock/GovernorMetadataMock.sol index 60462a8e..ab4a9ee7 100644 --- a/test/mock/GovernorMetadataMock.sol +++ b/test/mock/GovernorMetadataMock.sol @@ -45,7 +45,7 @@ abstract contract GovernorMetadataMockBase is L2GovernorMetadata { } contract GovernorMetadataMock is GovernorMetadataMockBase, WormholeL2GovernorMetadata { - constructor(address _core) WormholeL2GovernorMetadata(_core, msg.sender, address(0x1b)) { + constructor(address _core) WormholeL2GovernorMetadata(_core, msg.sender, address(0x1b), 1200) { _proposals[1] = Proposal({voteStart: block.number, voteEnd: block.number + 3000, isCanceled: false}); } @@ -55,7 +55,9 @@ contract GovernorMetadataOptimizedMock is GovernorMetadataMockBase, WormholeL2GovernorMetadataOptimized { - constructor(address _core) WormholeL2GovernorMetadataOptimized(_core, msg.sender, address(0x1b)) {} + constructor(address _core) + WormholeL2GovernorMetadataOptimized(_core, msg.sender, address(0x1b), 1200) + {} function _addProposal(uint256 proposalId, uint256 voteStart, uint256 voteEnd, bool isCanceled) internal diff --git a/test/optimized/WormholeL2VoteAggregatorCalldataCompressor.t.sol b/test/optimized/WormholeL2VoteAggregatorCalldataCompressor.t.sol index 8258d7b9..b773034b 100644 --- a/test/optimized/WormholeL2VoteAggregatorCalldataCompressor.t.sol +++ b/test/optimized/WormholeL2VoteAggregatorCalldataCompressor.t.sol @@ -27,7 +27,8 @@ contract WormholeL2VoteAggregatorCalldataCompressorHarness is address _relayer, address _l1BlockAddress, uint16 _sourceChain, - uint16 _targetChain + uint16 _targetChain, + uint32 _castWindow ) WormholeL2VoteAggregatorCalldataCompressor( _votingToken, @@ -35,7 +36,8 @@ contract WormholeL2VoteAggregatorCalldataCompressorHarness is _l1BlockAddress, _sourceChain, _targetChain, - msg.sender + msg.sender, + _castWindow ) {} @@ -91,14 +93,16 @@ contract WormholeL2ERC20CalldataCompressorTest is Test, TestConstants { address(l1Block), L2_CHAIN.wormholeChainId, L1_CHAIN.wormholeChainId, - msg.sender + msg.sender, + 1200 ); routerHarness = new WormholeL2VoteAggregatorCalldataCompressorHarness( address(l2Erc20), L2_CHAIN.wormholeRelayer, address(l1Block), L2_CHAIN.wormholeChainId, - L1_CHAIN.wormholeChainId + L1_CHAIN.wormholeChainId, + 1200 ); }