Skip to content

Commit

Permalink
Add verifier to e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natebeauregard committed Dec 20, 2024
1 parent d89fa5f commit 511914b
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 9 deletions.
55 changes: 46 additions & 9 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
opgenesis "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-node/bindings"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/polymerdao/monomer/e2e/url"
"github.com/polymerdao/monomer/environment"
)

Expand All @@ -28,6 +29,7 @@ type StackConfig struct {
L2OutputOracleCaller *bindings.L2OutputOracleCaller
L2Client *bftclient.HTTP
MonomerClient *MonomerClient
VerifierClient *MonomerClient
RollupConfig *rollup.Config
WaitL1 func(numBlocks int) error
WaitL2 func(numBlocks int) error
Expand All @@ -53,20 +55,20 @@ func Run(
"--address-prefix", "e2e",
"--monomer-path", monomerPath,
))
if err := monogenCmd.Run(); err != nil {
if err = monogenCmd.Run(); err != nil {
return fmt.Errorf("run monogen: %v", err)
}

setupHelperCmd := setupCmd(exec.CommandContext(ctx, filepath.Join(appDirPath, "setup-helper.sh"))) //nolint:gosec
setupHelperCmd.Dir = appDirPath
// Add the "GOFLAGS='-gcflags=all=-N -l'" environment variable to disable optimizations and make debugging easier.
setupHelperCmd.Env = append(os.Environ(), "e2eapp_HOME="+outDir)
if err := setupHelperCmd.Run(); err != nil {
if err = setupHelperCmd.Run(); err != nil {
return fmt.Errorf("run setup helper: %v", err)
}

//nolint:gosec // We aren't worried about tainted cmd args.
appCmd := setupCmd(exec.CommandContext(ctx,
sequencerAppCmd := setupCmd(exec.CommandContext(ctx,
filepath.Join(appDirPath, appName+"d"),
"monomer",
"start",
Expand Down Expand Up @@ -95,13 +97,48 @@ func Run(
"--log_no_color",
))
*/
appCmd.Dir = appDirPath
appCmd.Env = append(os.Environ(), "e2eapp_HOME="+outDir)
if err := appCmd.Start(); err != nil {
return fmt.Errorf("run app: %v", err)
sequencerAppCmd.Dir = appDirPath
sequencerAppCmd.Env = append(os.Environ(), "e2eapp_HOME="+outDir)
if err = sequencerAppCmd.Start(); err != nil {
return fmt.Errorf("run sequencer app: %v", err)
}
env.DeferErr("wait for app", func() error {
err := appCmd.Wait()
env.DeferErr("wait for sequencer app", func() error {
err = sequencerAppCmd.Wait()
if errors.Is(err, context.Canceled) {
return nil
}
return err
})

// Wait for the L1 instance to start up before starting the verifier node.
l1URL, err := url.ParseString("ws://127.0.0.1:9001")
if err != nil {
return fmt.Errorf("parse L1 URL: %v", err)
}
if !l1URL.IsReachable(context.Background()) {
return fmt.Errorf("l1 instance is not reachable: %v", err)
}

//nolint:gosec // We aren't worried about tainted cmd args.
verifierAppCmd := setupCmd(exec.CommandContext(ctx,
filepath.Join(appDirPath, appName+"d"),
"monomer",
"start",
"--minimum-gas-prices", "0.001wei",
"--log_no_color",
"--grpc.enable=false",
"--rpc.laddr", "tcp://127.0.0.1:26667",
"--monomer.dev-start",
"--monomer.engine-url", "ws://127.0.0.1:9010",
"--monomer.dev.op-node-url", "http://127.0.0.1:9012",
))
verifierAppCmd.Dir = appDirPath
verifierAppCmd.Env = append(os.Environ(), "e2eapp_HOME="+outDir)
if err = verifierAppCmd.Start(); err != nil {
return fmt.Errorf("run verifier app: %v", err)
}
env.DeferErr("wait for verifier app", func() error {
err = verifierAppCmd.Wait()
if errors.Is(err, context.Canceled) {
return nil
}
Expand Down
19 changes: 19 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var e2eTests = []struct {
name: "No Rollbacks",
run: checkForRollbacks,
},
{
name: "Verifier Sync",
run: verifierSync,
},
}

func TestE2E(t *testing.T) {
Expand All @@ -54,6 +58,9 @@ func TestE2E(t *testing.T) {
defer cancel()
require.NoError(t, e2e.Run(ctx, env, t.TempDir()))

// Wait for the node setup to finish.
time.Sleep(time.Second)

for _, test := range e2eTests {
t.Run(test.name, func(t *testing.T) {
test.run(t, newStackConfig(t))
Expand Down Expand Up @@ -83,6 +90,17 @@ func newStackConfig(t *testing.T) *e2e.StackConfig {
require.NoError(t, err)
l1Client := e2e.NewL1Client(l1RPCClient)

verifierEngineURL, err := url.ParseString("ws://127.0.0.1:9010")
require.NoError(t, err)
require.True(t, engineURL.IsReachable(context.Background()))
verifierRPCClient, err := rpc.Dial(verifierEngineURL.String())
require.NoError(t, err)
verifierClient := e2e.NewMonomerClient(verifierRPCClient)

verifierBftClient, err := bftclient.New("tcp://127.0.0.1:26667", "/websocket")
require.NoError(t, err)
require.NoError(t, verifierBftClient.Start())

l1Deployments, err := opdevnet.DefaultL1Deployments()
require.NoError(t, err)

Expand All @@ -106,6 +124,7 @@ func newStackConfig(t *testing.T) *e2e.StackConfig {
L2OutputOracleCaller: l2OutputOracleCaller,
L2Client: bftClient,
MonomerClient: monomerClient,
VerifierClient: verifierClient,
RollupConfig: &rollup.Config{
SeqWindowSize: deployConfig.SequencerWindowSize,
},
Expand Down
18 changes: 18 additions & 0 deletions e2e/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ func containsAttributesTx(t *testing.T, stack *e2e.StackConfig) {
t.Log("Monomer blocks contain the l1 attributes deposit tx")
}

func verifierSync(t *testing.T, stack *e2e.StackConfig) {
sequencerBlock, err := stack.MonomerClient.BlockByNumber(stack.Ctx, nil)
require.NoError(t, err)

// Wait for the verifier node to sync with the sequencer node
for i := 0; i < 10; i++ {
verifierBlock, err := stack.VerifierClient.BlockByHash(stack.Ctx, sequencerBlock.Header().Hash())
if verifierBlock != nil && err == nil {
t.Log("Verifier node can sync with the sequencer node")
return
}

err = stack.WaitL1(1)
require.NoError(t, err)
}
require.Fail(t, "verifier node did not sync with the sequencer node")
}

func ethRollupFlow(t *testing.T, stack *e2e.StackConfig) {
l1Client := stack.L1Client

Expand Down
Loading

0 comments on commit 511914b

Please sign in to comment.