generated from ScopeLift/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3218636
commit 7723f64
Showing
5 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {WormholeL2GovernorMetadata} from "src/WormholeL2GovernorMetadata.sol"; | ||
|
||
contract WormholeL2GovernorMetadataOptimized is WormholeL2GovernorMetadata { | ||
/// @notice | ||
uint16 internal _proposalId = 1; | ||
|
||
/// @notice The id of the proposal mapped to the proposal metadata. | ||
mapping(uint256 governorProposalId => uint16) public optimizedProposalIds; | ||
|
||
constructor(address _relayer, address _owner) WormholeL2GovernorMetadata(_relayer, _owner) {} | ||
|
||
function _addProposal(uint256 proposalId, uint256 voteStart, uint256 voteEnd, bool isCanceled) | ||
internal | ||
virtual | ||
override | ||
{ | ||
super._addProposal(proposalId, voteStart, voteEnd, isCanceled); | ||
uint16 internalId = optimizedProposalIds[proposalId]; | ||
if (internalId == 0) { | ||
optimizedProposalIds[proposalId] = _proposalId; | ||
++_proposalId; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {WormholeL2GovernorMetadataOptimized} from | ||
"src/routers/WormholeL2GovernorMetadataOptimized.sol"; | ||
|
||
contract WormholeL2GovernorMetadataOptimizedHarness is WormholeL2GovernorMetadataOptimized { | ||
constructor(address _core, address _owner) WormholeL2GovernorMetadataOptimized(_core, _owner) {} | ||
|
||
function exposed_addProposal( | ||
uint256 proposalId, | ||
uint256 voteStart, | ||
uint256 voteEnd, | ||
bool isCanceled | ||
) external { | ||
_addProposal(proposalId, voteStart, voteEnd, isCanceled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {L2GovernorMetadata} from "src/L2GovernorMetadata.sol"; | ||
import {WormholeL2GovernorMetadataOptimizedHarness} from | ||
"test/harness/optimized/WormholeL2GovernorMetadataOptimizedHarness.sol"; | ||
import {TestConstants} from "test/Constants.sol"; | ||
import {WormholeReceiver} from "src/WormholeReceiver.sol"; | ||
|
||
// Test one proposal works | ||
// test two proposals | ||
// What if the same id is bridged twice | ||
|
||
contract WormholeL2GovernorMetadataOptimizedTest is TestConstants { | ||
WormholeL2GovernorMetadataOptimizedHarness l2GovernorMetadata; | ||
|
||
function setUp() public { | ||
l2GovernorMetadata = | ||
new WormholeL2GovernorMetadataOptimizedHarness(L2_CHAIN.wormholeRelayer, msg.sender); | ||
vm.prank(l2GovernorMetadata.owner()); | ||
l2GovernorMetadata.setRegisteredSender( | ||
L1_CHAIN.wormholeChainId, MOCK_WORMHOLE_SERIALIZED_ADDRESS | ||
); | ||
} | ||
} | ||
|
||
contract _AddProposal is WormholeL2GovernorMetadataOptimizedTest { | ||
function testFuzz_CorrectlyAddASingleProposal( | ||
uint256 proposalId, | ||
uint256 l1VoteStart, | ||
uint256 l1VoteEnd, | ||
bool isCanceled | ||
) public { | ||
l2GovernorMetadata.exposed_addProposal(proposalId, l1VoteStart, l1VoteEnd, isCanceled); | ||
L2GovernorMetadata.Proposal memory l2Proposal = l2GovernorMetadata.getProposal(proposalId); | ||
uint256 internalProposalId = l2GovernorMetadata.optimizedProposalIds(proposalId); | ||
|
||
assertEq(l2Proposal.voteStart, l1VoteStart, "Vote start has been incorrectly set"); | ||
assertEq(l2Proposal.voteEnd, l1VoteEnd, "Vote start has been incorrectly set"); | ||
assertEq(l2Proposal.isCanceled, isCanceled, "Canceled status of the vote is incorrect"); | ||
assertEq(internalProposalId, 1, "Internal id is incorrect"); | ||
} | ||
|
||
function testFuzz_CorrectlyAddAMultipleProposals( | ||
uint256 firstProposalId, | ||
uint256 firstL1VoteStart, | ||
uint256 firstL1VoteEnd, | ||
bool firstIsCanceled, | ||
uint256 secondProposalId, | ||
uint256 secondL1VoteStart, | ||
uint256 secondL1VoteEnd, | ||
bool secondIsCanceled, | ||
uint256 thirdProposalId, | ||
uint256 thirdL1VoteStart, | ||
uint256 thirdL1VoteEnd, | ||
bool thirdIsCanceled | ||
) public { | ||
vm.assume(firstProposalId != secondProposalId); | ||
vm.assume(thirdProposalId != secondProposalId); | ||
vm.assume(thirdProposalId != firstProposalId); | ||
|
||
l2GovernorMetadata.exposed_addProposal( | ||
firstProposalId, firstL1VoteStart, firstL1VoteEnd, firstIsCanceled | ||
); | ||
l2GovernorMetadata.exposed_addProposal( | ||
secondProposalId, secondL1VoteStart, secondL1VoteEnd, secondIsCanceled | ||
); | ||
l2GovernorMetadata.exposed_addProposal( | ||
thirdProposalId, thirdL1VoteStart, thirdL1VoteEnd, thirdIsCanceled | ||
); | ||
|
||
L2GovernorMetadata.Proposal memory thirdL2Proposal = | ||
l2GovernorMetadata.getProposal(thirdProposalId); | ||
uint256 thirdInternalProposalId = l2GovernorMetadata.optimizedProposalIds(thirdProposalId); | ||
|
||
assertEq( | ||
thirdL2Proposal.voteStart, thirdL1VoteStart, "Third vote start has been incorrectly set" | ||
); | ||
assertEq(thirdL2Proposal.voteEnd, thirdL1VoteEnd, "Third vote end has been incorrectly set"); | ||
assertEq( | ||
thirdL2Proposal.isCanceled, thirdIsCanceled, "Third canceled status of the vote is incorrect" | ||
); | ||
assertEq(thirdInternalProposalId, 3, "Third internal id is incorrect"); | ||
} | ||
|
||
function testFuzz_CorrectlyUpdateTheSameProposal( | ||
uint256 proposalId, | ||
uint256 initialVoteStart, | ||
uint256 initialVoteEnd, | ||
bool initialIsCanceled, | ||
uint256 updatedVoteStart, | ||
uint256 updatedVoteEnd, | ||
bool updatedIsCanceled | ||
) public { | ||
l2GovernorMetadata.exposed_addProposal( | ||
proposalId, initialVoteStart, initialVoteEnd, initialIsCanceled | ||
); | ||
|
||
L2GovernorMetadata.Proposal memory l2Proposal = l2GovernorMetadata.getProposal(proposalId); | ||
uint256 initialInternalProposalId = l2GovernorMetadata.optimizedProposalIds(proposalId); | ||
|
||
assertEq(l2Proposal.voteStart, initialVoteStart, "Initial vote start has been incorrectly set"); | ||
assertEq(l2Proposal.voteEnd, initialVoteEnd, "Initial vote end has been incorrectly set"); | ||
assertEq( | ||
l2Proposal.isCanceled, initialIsCanceled, "Initial canceled status of the vote is incorrect" | ||
); | ||
assertEq(initialInternalProposalId, 1, "Initial internal id is incorrect"); | ||
|
||
l2GovernorMetadata.exposed_addProposal( | ||
proposalId, updatedVoteStart, updatedVoteEnd, updatedIsCanceled | ||
); | ||
|
||
L2GovernorMetadata.Proposal memory updatedL2Proposal = | ||
l2GovernorMetadata.getProposal(proposalId); | ||
uint256 updatedInternalProposalId = l2GovernorMetadata.optimizedProposalIds(proposalId); | ||
|
||
assertEq( | ||
updatedL2Proposal.voteStart, updatedVoteStart, "Updated vote start has been incorrectly set" | ||
); | ||
assertEq(updatedL2Proposal.voteEnd, updatedVoteEnd, "Updated vote end has been incorrectly set"); | ||
assertEq( | ||
updatedL2Proposal.isCanceled, | ||
updatedIsCanceled, | ||
"Updated canceled status of the vote is incorrect" | ||
); | ||
assertEq(updatedInternalProposalId, 1, "Updated internal id is incorrect"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters