Skip to content

Commit

Permalink
add stepDefend success testcase (ethereum-optimism#11148)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenseDenise authored Jul 22, 2024
1 parent f6f8cd5 commit 3c30fa1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/contracts-bedrock/test/dispute/FaultDisputeGame.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,39 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
gameProxy.step(8, true, claimData5, hex"");
}

/// @dev Tests that successfully step with true defend claim when there is a true defend claim(claim7) in the
/// middle of the dispute game.
function test_stepDefendDummyClaim_defendTrueClaimInTheMiddle_succeeds() public {
// Give the test contract some ether
vm.deal(address(this), 1000 ether);

// Make claims all the way down the tree.
(,,,, Claim disputed,,) = gameProxy.claimData(0);
gameProxy.attack{ value: _getRequiredBond(0) }(disputed, 0, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(1);
gameProxy.attack{ value: _getRequiredBond(1) }(disputed, 1, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(2);
gameProxy.attack{ value: _getRequiredBond(2) }(disputed, 2, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(3);
gameProxy.attack{ value: _getRequiredBond(3) }(disputed, 3, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(4);
gameProxy.attack{ value: _getRequiredBond(4) }(disputed, 4, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC));

bytes memory claimData7 = abi.encode(7, 7);
Claim postState_ = Claim.wrap(gameImpl.vm().step(claimData7, hex"", bytes32(0)));

(,,,, disputed,,) = gameProxy.claimData(5);
gameProxy.attack{ value: _getRequiredBond(5) }(disputed, 5, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(6);
bytes memory _dummyClaimData = abi.encode(gasleft(), gasleft());
gameProxy.defend{ value: _getRequiredBond(6) }(disputed, 6, postState_);
(,,,, disputed,,) = gameProxy.claimData(7);

gameProxy.attack{ value: _getRequiredBond(7) }(disputed, 7, Claim.wrap(keccak256(claimData7)));
gameProxy.addLocalData(LocalPreimageKey.DISPUTED_L2_BLOCK_NUMBER, 8, 0);
gameProxy.step(8, false, claimData7, hex"");
}

/// @dev Tests that step reverts with false attacking claim when there is a true defend claim(claim5) in the middle
/// of the dispute game.
function test_stepAttackTrueClaim_defendTrueClaimInTheMiddle_reverts() public {
Expand Down

0 comments on commit 3c30fa1

Please sign in to comment.