From 1b863592faece139656fbdda1d24169f074d38c7 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 13 Aug 2024 18:53:55 +0530 Subject: [PATCH] fix: comments --- .github/workflows/infrastructure.yml | 2 +- testing/cmd/main.go | 50 +++++++++++++----------- testing/pkg/orchestrator/orchestrator.go | 40 +++++++++++-------- testing/pkg/tests/deposit/deposit.go | 2 +- testing/pkg/tests/preconf/preconf.go | 6 +-- testing/pkg/tests/staking/staking.go | 2 +- 6 files changed, 56 insertions(+), 46 deletions(-) diff --git a/.github/workflows/infrastructure.yml b/.github/workflows/infrastructure.yml index d1d96195e..7affd04b0 100644 --- a/.github/workflows/infrastructure.yml +++ b/.github/workflows/infrastructure.yml @@ -208,7 +208,7 @@ jobs: echo "DEPLOY_DURATION=$(date -ud "@$((END_TIME - START_TIME))" +'%H:%M:%S')" >> ${GITHUB_ENV} working-directory: infrastructure/nomad - - name: Run integration tests + - name: Run Integration tests if: ${{ env.IS_MANUAL_DEPLOYMENT == 'false' && success() }} working-directory: testing run: | diff --git a/testing/cmd/main.go b/testing/cmd/main.go index 555011657..8f9f0cda8 100644 --- a/testing/cmd/main.go +++ b/testing/cmd/main.go @@ -1,9 +1,8 @@ package main import ( - "context" "fmt" - "net" + "net/url" "os" "slices" "strings" @@ -21,6 +20,10 @@ var ( Usage: "Settlement RPC endpoint", Required: true, EnvVars: []string{"MEV_COMMIT_TEST_SETTLEMENT_RPC_ENDPOINT"}, + Action: func(_ *cli.Context, s string) error { + _, err := url.Parse(s) + return fmt.Errorf("invalid settlement RPC endpoint: %w", err) + }, } optionL1RPCEndpoint = &cli.StringFlag{ @@ -28,6 +31,10 @@ var ( Usage: "L1 RPC endpoint", Required: true, EnvVars: []string{"MEV_COMMIT_TEST_L1_RPC_ENDPOINT"}, + Action: func(_ *cli.Context, s string) error { + _, err := url.Parse(s) + return fmt.Errorf("invalid L1 RPC endpoint: %w", err) + }, } optionProviderRegistryAddress = &cli.StringFlag{ @@ -91,16 +98,16 @@ var ( } optionBootnodeRPCAddresses = &cli.StringSliceFlag{ - Name: "bootnode-rpc-addresses", - Usage: "Bootnode RPC addresses", - EnvVars: []string{"MEV_COMMIT_TEST_BOOTNODE_RPC_ADDRESSES"}, + Name: "bootnode-rpc-urls", + Usage: "Bootnode RPC URLs", + EnvVars: []string{"MEV_COMMIT_TEST_BOOTNODE_RPC_URLS"}, Action: func(c *cli.Context, addresses []string) error { if len(addresses) == 0 { return fmt.Errorf("at least one bootnode RPC address is required") } for _, address := range addresses { - if _, _, err := net.SplitHostPort(address); err != nil { - return fmt.Errorf("invalid bootnode RPC address") + if _, err := url.Parse(address); err != nil { + return fmt.Errorf("invalid bootnode RPC address: %w", err) } } return nil @@ -108,16 +115,16 @@ var ( } optionProviderRPCAddresses = &cli.StringSliceFlag{ - Name: "provider-rpc-addresses", - Usage: "Provider RPC addresses", - EnvVars: []string{"MEV_COMMIT_TEST_PROVIDER_RPC_ADDRESSES"}, + Name: "provider-rpc-urls", + Usage: "Provider RPC URLs", + EnvVars: []string{"MEV_COMMIT_TEST_PROVIDER_RPC_URLS"}, Action: func(c *cli.Context, addresses []string) error { if len(addresses) == 0 { return fmt.Errorf("at least one provider RPC address is required") } for _, address := range addresses { - if _, _, err := net.SplitHostPort(address); err != nil { - return fmt.Errorf("invalid provider RPC address") + if _, err := url.Parse(address); err != nil { + return fmt.Errorf("invalid provider RPC address: %w", err) } } return nil @@ -125,16 +132,16 @@ var ( } optionBidderRPCAddresses = &cli.StringSliceFlag{ - Name: "bidder-rpc-addresses", - Usage: "Bidder RPC addresses", - EnvVars: []string{"MEV_COMMIT_TEST_BIDDER_RPC_ADDRESSES"}, + Name: "bidder-rpc-urls", + Usage: "Bidder RPC URLs", + EnvVars: []string{"MEV_COMMIT_TEST_BIDDER_RPC_URLS"}, Action: func(c *cli.Context, addresses []string) error { if len(addresses) == 0 { return fmt.Errorf("at least one bidder RPC address is required") } for _, address := range addresses { - if _, _, err := net.SplitHostPort(address); err != nil { - return fmt.Errorf("invalid bidder RPC address") + if _, err := url.Parse(address); err != nil { + return fmt.Errorf("invalid bidder RPC address: %w", err) } } return nil @@ -201,9 +208,7 @@ func main() { optionLogLevel, optionLogTags, }, - Action: func(c *cli.Context) error { - return run(c) - }, + Action: run, } if err := app.Run(os.Args); err != nil { @@ -242,7 +247,6 @@ func run(c *cli.Context) error { logger.Info("running with options", "options", opts) o, err := orchestrator.NewOrchestrator(opts) - if err != nil { return err } @@ -252,14 +256,14 @@ func run(c *cli.Context) error { // Run test cases for _, tc := range tests.TestCases { logger.Info("running test case", "name", tc.Name) - if err := tc.Run(context.Background(), o, nil); err != nil { + if err := tc.Run(c.Context, o, nil); err != nil { logger.Error("test case failed", "name", tc.Name, "error", err) return fmt.Errorf("test case %s failed: %w", tc.Name, err) } logger.Info("test case passed", "name", tc.Name) } - logger.Info("all test cases passed") + logger.Info("all test cases passed successfully") return nil } diff --git a/testing/pkg/orchestrator/orchestrator.go b/testing/pkg/orchestrator/orchestrator.go index 47d17a3fe..740a59396 100644 --- a/testing/pkg/orchestrator/orchestrator.go +++ b/testing/pkg/orchestrator/orchestrator.go @@ -28,39 +28,45 @@ import ( ) type Orchestrator interface { + io.Closer + + // Providers returns the list of providers Providers() []Provider + // Bidders returns the list of bidders Bidders() []Bidder + // Bootnodes returns the list of bootnodes Bootnodes() []Bootnode + // Events returns the event manager used to listen to contract events Events() events.EventManager + // Logger returns the logger used by the orchestrator Logger() *slog.Logger - L1RPC() *ethclient.Client + // L1Client returns the L1 RPC client + L1Client() *ethclient.Client +} +type Node interface { io.Closer -} -type BaseNode interface { EthAddress() string DebugAPI() debugapiv1.DebugServiceClient - - io.Closer } type Provider interface { - BaseNode + Node ProviderAPI() providerapiv1.ProviderClient } type Bidder interface { - BaseNode + Node BidderAPI() bidderapiv1.BidderClient } type Bootnode interface { - BaseNode + Node } type Options struct { @@ -179,7 +185,7 @@ func (o *orchestrator) Bootnodes() []Bootnode { return o.bootnodes } -func (o *orchestrator) L1RPC() *ethclient.Client { +func (o *orchestrator) L1Client() *ethclient.Client { return o.l1RPC } @@ -215,7 +221,7 @@ func (o *orchestrator) Close() error { return errs } -func createNodes[T any](rpcAddrs []string, logger *slog.Logger) ([]T, error) { +func createNodes[T any](logger *slog.Logger, rpcAddrs []string) ([]T, error) { nodes := make([]T, 0, len(rpcAddrs)) for _, rpcAddr := range rpcAddrs { n, err := newNode(rpcAddr, logger) @@ -232,17 +238,17 @@ func createNodes[T any](rpcAddrs []string, logger *slog.Logger) ([]T, error) { } func NewOrchestrator(opts Options) (Orchestrator, error) { - providers, err := createNodes[Provider](opts.ProviderRPCAddresses, opts.Logger) + providers, err := createNodes[Provider](opts.Logger, opts.ProviderRPCAddresses) if err != nil { return nil, err } - bidders, err := createNodes[Bidder](opts.BidderRPCAddresses, opts.Logger) + bidders, err := createNodes[Bidder](opts.Logger, opts.BidderRPCAddresses) if err != nil { return nil, err } - bootnodes, err := createNodes[Bootnode](opts.BootnodeRPCAddresses, opts.Logger) + bootnodes, err := createNodes[Bootnode](opts.Logger, opts.BootnodeRPCAddresses) if err != nil { return nil, err } @@ -271,7 +277,7 @@ func NewOrchestrator(opts Options) (Orchestrator, error) { ) evtPublisher := publisher.NewWSPublisher( - nilStore{}, + dummyStore{}, opts.Logger.With("component", "ws_publisher"), ethClient, evtMgr, @@ -333,12 +339,12 @@ func getContractABIs(opts Options) (map[common.Address]*abi.ABI, error) { return abis, nil } -type nilStore struct{} +type dummyStore struct{} -func (nilStore) SetLastBlock(block uint64) error { +func (dummyStore) SetLastBlock(block uint64) error { return nil } -func (nilStore) LastBlock() (uint64, error) { +func (dummyStore) LastBlock() (uint64, error) { return 0, nil } diff --git a/testing/pkg/tests/deposit/deposit.go b/testing/pkg/tests/deposit/deposit.go index bf58e5f33..53b6a89ff 100644 --- a/testing/pkg/tests/deposit/deposit.go +++ b/testing/pkg/tests/deposit/deposit.go @@ -181,7 +181,7 @@ func RunCancelAutoDeposit(ctx context.Context, cluster orchestrator.Orchestrator depositsRcvd := make(map[common.Address][]*bidderregistry.BidderregistryBidderRegistered) withdrawalsRcvd := make(map[common.Address][]*bidderregistry.BidderregistryBidderWithdrawal) - eg := errgroup.Group{} + eg, ctx := errgroup.WithContext(ctx) egCtx, egCancel := context.WithCancel(ctx) defer egCancel() diff --git a/testing/pkg/tests/preconf/preconf.go b/testing/pkg/tests/preconf/preconf.go index 653a2705d..21c92c5ff 100644 --- a/testing/pkg/tests/preconf/preconf.go +++ b/testing/pkg/tests/preconf/preconf.go @@ -378,7 +378,7 @@ DONE: // handle reverting transactions. failedTxnPresent := false for _, h := range entry.Bid.TxHashes { - receipt, err := cluster.L1RPC().TransactionReceipt( + receipt, err := cluster.L1Client().TransactionReceipt( context.Background(), common.HexToHash(h), ) @@ -425,14 +425,14 @@ func getRandomBid( o orchestrator.Orchestrator, store *radix.Tree, ) (*BidEntry, error) { - blkNum, err := o.L1RPC().BlockNumber(context.Background()) + blkNum, err := o.L1Client().BlockNumber(context.Background()) if err != nil { return nil, err } blk, found := store.Get(blkKey(blkNum)) if !found { - blk, err = o.L1RPC().BlockByNumber(context.Background(), big.NewInt(int64(blkNum))) + blk, err = o.L1Client().BlockByNumber(context.Background(), big.NewInt(int64(blkNum))) if err != nil { return nil, err } diff --git a/testing/pkg/tests/staking/staking.go b/testing/pkg/tests/staking/staking.go index 3d17d5294..742fb86f9 100644 --- a/testing/pkg/tests/staking/staking.go +++ b/testing/pkg/tests/staking/staking.go @@ -34,7 +34,7 @@ func Run(ctx context.Context, cluster orchestrator.Orchestrator, _ any) error { return fmt.Errorf("failed to subscribe to provider registered events: %w", err) } - eg := errgroup.Group{} + eg, ctx := errgroup.WithContext(ctx) eg.Go(func() error { defer sub.Unsubscribe()