Commit 9223f920 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #7436 from ethereum-optimism/aj/external-client

op-e2e: Support external client in the e2e new tests
parents 058c796f c8fad370
......@@ -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 {
......
......@@ -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(),
......
......@@ -38,7 +38,7 @@ 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
SystemConfig eth.SystemConfig
......@@ -73,9 +73,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: "l2",
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))
......
......@@ -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)
......@@ -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.L2Client.Client().Call(&txPoolStatus, "txpool_status"))
if txPoolStatus.Pending == 0 {
time.Sleep(time.Second)
} else {
......
......@@ -225,8 +225,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
......@@ -236,7 +236,7 @@ type EthInstance interface {
WSEndpoint() string
HTTPAuthEndpoint() string
WSAuthEndpoint() string
Close()
Close() error
}
type System struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment