Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-e2e: Support external client in the e2e new tests #7346

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion op-e2e/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ func (eec *ExternalEthClient) WSAuthEndpoint() string {
return eec.Endpoints.WSAuthEndpoint
}

func (eec *ExternalEthClient) Close() {
func (eec *ExternalEthClient) Close() error {
eec.Session.Terminate()
select {
case <-time.After(5 * time.Second):
eec.Session.Kill()
case <-eec.Session.Exited:
}
return nil
}

func (er *ExternalRunner) Run(t *testing.T) *ExternalEthClient {
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/external_geth/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestShim(t *testing.T) {
Name: "TestShim",
BinPath: shimPath,
}).Run(t)
t.Cleanup(ec.Close)
t.Cleanup(func() { _ = ec.Close })

for _, endpoint := range []string{
ec.HTTPEndpoint(),
Expand Down
26 changes: 22 additions & 4 deletions op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ var (
// OpGeth is an actor that functions as a l2 op-geth node
// It provides useful functions for advancing and querying the chain
type OpGeth struct {
node *gn.Node
node EthInstance
l2Engine *sources.EngineClient
L2Client *ethclient.Client
L2RpcClient *rpc.Client
SystemConfig eth.SystemConfig
L1ChainConfig *params.ChainConfig
L2ChainConfig *params.ChainConfig
Expand Down Expand Up @@ -73,9 +74,21 @@ func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, e
SystemConfig: e2eutils.SystemConfigFromDeployConfig(cfg.DeployConfig),
}

node, _, err := geth.InitL2("l2", big.NewInt(int64(cfg.DeployConfig.L2ChainID)), l2Genesis, cfg.JWTFilePath)
require.Nil(t, err)
require.Nil(t, node.Start())
var node EthInstance
if cfg.ExternalL2Shim == "" {
gethNode, _, err := geth.InitL2("l2", big.NewInt(int64(cfg.DeployConfig.L2ChainID)), l2Genesis, cfg.JWTFilePath)
require.Nil(t, err)
require.Nil(t, gethNode.Start())
node = gethNode
} else {
externalNode := (&ExternalRunner{
Name: "Sequencer",
boyuan-chen marked this conversation as resolved.
Show resolved Hide resolved
BinPath: cfg.ExternalL2Shim,
Genesis: l2Genesis,
JWTPath: cfg.JWTFilePath,
}).Run(t)
node = externalNode
}

auth := rpc.WithHTTPAuth(gn.NewJWTAuth(cfg.JWTSecret))
l2Node, err := client.NewRPC(ctx, logger, node.WSAuthEndpoint(), client.WithGethRPCOptions(auth))
Expand All @@ -93,12 +106,16 @@ func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, e
l2Client, err := ethclient.Dial(node.HTTPEndpoint())
require.Nil(t, err)

l2RpcClient, err := rpc.Dial(node.HTTPEndpoint())
require.Nil(t, err)
boyuan-chen marked this conversation as resolved.
Show resolved Hide resolved

genesisPayload, err := eth.BlockAsPayload(l2GenesisBlock)

require.Nil(t, err)
return &OpGeth{
node: node,
L2Client: l2Client,
L2RpcClient: l2RpcClient,
l2Engine: l2Engine,
SystemConfig: rollupGenesis.SystemConfig,
L1ChainConfig: l1Genesis.Config,
Expand All @@ -112,6 +129,7 @@ func (d *OpGeth) Close() {
_ = d.node.Close()
d.l2Engine.Close()
d.L2Client.Close()
d.L2RpcClient.Close()
}

// AddL2Block Appends a new L2 block to the current chain including the specified transactions
Expand Down
6 changes: 2 additions & 4 deletions op-e2e/op_geth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestMissingGasLimit(t *testing.T) {
attrs.GasLimit = nil

res, err := opGeth.StartBlockBuilding(ctx, attrs)
require.Error(t, err)
require.ErrorIs(t, err, eth.InputError{})
require.Equal(t, eth.InvalidPayloadAttributes, err.(eth.InputError).Code)
require.Nil(t, res)
Expand Down Expand Up @@ -157,15 +158,12 @@ func TestGethOnlyPendingBlockIsLatest(t *testing.T) {
require.NoError(t, opGeth.L2Client.SendTransaction(ctx, tx), "send tx to make pending work different")
checkPending("prepared", 0)

rpcClient := opGeth.node.Attach()
defer rpcClient.Close()

// Wait for tx to be in tx-pool, for it to be picked up in block building
var txPoolStatus struct {
Pending hexutil.Uint64 `json:"pending"`
}
for i := 0; i < 5; i++ {
require.NoError(t, rpcClient.CallContext(ctx, &txPoolStatus, "txpool_status"))
require.NoError(t, opGeth.L2RpcClient.CallContext(ctx, &txPoolStatus, "txpool_status"))
if txPoolStatus.Pending == 0 {
time.Sleep(time.Second)
} else {
Expand Down
6 changes: 3 additions & 3 deletions op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func (gi *GethInstance) HTTPAuthEndpoint() string {
return gi.Node.HTTPAuthEndpoint()
}

func (gi *GethInstance) Close() {
gi.Node.Close()
func (gi *GethInstance) Close() error {
return gi.Node.Close()
}

// EthInstance is either an in process Geth or external process exposing its
Expand All @@ -235,7 +235,7 @@ type EthInstance interface {
WSEndpoint() string
HTTPAuthEndpoint() string
WSAuthEndpoint() string
Close()
Close() error
}

type System struct {
Expand Down