Commit 5e7efe5a authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6681 from ethereum-optimism/aj/cannon-e2e-moves

op-e2e: Update cannon e2e test to execute moves down to the max depth
parents a14e19a4 9de9ae67
...@@ -27,7 +27,7 @@ func (g *CannonGameHelper) StartChallenger(ctx context.Context, rollupCfg *rollu ...@@ -27,7 +27,7 @@ func (g *CannonGameHelper) StartChallenger(ctx context.Context, rollupCfg *rollu
c.CannonDatadir = g.t.TempDir() c.CannonDatadir = g.t.TempDir()
c.CannonServer = "../op-program/bin/op-program" c.CannonServer = "../op-program/bin/op-program"
c.CannonAbsolutePreState = "../op-program/bin/prestate.json" c.CannonAbsolutePreState = "../op-program/bin/prestate.json"
c.CannonSnapshotFreq = config.DefaultCannonSnapshotFreq c.CannonSnapshotFreq = 10_000_000
genesisBytes, err := json.Marshal(l2Genesis) genesisBytes, err := json.Marshal(l2Genesis)
g.require.NoError(err, "marshall l2 genesis config") g.require.NoError(err, "marshall l2 genesis config")
......
...@@ -22,7 +22,6 @@ type FaultGameHelper struct { ...@@ -22,7 +22,6 @@ type FaultGameHelper struct {
client *ethclient.Client client *ethclient.Client
opts *bind.TransactOpts opts *bind.TransactOpts
game *bindings.FaultDisputeGame game *bindings.FaultDisputeGame
maxDepth int
addr common.Address addr common.Address
} }
...@@ -54,6 +53,12 @@ type ContractClaim struct { ...@@ -54,6 +53,12 @@ type ContractClaim struct {
Clock *big.Int Clock *big.Int
} }
func (g *FaultGameHelper) MaxDepth(ctx context.Context) int64 {
depth, err := g.game.MAXGAMEDEPTH(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "Failed to load game depth")
return depth.Int64()
}
func (g *FaultGameHelper) WaitForClaim(ctx context.Context, predicate func(claim ContractClaim) bool) { func (g *FaultGameHelper) WaitForClaim(ctx context.Context, predicate func(claim ContractClaim) bool) {
ctx, cancel := context.WithTimeout(ctx, time.Minute) ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel() defer cancel()
...@@ -78,9 +83,10 @@ func (g *FaultGameHelper) WaitForClaim(ctx context.Context, predicate func(claim ...@@ -78,9 +83,10 @@ func (g *FaultGameHelper) WaitForClaim(ctx context.Context, predicate func(claim
} }
func (g *FaultGameHelper) WaitForClaimAtMaxDepth(ctx context.Context, countered bool) { func (g *FaultGameHelper) WaitForClaimAtMaxDepth(ctx context.Context, countered bool) {
maxDepth := g.MaxDepth(ctx)
g.WaitForClaim(ctx, func(claim ContractClaim) bool { g.WaitForClaim(ctx, func(claim ContractClaim) bool {
pos := types.NewPositionFromGIndex(claim.Position.Uint64()) pos := types.NewPositionFromGIndex(claim.Position.Uint64())
return pos.Depth() == g.maxDepth && claim.Countered == countered return int64(pos.Depth()) == maxDepth && claim.Countered == countered
}) })
} }
...@@ -109,3 +115,10 @@ func (g *FaultGameHelper) WaitForGameStatus(ctx context.Context, expected Status ...@@ -109,3 +115,10 @@ func (g *FaultGameHelper) WaitForGameStatus(ctx context.Context, expected Status
}) })
g.require.NoError(err, "wait for game status") g.require.NoError(err, "wait for game status")
} }
func (g *FaultGameHelper) Attack(ctx context.Context, claimIdx int64, claim common.Hash) {
tx, err := g.game.Attack(g.opts, big.NewInt(claimIdx), claim)
g.require.NoError(err, "Attack transaction did not send")
_, err = utils.WaitReceiptOK(ctx, g.client, tx.Hash())
g.require.NoError(err, "Attack transaction was not OK")
}
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
const alphabetGameType uint8 = 0 const alphabetGameType uint8 = 0
const cannonGameType uint8 = 1 const cannonGameType uint8 = 1
const alphabetGameDepth = 4 const alphabetGameDepth = 4
const cannonGameDepth = 64
const lastAlphabetTraceIndex = 1<<alphabetGameDepth - 1 const lastAlphabetTraceIndex = 1<<alphabetGameDepth - 1
type Status uint8 type Status uint8
...@@ -114,7 +113,6 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s ...@@ -114,7 +113,6 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s
client: h.client, client: h.client,
opts: h.opts, opts: h.opts,
game: game, game: game,
maxDepth: alphabetGameDepth,
addr: createdEvent.DisputeProxy, addr: createdEvent.DisputeProxy,
}, },
claimedAlphabet: claimedAlphabet, claimedAlphabet: claimedAlphabet,
...@@ -148,7 +146,6 @@ func (h *FactoryHelper) StartCannonGame(ctx context.Context, rootClaim common.Ha ...@@ -148,7 +146,6 @@ func (h *FactoryHelper) StartCannonGame(ctx context.Context, rootClaim common.Ha
client: h.client, client: h.client,
opts: h.opts, opts: h.opts,
game: game, game: game,
maxDepth: cannonGameDepth,
addr: createdEvent.DisputeProxy, addr: createdEvent.DisputeProxy,
}, },
} }
......
...@@ -160,8 +160,18 @@ func TestCannonDisputeGame(t *testing.T) { ...@@ -160,8 +160,18 @@ func TestCannonDisputeGame(t *testing.T) {
c.TxMgrConfig.PrivateKey = e2eutils.EncodePrivKeyToString(sys.cfg.Secrets.Alice) c.TxMgrConfig.PrivateKey = e2eutils.EncodePrivKeyToString(sys.cfg.Secrets.Alice)
}) })
// Challenger should counter the root claim maxDepth := game.MaxDepth(ctx)
game.WaitForClaimCount(ctx, 2) for claimCount := int64(1); claimCount < maxDepth; {
claimCount++
// Wait for the challenger to counter
game.WaitForClaimCount(ctx, claimCount)
// Post our own counter to the latest challenger claim
game.Attack(ctx, claimCount-1, common.Hash{byte(claimCount)})
claimCount++
game.WaitForClaimCount(ctx, claimCount)
}
game.WaitForClaimAtMaxDepth(ctx, false)
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx)) sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, utils.WaitNextBlock(ctx, l1Client)) require.NoError(t, utils.WaitNextBlock(ctx, l1Client))
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"l1GenesisBlockTimestamp": "0x64c811bf", "l1GenesisBlockTimestamp": "0x64c811bf",
"l2GenesisRegolithTimeOffset": "0x0", "l2GenesisRegolithTimeOffset": "0x0",
"faultGameAbsolutePrestate": "0x41c7ae758795765c6664a5d39bf63841c71ff191e9189522bad8ebff5d4eca98", "faultGameAbsolutePrestate": "0x41c7ae758795765c6664a5d39bf63841c71ff191e9189522bad8ebff5d4eca98",
"faultGameMaxDepth": 4, "faultGameMaxDepth": 31,
"faultGameMaxDuration": 300, "faultGameMaxDuration": 300,
"systemConfigStartBlock": 0 "systemConfigStartBlock": 0
} }
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