From f35ca5e1f62de5944418cf294444e4fc4371c4a8 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Mon, 5 Jan 2026 16:40:29 +0100 Subject: [PATCH] Fix prefund L2 addresses --- playground/artifacts.go | 10 +++++++++- playground/artifacts_test.go | 18 ++++++++++++++++++ playground/components_test.go | 14 +++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/playground/artifacts.go b/playground/artifacts.go index 6105587a..a622325b 100644 --- a/playground/artifacts.go +++ b/playground/artifacts.go @@ -257,7 +257,7 @@ func (b *ArtifactsBuilder) Build(out *output) error { // override l2 genesis, make the timestamp start 2 seconds after the L1 genesis input := map[string]interface{}{ "timestamp": hexutil.Uint64(opTimestamp).String(), - "allocs": allocs, + "alloc": allocs, } if forkTime != nil { // We need to enable prague on the EL to enable the engine v4 calls @@ -422,6 +422,14 @@ func NewOutput(dst string) (*output, error) { return out, nil } +func (o *output) Read(path string) (string, error) { + data, err := os.ReadFile(filepath.Join(o.dst, path)) + if err != nil { + return "", err + } + return string(data), nil +} + func (o *output) AbsoluteDstPath() (string, error) { return filepath.Abs(o.dst) } diff --git a/playground/artifacts_test.go b/playground/artifacts_test.go index 083e66de..a67b1f50 100644 --- a/playground/artifacts_test.go +++ b/playground/artifacts_test.go @@ -1,8 +1,12 @@ package playground import ( + "encoding/json" "os" "testing" + + "github.com/ethereum/go-ethereum/core" + "github.com/stretchr/testify/require" ) func TestEnodeGeneration(t *testing.T) { @@ -17,6 +21,20 @@ func TestEnodeGeneration(t *testing.T) { } } +func TestL2PrefundedAccounts(t *testing.T) { + o := newTestOutput(t) + + b := NewArtifactsBuilder() + require.NoError(t, b.Build(o)) + + genesisRaw, err := o.Read("l2-genesis.json") + require.NoError(t, err) + + var genesis core.Genesis + require.NoError(t, json.Unmarshal([]byte(genesisRaw), &genesis)) + require.Len(t, genesis.Alloc, 10) +} + func newTestOutput(t *testing.T) *output { dir, err := os.MkdirTemp("/tmp", "test-output") if err != nil { diff --git a/playground/components_test.go b/playground/components_test.go index df2b6567..ef77c032 100644 --- a/playground/components_test.go +++ b/playground/components_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "math/big" "math/rand" "net/http" "os" @@ -14,6 +15,7 @@ import ( "testing" "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/rpc" "github.com/stretchr/testify/require" @@ -23,7 +25,17 @@ func TestRecipeOpstackSimple(t *testing.T) { tt := newTestFramework(t) defer tt.Close() - tt.test(&OpRecipe{}, nil) + m := tt.test(&OpRecipe{}, nil) + + httpPort := m.MustGetService("op-geth").MustGetPort("http") + client, err := ethclient.Dial(fmt.Sprintf("http://localhost:%d", httpPort.HostPort)) + require.NoError(t, err) + + // validate that the default addresses are prefunded + knownAddress := common.HexToAddress("0xf49Fd6e51aad88F6F4ce6aB8827279cffFb92266") + balance, err := client.BalanceAt(context.Background(), knownAddress, nil) + require.NoError(t, err) + require.NotEqual(t, balance, big.NewInt(0)) } func TestRecipeOpstackExternalBuilder(t *testing.T) {