|
| 1 | +package osaka |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + "os/exec" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + "time" |
| 11 | + |
| 12 | + "github.com/ethereum-optimism/optimism/op-batcher/batcher" |
| 13 | + "github.com/ethereum-optimism/optimism/op-batcher/flags" |
| 14 | + "github.com/ethereum-optimism/optimism/op-chain-ops/devkeys" |
| 15 | + "github.com/ethereum-optimism/optimism/op-devstack/devtest" |
| 16 | + "github.com/ethereum-optimism/optimism/op-devstack/presets" |
| 17 | + "github.com/ethereum-optimism/optimism/op-devstack/stack" |
| 18 | + "github.com/ethereum-optimism/optimism/op-devstack/sysgo" |
| 19 | + "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/intentbuilder" |
| 20 | + "github.com/ethereum-optimism/optimism/op-service/eth" |
| 21 | +) |
| 22 | + |
| 23 | +const osakaOffset = 30 |
| 24 | + |
| 25 | +func TestMain(m *testing.M) { |
| 26 | + // If the env var is unset, use geth (should be installed with mise). |
| 27 | + // Note that we always want a subprocess L1 EL for these tests because (as of right now) the |
| 28 | + // op-geth version we use in the monorepo does not include enough Osaka support. |
| 29 | + if _, ok := os.LookupEnv(sysgo.GethExecPathEnvVar); !ok { |
| 30 | + cmd := exec.Command("mise", "which", "geth") |
| 31 | + buf := bytes.NewBuffer([]byte{}) |
| 32 | + cmd.Stdout = buf |
| 33 | + if err := cmd.Run(); err == nil { |
| 34 | + execPath := strings.TrimSpace(buf.String()) |
| 35 | + fmt.Println("Found mise-installed geth:", execPath) |
| 36 | + _ = os.Setenv(sysgo.GethExecPathEnvVar, execPath) |
| 37 | + defer func() { |
| 38 | + _ = os.Setenv(sysgo.GethExecPathEnvVar, "") |
| 39 | + }() |
| 40 | + } else { |
| 41 | + fmt.Printf("Failed to find mise-installed geth: %v\n", err) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + ids := sysgo.NewDefaultMinimalSystemIDs(sysgo.DefaultL1ID, sysgo.DefaultL2AID) |
| 46 | + opt := stack.Combine[*sysgo.Orchestrator]() |
| 47 | + opt.Add(sysgo.DefaultMinimalSystem(&ids)) |
| 48 | + opt.Add(sysgo.WithDeployerOptions( |
| 49 | + func(_ devtest.P, _ devkeys.Keys, builder intentbuilder.Builder) { |
| 50 | + _, l1Config := builder.WithL1(ids.L1.ChainID()) |
| 51 | + l1Config.WithOsakaOffset(osakaOffset) |
| 52 | + })) |
| 53 | + opt.Add(sysgo.WithBatcherOption(func(_ stack.L2BatcherID, cfg *batcher.CLIConfig) { |
| 54 | + cfg.DataAvailabilityType = flags.BlobsType |
| 55 | + })) |
| 56 | + presets.DoMain(m, stack.MakeCommon(opt)) |
| 57 | +} |
| 58 | + |
| 59 | +func TestOsakaActivation(gt *testing.T) { |
| 60 | + t := devtest.SerialT(gt) |
| 61 | + sys := presets.NewMinimal(t) |
| 62 | + osakaActivationTime := *sys.L1Network.Escape().ChainConfig().OsakaTime |
| 63 | + t.Log("Waiting for Osaka to activate...") |
| 64 | + for range time.Tick(sys.L1EL.EstimateBlockTime()) { |
| 65 | + ref := sys.L1EL.BlockRefByLabel(eth.Unsafe) |
| 66 | + if ref.Time >= osakaActivationTime { |
| 67 | + break |
| 68 | + } |
| 69 | + t.Logf("Waiting for Osaka activation currentBlock=%d remainingTime=%d", ref.Number, osakaActivationTime-ref.Time) |
| 70 | + } |
| 71 | + t.Log("Osaka activated") |
| 72 | + sys.L1EL.WaitForFinalization() |
| 73 | +} |
0 commit comments