@@ -77,6 +77,48 @@ contract AnchorStateRegistry_GetAnchorRoot_Test is AnchorStateRegistry_Init {
7777 assertEq (root.raw (), 0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF );
7878 assertEq (l2BlockNumber, 0 );
7979 }
80+
81+ /// @notice Tests that getAnchorRoot will return the correct anchor root if an anchor game exists.
82+ function test_getAnchorRoot_anchorGameExists_succeeds () public {
83+ // Mock the game to be resolved.
84+ vm.mockCall (address (gameProxy), abi.encodeCall (gameProxy.resolvedAt, ()), abi.encode (block .timestamp ));
85+ vm.warp (block .timestamp + optimismPortal2.disputeGameFinalityDelaySeconds () + 1 );
86+
87+ // Mock the game to be the defender wins.
88+ vm.mockCall (address (gameProxy), abi.encodeCall (gameProxy.status, ()), abi.encode (GameStatus.DEFENDER_WINS));
89+
90+ // Set the anchor game to the game proxy.
91+ anchorStateRegistry.setAnchorState (gameProxy);
92+
93+ // We should get the anchor root back.
94+ (Hash root , uint256 l2BlockNumber ) = anchorStateRegistry.getAnchorRoot ();
95+ assertEq (root.raw (), gameProxy.rootClaim ().raw ());
96+ assertEq (l2BlockNumber, gameProxy.l2BlockNumber ());
97+ }
98+ }
99+
100+ contract AnchorStateRegistry_GetAnchorRoot_TestFail is AnchorStateRegistry_Init {
101+ /// @notice Tests that getAnchorRoot will revert if the anchor game is blacklisted.
102+ function test_getAnchorRoot_blacklistedGame_fails () public {
103+ // Mock the game to be resolved.
104+ vm.mockCall (address (gameProxy), abi.encodeCall (gameProxy.resolvedAt, ()), abi.encode (block .timestamp ));
105+ vm.warp (block .timestamp + optimismPortal2.disputeGameFinalityDelaySeconds () + 1 );
106+
107+ // Mock the game to be the defender wins.
108+ vm.mockCall (address (gameProxy), abi.encodeCall (gameProxy.status, ()), abi.encode (GameStatus.DEFENDER_WINS));
109+
110+ // Set the anchor game to the game proxy.
111+ anchorStateRegistry.setAnchorState (gameProxy);
112+
113+ // Mock the disputeGameBlacklist call to return true.
114+ vm.mockCall (
115+ address (optimismPortal2),
116+ abi.encodeCall (optimismPortal2.disputeGameBlacklist, (gameProxy)),
117+ abi.encode (true )
118+ );
119+ vm.expectRevert (IAnchorStateRegistry.AnchorStateRegistry_AnchorGameBlacklisted.selector );
120+ anchorStateRegistry.getAnchorRoot ();
121+ }
80122}
81123
82124contract AnchorStateRegistry_Anchors_Test is AnchorStateRegistry_Init {
@@ -150,17 +192,11 @@ contract AnchorStateRegistry_IsGameRespected_Test is AnchorStateRegistry_Init {
150192
151193 /// @notice Tests that isGameRespected will return false if the game is not of the respected game
152194 /// type.
153- /// @param _gameType The game type to use for the test.
154- function testFuzz_isGameRespected_isNotRespected_succeeds (GameType _gameType ) public {
155- if (_gameType.raw () == gameProxy.gameType ().raw ()) {
156- _gameType = GameType.wrap (_gameType.raw () + 1 );
157- }
158-
195+ function test_isGameRespected_isNotRespected_succeeds () public {
159196 // Mock that the game was not respected.
160197 vm.mockCall (
161198 address (gameProxy), abi.encodeCall (gameProxy.wasRespectedGameTypeWhenCreated, ()), abi.encode (false )
162199 );
163-
164200 assertFalse (anchorStateRegistry.isGameRespected (gameProxy));
165201 }
166202}
@@ -308,7 +344,7 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
308344 /// @notice Tests that setAnchorState will revert if the game is valid and the game block
309345 /// number is less than or equal to the current anchor root block number.
310346 /// @param _l2BlockNumber The L2 block number to use for the game.
311- function testFuzz_setAnchorState_validOlderState_fails (uint256 _l2BlockNumber ) public {
347+ function testFuzz_setAnchorState_olderValidGameClaim_fails (uint256 _l2BlockNumber ) public {
312348 // Grab block number of the existing anchor root.
313349 (Hash root , uint256 l2BlockNumber ) = anchorStateRegistry.getAnchorRoot ();
314350
@@ -445,10 +481,9 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
445481 assertEq (updatedRoot.raw (), root.raw ());
446482 }
447483
448- /// @notice Tests that setAnchorState will revert if the game is valid and the game type
449- /// is not the respected game type.
484+ /// @notice Tests that setAnchorState will revert if the game is not respected.
450485 /// @param _l2BlockNumber The L2 block number to use for the game.
451- function testFuzz_setAnchorState_notRespectedGameType_fails (uint256 _l2BlockNumber ) public {
486+ function testFuzz_setAnchorState_isNotRespectedGame_fails (uint256 _l2BlockNumber ) public {
452487 // Grab block number of the existing anchor root.
453488 (Hash root , uint256 l2BlockNumber ) = anchorStateRegistry.anchors (gameProxy.gameType ());
454489
@@ -465,7 +500,7 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
465500 vm.mockCall (address (gameProxy), abi.encodeCall (gameProxy.resolvedAt, ()), abi.encode (block .timestamp ));
466501 vm.warp (block .timestamp + optimismPortal2.disputeGameFinalityDelaySeconds () + 1 );
467502
468- // Mock that the game was not respected.
503+ // Mock that the game was not respected when created .
469504 vm.mockCall (
470505 address (gameProxy), abi.encodeCall (gameProxy.wasRespectedGameTypeWhenCreated, ()), abi.encode (false )
471506 );
0 commit comments