Commit f20c4cdf authored by clabby's avatar clabby

Add tests for init reverts

parent b7aa3561
...@@ -97,25 +97,27 @@ FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeed ...@@ -97,25 +97,27 @@ FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeed
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 502315) FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 502315)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 501604) FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 501604)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32354) FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32354)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32828) FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32806)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10410) FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10410)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8266) FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8266)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17627) FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 58226)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 415931) FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210532)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26450) FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 276399)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 415921)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26428)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13322) FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13322)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 103333) FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 103377)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 408316) FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 408316)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11046) FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11046)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24623) FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24623)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 107322) FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 107300)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 224891) FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 224847)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9663) FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9686)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 109882) FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 109882)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21487) FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21465)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27344) FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27322)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 395563) FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 395519)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8275) FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8253)
FeeVault_Test:test_constructor_succeeds() (gas: 18185) FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113) GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320) GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
......
...@@ -281,16 +281,25 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver { ...@@ -281,16 +281,25 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
if (_ident == 1) { if (_ident == 1) {
// Load the L1 head hash into the game's local context in the preimage oracle. // Load the L1 head hash into the game's local context in the preimage oracle.
oracle.loadLocalData(_ident, Hash.unwrap(l1Head), 32, _partOffset); oracle.loadLocalData(_ident, Hash.unwrap(l1Head), 32, _partOffset);
} else if (_ident == 2) { } else if (_ident < 4) {
// Load the starting output root into the game's local context in the preimage oracle. // Grab the index of the proposal to load at the given ident.
oracle.loadLocalData(_ident, Hash.unwrap(proposals[0].outputRoot), 32, _partOffset); // Ident 2 loads the starting output root, and ident 3 loads the disputed output root.
} else if (_ident == 3) { uint256 proposal;
// Load the disputed output root into the game's local context in the preimage oracle. assembly {
oracle.loadLocalData(_ident, Hash.unwrap(proposals[1].outputRoot), 32, _partOffset); proposal := iszero(mod(_ident, 2))
}
// Load the starting or disputed output root into the game's local context in the
// preimage oracle.
oracle.loadLocalData(
_ident,
Hash.unwrap(proposals[proposal].outputRoot),
32,
_partOffset
);
} else if (_ident == 4) { } else if (_ident == 4) {
// Load the starting l2 block number into the game's local context in the preimage oracle. // Load the starting l2 block number into the game's local context in the preimage
// The L2 block number is stored as a big-endian uint64 in the upper 8 bytes of the // oracle. The L2 block number is stored as a big-endian uint64 in the upper 8 bytes
// passed word. // of the passed word.
oracle.loadLocalData( oracle.loadLocalData(
_ident, _ident,
bytes32(uint256(proposals[0].l2BlockNumber) << 192), bytes32(uint256(proposals[0].l2BlockNumber) << 192),
...@@ -451,9 +460,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver { ...@@ -451,9 +460,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
); );
// Grab the index of the output proposal that commits to the starting L2 head. // Grab the index of the output proposal that commits to the starting L2 head.
// The output disputed is all outputs after this one. // All outputs after this one are disputed.
// TODO(clabby): This is 2 calls too many for the information we need. Maybe // TODO(clabby): This is 2 calls too many for the information we need. Maybe
// add a function to the L2OO? // add a function to the L2OO?
// TODO(clabby): The block hash bisection game will allow us to dispute the first output
// root by using genesis as the starting point. For now, it is critical that
// the first proposed output root of an OP stack chain is done so by an
// honest party.
uint256 proposalIdx = L2_OUTPUT_ORACLE.getL2OutputIndexAfter(l2BlockNumber()); uint256 proposalIdx = L2_OUTPUT_ORACLE.getL2OutputIndexAfter(l2BlockNumber());
Types.OutputProposal memory starting = L2_OUTPUT_ORACLE.getL2Output(proposalIdx - 1); Types.OutputProposal memory starting = L2_OUTPUT_ORACLE.getL2Output(proposalIdx - 1);
Types.OutputProposal memory disputed = L2_OUTPUT_ORACLE.getL2Output(proposalIdx); Types.OutputProposal memory disputed = L2_OUTPUT_ORACLE.getL2Output(proposalIdx);
...@@ -474,13 +487,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver { ...@@ -474,13 +487,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
// resolved. // resolved.
proposals[0] = OutputProposal({ proposals[0] = OutputProposal({
index: uint128(proposalIdx - 1), index: uint128(proposalIdx - 1),
outputRoot: Hash.wrap(starting.outputRoot), l2BlockNumber: starting.l2BlockNumber,
l2BlockNumber: starting.l2BlockNumber outputRoot: Hash.wrap(starting.outputRoot)
}); });
proposals[1] = OutputProposal({ proposals[1] = OutputProposal({
index: uint128(proposalIdx), index: uint128(proposalIdx),
outputRoot: Hash.wrap(starting.outputRoot), l2BlockNumber: disputed.l2BlockNumber,
l2BlockNumber: starting.l2BlockNumber outputRoot: Hash.wrap(disputed.outputRoot)
}); });
// Persist the L1 head hash of the L1 block number provided. // Persist the L1 head hash of the L1 block number provided.
l1Head = blockInfo.hash; l1Head = blockInfo.hash;
......
...@@ -25,7 +25,6 @@ contract BlockOracle_Test is Test { ...@@ -25,7 +25,6 @@ contract BlockOracle_Test is Test {
BlockOracle.BlockInfo memory res = oracle.load(_blockNumber); BlockOracle.BlockInfo memory res = oracle.load(_blockNumber);
assertEq(Hash.unwrap(res.hash), blockhash(_blockNumber)); assertEq(Hash.unwrap(res.hash), blockhash(_blockNumber));
emit log_uint(block.timestamp - ((block.number - _blockNumber) * 13));
assertEq(Timestamp.unwrap(res.timestamp), block.timestamp - ((block.number - _blockNumber) * 13)); assertEq(Timestamp.unwrap(res.timestamp), block.timestamp - ((block.number - _blockNumber) * 13));
} }
......
...@@ -11,6 +11,7 @@ import { BlockOracle } from "src/dispute/BlockOracle.sol"; ...@@ -11,6 +11,7 @@ import { BlockOracle } from "src/dispute/BlockOracle.sol";
import "src/libraries/DisputeTypes.sol"; import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol"; import "src/libraries/DisputeErrors.sol";
import { Types } from "src/libraries/Types.sol";
import { LibClock } from "src/dispute/lib/LibClock.sol"; import { LibClock } from "src/dispute/lib/LibClock.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol"; import { LibPosition } from "src/dispute/lib/LibPosition.sol";
import { IBigStepper, IPreimageOracle } from "src/dispute/interfaces/IBigStepper.sol"; import { IBigStepper, IPreimageOracle } from "src/dispute/interfaces/IBigStepper.sol";
...@@ -123,8 +124,45 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init { ...@@ -123,8 +124,45 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
// `IFaultDisputeGame` Implementation Tests // // `IFaultDisputeGame` Implementation Tests //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
/// @dev Tests that the root claim's data is set correctly when the game is initialized. /// @dev Tests that a game cannot be created by the factory if the L1 head hash does not
function test_initialRootClaimData_succeeds() public { /// contain the disputed L2 output root.
function test_initialize_l1HeadTooOld_reverts() public {
gameProxy.BLOCK_ORACLE().store(block.number - 128);
bytes memory _extraData = abi.encode(oracle.SUBMISSION_INTERVAL() * 2, block.number - 128);
vm.expectRevert(L1HeadTooOld.selector);
factory.create(GAME_TYPE, ROOT_CLAIM, _extraData);
}
/// @dev Tests that a game cannot be created that disputes the first output root proposed.
/// TODO(clabby): This will be solved by the block hash bisection game, where we'll be able
/// to dispute the first output root by using genesis as the starting point.
/// For now, it is critical that the first proposed output root of an OP stack
/// chain is done so by an honest party.
function test_initialize_firstOutput_reverts() public {
vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
factory.create(GAME_TYPE, ROOT_CLAIM, abi.encode(1800, block.number - 1));
}
/// @dev Tests that the game is initialized with the correct data.
function test_initialize_correctData_succeeds() public {
// Starting
(uint128 index, uint128 l2BlockNumber, Hash outputRoot) = gameProxy.proposals(0);
Types.OutputProposal memory starting = oracle.getL2Output(index);
assertEq(index, 0);
assertEq(l2BlockNumber, starting.l2BlockNumber);
assertEq(Hash.unwrap(outputRoot), starting.outputRoot);
// Disputed
(uint128 _index, uint128 _l2BlockNumber, Hash _outputRoot) = gameProxy.proposals(1);
Types.OutputProposal memory disputed = oracle.getL2Output(_index);
assertEq(_index, 1);
assertEq(_l2BlockNumber, disputed.l2BlockNumber);
assertEq(Hash.unwrap(_outputRoot), disputed.outputRoot);
// L1 head
(, uint256 l1HeadNumber) = abi.decode(gameProxy.extraData(), (uint256, uint256));
assertEq(blockhash(l1HeadNumber), Hash.unwrap(gameProxy.l1Head()));
( (
uint32 parentIndex, uint32 parentIndex,
bool countered, bool countered,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment