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 19, 2024
1 parent d89fa5f commit c465f05
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 9 deletions.
49 changes: 40 additions & 9 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"syscall"
"time"

bftclient "github.com/cometbft/cometbft/rpc/client/http"
opbindings "github.com/ethereum-optimism/optimism/op-bindings/bindings"
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,42 @@ 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.
time.Sleep(time.Second)

//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 All @@ -76,6 +83,17 @@ func newStackConfig(t *testing.T) *e2e.StackConfig {
require.NoError(t, err)
require.NoError(t, bftClient.Start())

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())

l1URL, err := url.ParseString("ws://127.0.0.1:9001")
require.NoError(t, err)
require.True(t, l1URL.IsReachable(context.Background()))
Expand Down Expand Up @@ -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
17 changes: 17 additions & 0 deletions e2e/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ 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 10 seconds 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
}

time.Sleep(time.Second)
}
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 c465f05

Please sign in to comment.