Skip to content

Commit 4137794

Browse files
committed
fix tests
1 parent 7a4fe2e commit 4137794

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,30 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
634634
}
635635

636636
/// @dev Tests that the guardian role can set the respected game type to anything they want.
637-
function testFuzz_setRespectedGameType_guardian_succeeds(GameType _ty) external {
637+
function testFuzz_setRespectedGameType_guardian_canSetRespectedGameType_succeeds(GameType _ty) external {
638+
vm.assume(_ty.raw() != type(uint32).max);
639+
uint64 respectedGameTypeUpdatedAt = optimismPortal2.respectedGameTypeUpdatedAt();
638640
vm.expectEmit(address(optimismPortal2));
639-
emit RespectedGameTypeSet(_ty, Timestamp.wrap(uint64(block.timestamp)));
641+
emit RespectedGameTypeSet(_ty, Timestamp.wrap(respectedGameTypeUpdatedAt));
640642
vm.prank(optimismPortal2.guardian());
641643
optimismPortal2.setRespectedGameType(_ty);
642644

643645
assertEq(optimismPortal2.respectedGameType().raw(), _ty.raw());
644646
}
645647

648+
function testFuzz_setRespectedGameType_guardian_canSetRespectedGameTypeUpdatedAt_succeeds(uint64 _elapsed)
649+
external
650+
{
651+
_elapsed = uint64(bound(_elapsed, 0, type(uint64).max - uint64(block.timestamp)));
652+
GameType _ty = GameType.wrap(type(uint32).max);
653+
uint64 _timestamp = uint64(block.timestamp) + _elapsed;
654+
vm.warp(_timestamp);
655+
// TODO: event?
656+
vm.prank(optimismPortal2.guardian());
657+
optimismPortal2.setRespectedGameType(_ty);
658+
assertEq(optimismPortal2.respectedGameTypeUpdatedAt(), _timestamp);
659+
}
660+
646661
/// @dev Tests that `proveWithdrawalTransaction` reverts when paused.
647662
function test_proveWithdrawalTransaction_paused_reverts() external {
648663
vm.prank(optimismPortal2.guardian());
@@ -1644,35 +1659,6 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
16441659
assertTrue(optimismPortal2.finalizedWithdrawals(_withdrawalHash));
16451660
}
16461661

1647-
/// @dev Tests that `finalizeWithdrawalTransaction` reverts if the respected game type has changed since the
1648-
/// withdrawal was proven.
1649-
function test_finalizeWithdrawalTransaction_respectedTypeChangedSinceProving_reverts() external {
1650-
vm.expectEmit(true, true, true, true);
1651-
emit WithdrawalProven(_withdrawalHash, alice, bob);
1652-
vm.expectEmit(true, true, true, true);
1653-
emit WithdrawalProvenExtension1(_withdrawalHash, address(this));
1654-
optimismPortal2.proveWithdrawalTransaction({
1655-
_tx: _defaultTx,
1656-
_disputeGameIndex: _proposedGameIndex,
1657-
_outputRootProof: _outputRootProof,
1658-
_withdrawalProof: _withdrawalProof
1659-
});
1660-
1661-
// Warp past the finalization period.
1662-
vm.warp(block.timestamp + optimismPortal2.proofMaturityDelaySeconds() + 1);
1663-
1664-
// Resolve the dispute game.
1665-
game.resolveClaim(0, 0);
1666-
game.resolve();
1667-
1668-
// Change the respected game type in the portal.
1669-
vm.prank(optimismPortal2.guardian());
1670-
optimismPortal2.setRespectedGameType(GameType.wrap(0xFF));
1671-
1672-
vm.expectRevert(InvalidGameType.selector);
1673-
optimismPortal2.finalizeWithdrawalTransaction(_defaultTx);
1674-
}
1675-
16761662
/// @dev Tests that `finalizeWithdrawalTransaction` reverts if the respected game type was updated after the
16771663
/// dispute game was created.
16781664
function test_finalizeWithdrawalTransaction_gameOlderThanRespectedGameTypeUpdate_reverts() external {
@@ -1694,12 +1680,12 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
16941680
game.resolveClaim(0, 0);
16951681
game.resolve();
16961682

1697-
// Change the respected game type in the portal.
1698-
vm.prank(optimismPortal2.guardian());
1699-
optimismPortal2.setRespectedGameType(GameType.wrap(0xFF));
1683+
// Warp past the dispute game finality delay.
1684+
vm.warp(block.timestamp + optimismPortal2.disputeGameFinalityDelaySeconds() + 1);
17001685

1701-
// Mock the game's type so that we pass the correct game type check.
1702-
vm.mockCall(address(game), abi.encodeCall(game.gameType, ()), abi.encode(GameType.wrap(0xFF)));
1686+
// Set respectedGameTypeUpdatedAt.
1687+
vm.prank(optimismPortal2.guardian());
1688+
optimismPortal2.setRespectedGameType(GameType.wrap(type(uint32).max));
17031689

17041690
vm.expectRevert("OptimismPortal: dispute game created before respected game type was updated");
17051691
optimismPortal2.finalizeWithdrawalTransaction(_defaultTx);

0 commit comments

Comments
 (0)