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

feat: automated integration tests #252

Merged
merged 31 commits into from
Aug 13, 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
18 changes: 18 additions & 0 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ jobs:
echo "DEPLOY_DURATION=$(date -ud "@$((END_TIME - START_TIME))" +'%H:%M:%S')" >> ${GITHUB_ENV}
working-directory: infrastructure/nomad

- name: Run Integration tests
if: ${{ env.IS_MANUAL_DEPLOYMENT == 'false' && success() }}
working-directory: testing
run: |
CONTRACTS_JSON=$(curl -s http://127.0.0.1:1010/contracts.json)
export MEV_COMMIT_TEST_PROVIDER_REGISTRY_ADDRESS=$(echo $CONTRACTS_JSON | jq -r '.ProviderRegistry')
export MEV_COMMIT_TEST_BIDDER_REGISTRY_ADDRESS=$(echo $CONTRACTS_JSON | jq -r '.BidderRegistry')
export MEV_COMMIT_TEST_BLOCKTRACKER_CONTRACT_ADDRESS=$(echo $CONTRACTS_JSON | jq -r '.BlockTracker')
export MEV_COMMIT_TEST_PRECONF_CONTRACT_ADDRESS=$(echo $CONTRACTS_JSON | jq -r '.PreConfCommitmentStore')
export MEV_COMMIT_TEST_ORACLE_CONTRACT_ADDRESS=$(echo $CONTRACTS_JSON | jq -r '.Oracle')
export MEV_COMMIT_TEST_L1_RPC_ENDPOINT="${{ secrets.L1_RPC_URL }}"
go build -ldflags="-s -w" -o mev-commit-test ./cmd/main.go
./mev-commit-test \
--settlement-rpc-endpoint ws://127.0.0.1:8546 \
--bootnode-rpc-urls 127.0.0.1:13524 \
--provider-rpc-urls 127.0.0.1:13624 \
--bidder-rpc-urls 127.0.0.1:13724

- name: Notify - Deployment Successful
if: ${{ env.IS_MANUAL_DEPLOYMENT == 'true' && success() }}
run: |
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ use (
./infrastructure/tools/keystore-generator
./oracle
./p2p
./testing
./x
)
5 changes: 3 additions & 2 deletions infrastructure/nomad/playbooks/variables/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ jobs:
p2p:
static: 13522
to: 13522
rpc:
static: 13524
to: 13524
env:
type: bootnode
tls_crt_file: "{{ tls_crt_file }}"
Expand Down Expand Up @@ -514,8 +517,6 @@ profiles:
- *mev_commit_oracle_job
- *mev_commit_bidder_node1_job
- *mev_commit_bidder_node1_funder_job
- *mev_commit_provider_emulator_node1_job
- *mev_commit_bidder_emulator_node1_job
- *mev_commit_faucet_job

devnet:
Expand Down
274 changes: 274 additions & 0 deletions testing/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
package main

import (
"fmt"
"net"
"net/url"
"os"
"slices"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/primev/mev-commit/testing/pkg/orchestrator"
"github.com/primev/mev-commit/testing/pkg/tests"
"github.com/primev/mev-commit/x/util"
"github.com/urfave/cli/v2"
)

var (
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
optionSettlementRPCEndpoint = &cli.StringFlag{
Name: "settlement-rpc-endpoint",
Usage: "Settlement RPC endpoint",
Required: true,
EnvVars: []string{"MEV_COMMIT_TEST_SETTLEMENT_RPC_ENDPOINT"},
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
Action: func(_ *cli.Context, s string) error {
if _, err := url.Parse(s); err != nil {
return fmt.Errorf("invalid settlement RPC endpoint: %w", err)
}
return nil
},
}

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 {
if _, err := url.Parse(s); err != nil {
return fmt.Errorf("invalid L1 RPC endpoint: %w", err)
}
return nil
},
}

optionProviderRegistryAddress = &cli.StringFlag{
Name: "provider-registry-address",
Usage: "Provider registry address",
EnvVars: []string{"MEV_COMMIT_TEST_PROVIDER_REGISTRY_ADDRESS"},
Action: func(c *cli.Context, address string) error {
if !common.IsHexAddress(address) {
return fmt.Errorf("invalid provider registry address")
}
return nil
},
}

optionBidderRegistryAddress = &cli.StringFlag{
Name: "bidder-registry-address",
Usage: "Bidder registry address",
EnvVars: []string{"MEV_COMMIT_TEST_BIDDER_REGISTRY_ADDRESS"},
Action: func(c *cli.Context, address string) error {
if !common.IsHexAddress(address) {
return fmt.Errorf("invalid bidder registry address")
}
return nil
},
}

optionPreconfContractAddress = &cli.StringFlag{
Name: "preconf-contract-address",
Usage: "Preconfirmation contract address",
EnvVars: []string{"MEV_COMMIT_TEST_PRECONF_CONTRACT_ADDRESS"},
Action: func(c *cli.Context, address string) error {
if !common.IsHexAddress(address) {
return fmt.Errorf("invalid preconf contract address")
}
return nil
},
}

optionBlocktrackerContractAddress = &cli.StringFlag{
Name: "blocktracker-contract-address",
Usage: "Blocktracker contract address",
EnvVars: []string{"MEV_COMMIT_TEST_BLOCKTRACKER_CONTRACT_ADDRESS"},
Action: func(c *cli.Context, address string) error {
if !common.IsHexAddress(address) {
return fmt.Errorf("invalid provider registry address")
}
return nil
},
}

optionOracleContractAddress = &cli.StringFlag{
Name: "oracle-contract-address",
Usage: "Oracle contract address",
EnvVars: []string{"MEV_COMMIT_TEST_ORACLE_CONTRACT_ADDRESS"},
Action: func(c *cli.Context, address string) error {
if !common.IsHexAddress(address) {
return fmt.Errorf("invalid oracle address")
}
return nil
},
}

optionBootnodeRPCAddresses = &cli.StringSliceFlag{
Name: "bootnode-rpc-urls",
Usage: "Bootnode RPC URLs",
EnvVars: []string{"MEV_COMMIT_TEST_BOOTNODE_RPC_URLS"},
Action: func(c *cli.Context, addresses []string) error {
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
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: %w", err)
}
}
return nil
},
}

optionProviderRPCAddresses = &cli.StringSliceFlag{
Name: "provider-rpc-urls",
Usage: "Provider RPC URLs",
EnvVars: []string{"MEV_COMMIT_TEST_PROVIDER_RPC_URLS"},
Action: func(c *cli.Context, addresses []string) error {
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
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: %w", err)
}
}
return nil
},
}

optionBidderRPCAddresses = &cli.StringSliceFlag{
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 {
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
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: %w", err)
}
}
return nil
},
}

optionLogFmt = &cli.StringFlag{
Name: "log-fmt",
Usage: "log format to use, options are 'text' or 'json'",
EnvVars: []string{"MEV_COMMIT_TEST_LOG_FMT"},
Value: "text",
Action: func(ctx *cli.Context, s string) error {
if !slices.Contains([]string{"text", "json"}, s) {
return fmt.Errorf("invalid log format")
}
return nil
},
}

optionLogLevel = &cli.StringFlag{
Name: "log-level",
Usage: "log level to use, options are 'debug', 'info', 'warn', 'error'",
EnvVars: []string{"MEV_COMMIT_TEST_LOG_LEVEL"},
Value: "info",
Action: func(ctx *cli.Context, s string) error {
if !slices.Contains([]string{"debug", "info", "warn", "error"}, s) {
return fmt.Errorf("invalid log level")
}
return nil
},
}

optionLogTags = &cli.StringFlag{
Name: "log-tags",
Usage: "log tags is a comma-separated list of <name:value> pairs that will be inserted into each log line",
EnvVars: []string{"MEV_COMMIT_TEST_LOG_TAGS"},
Action: func(ctx *cli.Context, s string) error {
for i, p := range strings.Split(s, ",") {
if len(strings.Split(p, ":")) != 2 {
return fmt.Errorf("invalid log-tags at index %d, expecting <name:value>", i)
}
}
return nil
},
}
)

func main() {
app := &cli.App{
Name: "mev-commit-test",
Usage: "MEV commit test",
Flags: []cli.Flag{
optionSettlementRPCEndpoint,
optionL1RPCEndpoint,
optionProviderRegistryAddress,
optionBidderRegistryAddress,
optionPreconfContractAddress,
optionBlocktrackerContractAddress,
optionOracleContractAddress,
optionBootnodeRPCAddresses,
optionProviderRPCAddresses,
optionBidderRPCAddresses,
optionLogFmt,
optionLogLevel,
optionLogTags,
},
Action: run,
}

if err := app.Run(os.Args); err != nil {
fmt.Println(err)
os.Exit(1)
}

os.Exit(0)
}

func run(c *cli.Context) error {
logger, err := util.NewLogger(
c.String(optionLogLevel.Name),
c.String(optionLogFmt.Name),
c.String(optionLogTags.Name),
c.App.Writer,
)
if err != nil {
return fmt.Errorf("failed to create logger: %w", err)
}

opts := orchestrator.Options{
SettlementRPCEndpoint: c.String(optionSettlementRPCEndpoint.Name),
L1RPCEndpoint: c.String(optionL1RPCEndpoint.Name),
ProviderRegistryAddress: common.HexToAddress(c.String(optionProviderRegistryAddress.Name)),
BidderRegistryAddress: common.HexToAddress(c.String(optionBidderRegistryAddress.Name)),
PreconfContractAddress: common.HexToAddress(c.String(optionPreconfContractAddress.Name)),
BlockTrackerContractAddress: common.HexToAddress(c.String(optionBlocktrackerContractAddress.Name)),
OracleContractAddress: common.HexToAddress(c.String(optionOracleContractAddress.Name)),
BootnodeRPCAddresses: c.StringSlice(optionBootnodeRPCAddresses.Name),
ProviderRPCAddresses: c.StringSlice(optionProviderRPCAddresses.Name),
BidderRPCAddresses: c.StringSlice(optionBidderRPCAddresses.Name),
Logger: logger,
}

logger.Info("running with options", "options", opts)

o, err := orchestrator.NewOrchestrator(opts)
if err != nil {
return err
}

defer o.Close()

// Run test cases
for _, tc := range tests.TestCases {
logger.Info("running test case", "name", tc.Name)
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)
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved
}
logger.Info("test case passed", "name", tc.Name)
}

logger.Info("all test cases passed successfully")

return nil
}
66 changes: 66 additions & 0 deletions testing/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module github.com/primev/mev-commit/testing

go 1.22

require (
github.com/armon/go-radix v1.0.0
github.com/ethereum/go-ethereum v1.13.14
github.com/primev/mev-commit/contracts-abi v0.0.1
github.com/primev/mev-commit/p2p v0.0.1
github.com/primev/mev-commit/x v0.0.1
github.com/urfave/cli/v2 v2.27.1
golang.org/x/sync v0.7.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.2
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240221180331-f05a6f4403ce.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/primev/mev-commit/p2p => ../p2p

replace github.com/primev/mev-commit/contracts-abi => ../contracts-abi

replace github.com/primev/mev-commit/x => ../x
Loading
Loading