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

Add verifier to e2e tests #325

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion e2e/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ func (m *MonomerClient) GenesisHash(ctx context.Context) (common.Hash, error) {
func (m *MonomerClient) BlockByNumber(ctx context.Context, number *big.Int) (*ethtypes.Block, error) {
block, err := m.ethclient.BlockByNumber(ctx, number)
if err != nil {
return nil, err
return nil, fmt.Errorf("block by number: %v", err)
}
return block, nil
}

func (m *MonomerClient) BlockByHash(ctx context.Context, hash common.Hash) (*ethtypes.Block, error) {
block, err := m.ethclient.BlockByHash(ctx, hash)
if err != nil {
return nil, fmt.Errorf("block by hash: %v", err)
}
return block, nil
}
Expand Down
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)
}
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved

//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)
}
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved
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")
}
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Loading
Loading