Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Aug 13, 2024
1 parent 878543a commit 1b86359
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
50 changes: 27 additions & 23 deletions testing/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package main

import (
"context"
"fmt"
"net"
"net/url"
"os"
"slices"
"strings"
Expand All @@ -21,13 +20,21 @@ 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{
Name: "l1-rpc-endpoint",
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{
Expand Down Expand Up @@ -91,50 +98,50 @@ 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
},
}

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
},
}

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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
40 changes: 23 additions & 17 deletions testing/pkg/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -271,7 +277,7 @@ func NewOrchestrator(opts Options) (Orchestrator, error) {
)

evtPublisher := publisher.NewWSPublisher(
nilStore{},
dummyStore{},
opts.Logger.With("component", "ws_publisher"),
ethClient,
evtMgr,
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion testing/pkg/tests/deposit/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions testing/pkg/tests/preconf/preconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion testing/pkg/tests/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1b86359

Please sign in to comment.