@@ -3,6 +3,7 @@ package devnet_tests
33import (
44 "bytes"
55 "context"
6+ "encoding/hex"
67 "fmt"
78 "math/big"
89 "os"
@@ -13,16 +14,20 @@ import (
1314 "testing"
1415 "time"
1516
17+ env "github.com/ethereum-optimism/optimism/espresso/environment"
18+ "github.com/ethereum-optimism/optimism/op-e2e/bindings"
19+ "github.com/ethereum-optimism/optimism/op-e2e/config/secrets"
1620 "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
1721 "github.com/ethereum-optimism/optimism/op-e2e/system/helpers"
22+ "github.com/ethereum-optimism/optimism/op-node/rollup"
23+ opclient "github.com/ethereum-optimism/optimism/op-service/client"
24+ "github.com/ethereum-optimism/optimism/op-service/sources"
25+ "github.com/ethereum/go-ethereum/accounts/abi/bind"
1826 "github.com/ethereum/go-ethereum/common"
1927 "github.com/ethereum/go-ethereum/core/types"
2028 "github.com/ethereum/go-ethereum/crypto"
2129 "github.com/ethereum/go-ethereum/ethclient"
2230 "github.com/ethereum/go-ethereum/log"
23-
24- env "github.com/ethereum-optimism/optimism/espresso/environment"
25- "github.com/ethereum-optimism/optimism/op-e2e/config/secrets"
2631)
2732
2833type Devnet struct {
@@ -31,8 +36,11 @@ type Devnet struct {
3136 outageTime time.Duration
3237 successTime time.Duration
3338
34- L2Seq * ethclient.Client
35- L2Verif * ethclient.Client
39+ L1 * ethclient.Client
40+ L2Seq * ethclient.Client
41+ L2SeqRollup * sources.RollupClient
42+ L2Verif * ethclient.Client
43+ L2VerifRollup * sources.RollupClient
3644}
3745
3846func NewDevnet (ctx context.Context , t * testing.T ) * Devnet {
@@ -70,6 +78,10 @@ func (d *Devnet) Up(verbose bool) (err error) {
7078 d .ctx ,
7179 "docker" , "compose" , "up" , "-d" ,
7280 )
81+ cmd .Env = append (
82+ cmd .Env ,
83+ fmt .Sprintf ("OP_BATCHER_PRIVATE_KEY=%s" , hex .EncodeToString (crypto .FromECDSA (d .secrets .Batcher ))),
84+ )
7385 buf := new (bytes.Buffer )
7486 cmd .Stderr = buf
7587 if err := cmd .Run (); err != nil {
@@ -112,10 +124,22 @@ func (d *Devnet) Up(verbose bool) (err error) {
112124 if err != nil {
113125 return err
114126 }
127+ d .L2SeqRollup , err = d .rollupClient ("op-node-sequencer" , 9545 )
128+ if err != nil {
129+ return err
130+ }
115131 d .L2Verif , err = d .serviceClient ("op-geth-verifier" , 8546 )
116132 if err != nil {
117133 return err
118134 }
135+ d .L2VerifRollup , err = d .rollupClient ("op-node-verifier" , 9546 )
136+ if err != nil {
137+ return err
138+ }
139+ d .L1 , err = d .serviceClient ("l1-geth" , 8545 )
140+ if err != nil {
141+ return err
142+ }
119143
120144 return nil
121145}
@@ -148,6 +172,28 @@ func (d *Devnet) ServiceRestart(service string) error {
148172 return nil
149173}
150174
175+ func (d * Devnet ) RollupConfig (ctx context.Context ) (* rollup.Config , error ) {
176+ return d .L2SeqRollup .RollupConfig (ctx )
177+ }
178+
179+ func (d * Devnet ) SystemConfig (ctx context.Context ) (* bindings.SystemConfig , * bind.TransactOpts , error ) {
180+ config , err := d .RollupConfig (ctx )
181+ if err != nil {
182+ return nil , nil , err
183+ }
184+ contract , err := bindings .NewSystemConfig (config .L1SystemConfigAddress , d .L1 )
185+ if err != nil {
186+ return nil , nil , err
187+ }
188+
189+ owner , err := bind .NewKeyedTransactorWithChainID (d .secrets .Deployer , config .L1ChainID )
190+ if err != nil {
191+ return nil , nil , err
192+ }
193+
194+ return contract , owner , nil
195+ }
196+
151197// Submits a transaction and waits until it is confirmed by the sequencer (but not necessarily the verifier).
152198func (d * Devnet ) SubmitL2Tx (applyTxOpts helpers.TxOptsFn ) (* types.Receipt , error ) {
153199 ctx , cancel := context .WithTimeout (d .ctx , 2 * time .Minute )
@@ -238,6 +284,15 @@ func (d *Devnet) RunL2Tx(applyTxOpts helpers.TxOptsFn) error {
238284 return d .VerifyL2Tx (receipt )
239285}
240286
287+ func (d * Devnet ) SendL1Tx (ctx context.Context , tx * types.Transaction ) (* types.Receipt , error ) {
288+ err := d .L1 .SendTransaction (ctx , tx )
289+ if err != nil {
290+ return nil , err
291+ }
292+
293+ return wait .ForReceiptOK (ctx , d .L1 , tx .Hash ())
294+ }
295+
241296type BurnReceipt struct {
242297 InitialBurnBalance * big.Int
243298 BurnAmount * big.Int
@@ -354,9 +409,23 @@ func (d *Devnet) serviceClient(service string, port uint16) (*ethclient.Client,
354409 if err != nil {
355410 return nil , fmt .Errorf ("could not get %s port: %w" , service , err )
356411 }
357- client , err := ethclient .DialContext (d .ctx , fmt .Sprintf ("http://localhost :%d" , port ))
412+ client , err := ethclient .DialContext (d .ctx , fmt .Sprintf ("http://127.0.0.1 :%d" , port ))
358413 if err != nil {
359414 return nil , fmt .Errorf ("could not open %s RPC client: %w" , service , err )
360415 }
361416 return client , nil
362417}
418+
419+ func (d * Devnet ) rollupClient (service string , port uint16 ) (* sources.RollupClient , error ) {
420+ port , err := d .hostPort (service , port )
421+ if err != nil {
422+ return nil , fmt .Errorf ("could not get %s port: %w" , service , err )
423+ }
424+ rpc , err := opclient .NewRPC (d .ctx , log .Root (), fmt .Sprintf ("http://127.0.0.1:%d" , port ), opclient .WithDialAttempts (10 ))
425+ if err != nil {
426+ return nil , fmt .Errorf ("could not open %s RPC client: %w" , service , err )
427+ }
428+
429+ client := sources .NewRollupClient (rpc )
430+ return client , nil
431+ }
0 commit comments