Skip to content

Commit

Permalink
op-e2e: Expose methods for asterisc e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Apr 22, 2024
1 parent fccdd29 commit f0be622
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions op-e2e/e2eutils/challenger/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func WithPollInterval(pollInterval time.Duration) Option {
}
}

// findMonorepoRoot finds the relative path to the monorepo root
// FindMonorepoRoot finds the relative path to the monorepo root
// Different tests might be nested in subdirectories of the op-e2e dir.
func findMonorepoRoot(t *testing.T) string {
func FindMonorepoRoot(t *testing.T) string {
path := "./"
// Only search up 5 directories
// Avoids infinite recursion if the root isn't found for some reason
Expand All @@ -104,7 +104,7 @@ func applyCannonConfig(
) {
require := require.New(t)
c.L2Rpc = l2Endpoint
root := findMonorepoRoot(t)
root := FindMonorepoRoot(t)
c.CannonBin = root + "cannon/bin/cannon"
c.CannonServer = root + "op-program/bin/op-program"
c.CannonAbsolutePreState = root + "op-program/bin/prestate.json"
Expand Down
6 changes: 3 additions & 3 deletions op-e2e/faultproofs/challenge_preimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestChallengeLargePreimages_ChallengeFirst(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand All @@ -34,7 +34,7 @@ func TestChallengeLargePreimages_ChallengeFirst(t *testing.T) {
func TestChallengeLargePreimages_ChallengeMiddle(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
disputeGameFactory.StartChallenger(ctx, "Challenger",
Expand All @@ -52,7 +52,7 @@ func TestChallengeLargePreimages_ChallengeMiddle(t *testing.T) {
func TestChallengeLargePreimages_ChallengeLast(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
disputeGameFactory.StartChallenger(ctx, "Challenger",
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/faultproofs/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMultipleGameTypes(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

gameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down
16 changes: 8 additions & 8 deletions op-e2e/faultproofs/output_alphabet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestOutputAlphabetGame_ChallengerWins(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -76,15 +76,15 @@ func TestOutputAlphabetGame_ChallengerWins(t *testing.T) {
func TestOutputAlphabetGame_ReclaimBond(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputAlphabetGame(ctx, "sequencer", 3, common.Hash{0xff})
game.LogGameData(ctx)

// The dispute game should have a zero balance
balance := game.WethBalance(ctx, game.Addr())
balance := game.WethBalance(ctx, game.Addr)
require.Zero(t, balance.Uint64())

alice := sys.Cfg.Secrets.Addresses().Alice
Expand All @@ -106,7 +106,7 @@ func TestOutputAlphabetGame_ReclaimBond(t *testing.T) {
_ = claim.WaitForCounterClaim(ctx)

// Expect posted claims so the game balance is non-zero
balance = game.WethBalance(ctx, game.Addr())
balance = game.WethBalance(ctx, game.Addr)
require.Truef(t, balance.Cmp(big.NewInt(0)) > 0, "Expected game balance to be above zero")

sys.TimeTravelClock.AdvanceTime(game.MaxClockDuration(ctx))
Expand All @@ -131,13 +131,13 @@ func TestOutputAlphabetGame_ReclaimBond(t *testing.T) {
game.WaitForNoAvailableCredit(ctx, alice)

// The dispute game delayed weth balance should be zero since it's all claimed
require.True(t, game.WethBalance(ctx, game.Addr()).Cmp(big.NewInt(0)) == 0)
require.True(t, game.WethBalance(ctx, game.Addr).Cmp(big.NewInt(0)) == 0)
}

func TestOutputAlphabetGame_ValidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestChallengerCompleteExhaustiveDisputeGame(t *testing.T) {

testCase := func(t *testing.T, isRootCorrect bool) {
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestChallengerCompleteExhaustiveDisputeGame(t *testing.T) {
func TestOutputAlphabetGame_FreeloaderEarnsNothing(t *testing.T) {
op_e2e.InitParallel(t)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

freeloaderOpts, err := bind.NewKeyedTransactorWithChainID(sys.Cfg.Secrets.Mallory, sys.Cfg.L1ChainIDBig())
Expand Down
32 changes: 16 additions & 16 deletions op-e2e/faultproofs/output_cannon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func TestOutputCannonGame(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestOutputCannon_ChallengeAllZeroClaim(t *testing.T) {
// The dishonest actor always posts claims with all zeros.
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestOutputCannon_PublishCannonRootClaim(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", test.disputeL2BlockNumber, common.Hash{0x01})
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestOutputCannonDisputeGame(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestOutputCannonDefendStep(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestOutputCannonStepWithLargePreimage(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t, withBatcherStopped())
sys, _ := StartFaultDisputeSystem(t, WithBatcherStopped())
t.Cleanup(sys.Close)

// Manually send a tx from the correct batcher key to the batcher input with very large (invalid) data
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestOutputCannonStepWithPreimage(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t, withBlobBatches())
sys, _ := StartFaultDisputeSystem(t, WithBlobBatches())
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestOutputCannonStepWithKZGPointEvaluation(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t, withEcotone())
sys, _ := StartFaultDisputeSystem(t, WithEcotone())
t.Cleanup(sys.Close)

// NOTE: Flake prevention
Expand All @@ -315,7 +315,7 @@ func TestOutputCannonStepWithKZGPointEvaluation(t *testing.T) {
require.NoError(t, err)
require.NoError(t, wait.ForSafeBlock(ctx, sys.RollupClient("sequencer"), safeBlock.NumberU64()+3))

receipt := sendKZGPointEvaluationTx(t, sys, "sequencer", sys.Cfg.Secrets.Alice)
receipt := SendKZGPointEvaluationTx(t, sys, "sequencer", sys.Cfg.Secrets.Alice)
precompileBlock := receipt.BlockNumber
t.Logf("KZG Point Evaluation block number: %d", precompileBlock)

Expand Down Expand Up @@ -406,7 +406,7 @@ func TestOutputCannonProposedOutputRootValid(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestOutputCannonPoisonedPostState(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestDisputeOutputRootBeyondProposedBlock_ValidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestDisputeOutputRootBeyondProposedBlock_InvalidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestDisputeOutputRoot_ChangeClaimedOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
sys, l1Client := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down Expand Up @@ -693,7 +693,7 @@ func TestInvalidateUnsafeProposal(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
sys, l1Client := startFaultDisputeSystem(t, withSequencerWindowSize(100000), withBatcherStopped())
sys, l1Client := StartFaultDisputeSystem(t, WithSequencerWindowSize(100000), WithBatcherStopped())
t.Cleanup(sys.Close)

blockNum := uint64(1)
Expand Down Expand Up @@ -755,7 +755,7 @@ func TestInvalidateProposalForFutureBlock(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
sys, l1Client := startFaultDisputeSystem(t, withSequencerWindowSize(100000))
sys, l1Client := StartFaultDisputeSystem(t, WithSequencerWindowSize(100000))
t.Cleanup(sys.Close)

farFutureBlockNum := uint64(10_000_000)
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/faultproofs/preimages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestLocalPreimages(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
sys, _ := StartFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
Expand Down
12 changes: 6 additions & 6 deletions op-e2e/faultproofs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

type faultDisputeConfigOpts func(cfg *op_e2e.SystemConfig)

func withBatcherStopped() faultDisputeConfigOpts {
func WithBatcherStopped() faultDisputeConfigOpts {
return func(cfg *op_e2e.SystemConfig) {
cfg.DisableBatcher = true
}
}

func withBlobBatches() faultDisputeConfigOpts {
func WithBlobBatches() faultDisputeConfigOpts {
return func(cfg *op_e2e.SystemConfig) {
cfg.DataAvailabilityType = batcherFlags.BlobsType

Expand All @@ -32,7 +32,7 @@ func withBlobBatches() faultDisputeConfigOpts {
}
}

func withEcotone() faultDisputeConfigOpts {
func WithEcotone() faultDisputeConfigOpts {
return func(cfg *op_e2e.SystemConfig) {
genesisActivation := hexutil.Uint64(0)
cfg.DeployConfig.L1CancunTimeOffset = &genesisActivation
Expand All @@ -41,13 +41,13 @@ func withEcotone() faultDisputeConfigOpts {
}
}

func withSequencerWindowSize(size uint64) faultDisputeConfigOpts {
func WithSequencerWindowSize(size uint64) faultDisputeConfigOpts {
return func(cfg *op_e2e.SystemConfig) {
cfg.DeployConfig.SequencerWindowSize = size
}
}

func startFaultDisputeSystem(t *testing.T, opts ...faultDisputeConfigOpts) (*op_e2e.System, *ethclient.Client) {
func StartFaultDisputeSystem(t *testing.T, opts ...faultDisputeConfigOpts) (*op_e2e.System, *ethclient.Client) {
cfg := op_e2e.DefaultSystemConfig(t)
delete(cfg.Nodes, "verifier")
for _, opt := range opts {
Expand All @@ -64,7 +64,7 @@ func startFaultDisputeSystem(t *testing.T, opts ...faultDisputeConfigOpts) (*op_
return sys, sys.Clients["l1"]
}

func sendKZGPointEvaluationTx(t *testing.T, sys *op_e2e.System, l2Node string, privateKey *ecdsa.PrivateKey) *types.Receipt {
func SendKZGPointEvaluationTx(t *testing.T, sys *op_e2e.System, l2Node string, privateKey *ecdsa.PrivateKey) *types.Receipt {
return op_e2e.SendL2Tx(t, sys.Cfg, sys.Clients[l2Node], privateKey, func(opts *op_e2e.TxOpts) {
precompile := common.BytesToAddress([]byte{0x0a})
opts.Gas = 100_000
Expand Down

0 comments on commit f0be622

Please sign in to comment.