diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0ee9b0a..37fc5973 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,7 @@ jobs: go work init make test - test-integration: + test-e2e: runs-on: ubuntu-latest timeout-minutes: 25 steps: @@ -62,8 +62,8 @@ jobs: # Ignore the failure of a step and avoid terminating the job. continue-on-error: true - - name: Integration Tests + - name: E2E Tests if: env.GIT_DIFF run: | go work init - make test-integration + make test-e2e diff --git a/Makefile b/Makefile index 30ca1639..6aaf5b35 100644 --- a/Makefile +++ b/Makefile @@ -97,17 +97,17 @@ build-and-start-app: build-test-app use-main: go work edit -use . - go work edit -dropuse ./tests/integration + go work edit -dropuse ./tests/e2e -use-integration: +use-e2e: go work edit -dropuse . - go work edit -use ./tests/integration + go work edit -use ./tests/e2e tidy: go mod tidy gofmt -s -w ./ -.PHONY: docker-build docker-build-integration +.PHONY: docker-build docker-build-e2e ############################################################################### ## Docker ## ############################################################################### @@ -116,25 +116,34 @@ docker-build: use-main @echo "Building E2E Docker image..." @DOCKER_BUILDKIT=1 docker build -t skip-mev/block-sdk-e2e -f contrib/images/block-sdk.e2e.Dockerfile . -docker-build-integration: use-main - @echo "Building integration-test Docker image..." - @DOCKER_BUILDKIT=1 docker build -t block-sdk-integration -f contrib/images/block-sdk.integration.Dockerfile . +docker-build-e2e: use-main + @echo "Building e2e-test Docker image..." + @DOCKER_BUILDKIT=1 docker build -t block-sdk-e2e -f contrib/images/block-sdk.e2e.Dockerfile . ############################################################################### ### Tests ### ############################################################################### -TEST_INTEGRATION_DEPS = docker-build-integration use-integration -TEST_INTEGRATION_TAGS = integration +TEST_E2E_DEPS = docker-build-e2e use-e2e +TEST_E2E_TAGS = e2e -test-integration: $(TEST_INTEGRATION_DEPS) - @ echo "Running integration tests..." - @go test ./tests/integration/block_sdk_integration_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_INTEGRATION_TAGS)' +test-e2e: $(TEST_E2E_DEPS) + @ echo "Running e2e tests..." + @go test ./tests/e2e/block_sdk_e2e_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_E2E_TAGS)' test: use-main @go test -v -race $(shell go list ./... | grep -v tests/) -.PHONY: test test-integration +test-cover: tidy + @echo Running unit tests and creating coverage report... + @go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(shell go list ./... | grep -v tests/) + @sed -i '/.pb.go/d' $(COVER_FILE) + @sed -i '/.pulsar.go/d' $(COVER_FILE) + @sed -i '/.proto/d' $(COVER_FILE) + @sed -i '/.pb.gw.go/d' $(COVER_FILE) + + +.PHONY: test test-e2e test-cover ############################################################################### ### Protobuf ### diff --git a/block/base/options.go b/block/base/options.go index 7636a4f6..0d36f171 100644 --- a/block/base/options.go +++ b/block/base/options.go @@ -2,6 +2,7 @@ package base import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/block-sdk/block" ) diff --git a/block/base/tx_info.go b/block/base/tx_info.go index 3de609ec..a6c9ed93 100644 --- a/block/base/tx_info.go +++ b/block/base/tx_info.go @@ -7,6 +7,7 @@ import ( comettypes "github.com/cometbft/cometbft/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/block-sdk/block/utils" ) diff --git a/block/mocks/lane.go b/block/mocks/lane.go index 60a1351b..bc180349 100644 --- a/block/mocks/lane.go +++ b/block/mocks/lane.go @@ -256,7 +256,8 @@ func (_m *Lane) Select(_a0 context.Context, _a1 [][]byte) mempool.Iterator { func NewLane(t interface { mock.TestingT Cleanup(func()) -}) *Lane { +}, +) *Lane { mock := &Lane{} mock.Mock.Test(t) diff --git a/block/mocks/lane_mempool.go b/block/mocks/lane_mempool.go index 7e0ca4ce..530cf0f7 100644 --- a/block/mocks/lane_mempool.go +++ b/block/mocks/lane_mempool.go @@ -133,7 +133,8 @@ func (_m *LaneMempool) Select(_a0 context.Context, _a1 [][]byte) mempool.Iterato func NewLaneMempool(t interface { mock.TestingT Cleanup(func()) -}) *LaneMempool { +}, +) *LaneMempool { mock := &LaneMempool{} mock.Mock.Test(t) diff --git a/block/service/service_test.go b/block/service/service_test.go index 44e23719..1bd61896 100644 --- a/block/service/service_test.go +++ b/block/service/service_test.go @@ -8,6 +8,8 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/skip-mev/block-sdk/block" "github.com/skip-mev/block-sdk/block/service" "github.com/skip-mev/block-sdk/block/service/types" @@ -15,7 +17,6 @@ import ( "github.com/skip-mev/block-sdk/lanes/free" "github.com/skip-mev/block-sdk/lanes/mev" "github.com/skip-mev/block-sdk/testutils" - "github.com/stretchr/testify/require" ) func TestGetTxDistribution(t *testing.T) { diff --git a/block/utils/utils.go b/block/utils/utils.go index c0ecd187..82fad10c 100644 --- a/block/utils/utils.go +++ b/block/utils/utils.go @@ -8,6 +8,7 @@ import ( comettypes "github.com/cometbft/cometbft/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool" + signerextraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter" ) diff --git a/contrib/images/block-sdk.integration.Dockerfile b/contrib/images/block-sdk.e2e.Dockerfile similarity index 63% rename from contrib/images/block-sdk.integration.Dockerfile rename to contrib/images/block-sdk.e2e.Dockerfile index 8d7aee83..2d50f94c 100644 --- a/contrib/images/block-sdk.integration.Dockerfile +++ b/contrib/images/block-sdk.e2e.Dockerfile @@ -1,14 +1,13 @@ FROM golang:1.21-bullseye AS builder -WORKDIR /src/pob +WORKDIR /src/bsdk COPY . . -RUN go mod tidy -RUN make build-test-app +RUN go mod tidy && make build-test-app ## Prepare the final clear binary FROM ubuntu:rolling EXPOSE 26656 26657 1317 9090 7171 -COPY --from=builder /src/pob/build/* /usr/local/bin/ +COPY --from=builder /src/bsdk/build/* /usr/local/bin/ RUN apt-get update && apt-get install ca-certificates -y diff --git a/lanes/base/tx_info_test.go b/lanes/base/tx_info_test.go index a5abb069..f661e93e 100644 --- a/lanes/base/tx_info_test.go +++ b/lanes/base/tx_info_test.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/block-sdk/testutils" ) diff --git a/tests/app/lanes.go b/tests/app/lanes.go index bae08350..ef2549e7 100644 --- a/tests/app/lanes.go +++ b/tests/app/lanes.go @@ -2,6 +2,7 @@ package app import ( "cosmossdk.io/math" + signerextraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter" "github.com/skip-mev/block-sdk/block/base" defaultlane "github.com/skip-mev/block-sdk/lanes/base" diff --git a/tests/integration/block_sdk_integration_test.go b/tests/e2e/block_sdk_e2e_test.go similarity index 90% rename from tests/integration/block_sdk_integration_test.go rename to tests/e2e/block_sdk_e2e_test.go index 547dc97d..2831c813 100644 --- a/tests/integration/block_sdk_integration_test.go +++ b/tests/e2e/block_sdk_e2e_test.go @@ -1,4 +1,4 @@ -package integration_test +package e2e_test import ( "fmt" @@ -11,7 +11,7 @@ import ( ictestutil "github.com/strangelove-ventures/interchaintest/v8/testutil" "github.com/stretchr/testify/suite" - "github.com/skip-mev/block-sdk/tests/integration" + "github.com/skip-mev/block-sdk/tests/e2e" auctiontypes "github.com/skip-mev/block-sdk/x/auction/types" ) @@ -22,7 +22,7 @@ var ( denom = "stake" image = ibc.DockerImage{ - Repository: "block-sdk-integration", + Repository: "block-sdk-e2e", Version: "latest", UidGid: "1000:1000", } @@ -80,6 +80,6 @@ func MakeEncodingConfig() *testutil.TestEncodingConfig { return &cfg } -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, integration.NewIntegrationTestSuiteFromSpec(spec)) +func TestE2ETestSuite(t *testing.T) { + suite.Run(t, e2e.NewE2ETestSuiteFromSpec(spec)) } diff --git a/tests/integration/block_sdk_suite.go b/tests/e2e/block_sdk_suite.go similarity index 97% rename from tests/integration/block_sdk_suite.go rename to tests/e2e/block_sdk_suite.go index 72499985..c5856344 100644 --- a/tests/integration/block_sdk_suite.go +++ b/tests/e2e/block_sdk_suite.go @@ -1,4 +1,4 @@ -package integration +package e2e import ( "context" @@ -12,13 +12,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/skip-mev/block-sdk/lanes/base" - "github.com/skip-mev/block-sdk/lanes/free" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v8/ibc" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/skip-mev/block-sdk/lanes/base" + "github.com/skip-mev/block-sdk/lanes/free" ) const ( @@ -30,8 +31,8 @@ type committedTx struct { res *rpctypes.ResultTx } -// IntegrationTestSuite runs the Block SDK integration test-suite against a given interchaintest specification -type IntegrationTestSuite struct { +// E2ETestSuite runs the Block SDK e2e test-suite against a given interchaintest specification +type E2ETestSuite struct { suite.Suite // spec spec *interchaintest.ChainSpec @@ -53,14 +54,14 @@ type IntegrationTestSuite struct { bc *cosmos.Broadcaster } -func NewIntegrationTestSuiteFromSpec(spec *interchaintest.ChainSpec) *IntegrationTestSuite { - return &IntegrationTestSuite{ +func NewE2ETestSuiteFromSpec(spec *interchaintest.ChainSpec) *E2ETestSuite { + return &E2ETestSuite{ spec: spec, denom: "stake", } } -func (s *IntegrationTestSuite) WithDenom(denom string) *IntegrationTestSuite { +func (s *E2ETestSuite) WithDenom(denom string) *E2ETestSuite { s.denom = denom // update the bech32 prefixes @@ -70,14 +71,14 @@ func (s *IntegrationTestSuite) WithDenom(denom string) *IntegrationTestSuite { return s } -func (s *IntegrationTestSuite) WithKeyringOptions(cdc codec.Codec, opts keyring.Option) { +func (s *E2ETestSuite) WithKeyringOptions(cdc codec.Codec, opts keyring.Option) { s.broadcasterOverrides = &KeyringOverride{ cdc: cdc, keyringOptions: opts, } } -func (s *IntegrationTestSuite) SetupSuite() { +func (s *E2ETestSuite) SetupSuite() { // build the chain s.T().Log("building chain with spec", s.spec) s.chain = ChainBuilderFromChainSpec(s.T(), s.spec) @@ -101,12 +102,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.setupBroadcaster() } -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *E2ETestSuite) TearDownSuite() { // close the interchain s.ic.Close() } -func (s *IntegrationTestSuite) SetupSubTest() { +func (s *E2ETestSuite) SetupSubTest() { // wait for 1 block height // query height height, err := s.chain.(*cosmos.CosmosChain).Height(context.Background()) @@ -115,7 +116,7 @@ func (s *IntegrationTestSuite) SetupSubTest() { s.T().Logf("reached height %d", height+2) } -func (s *IntegrationTestSuite) TestQueryParams() { +func (s *E2ETestSuite) TestQueryParams() { // query params params := QueryAuctionParams(s.T(), s.chain) @@ -123,7 +124,7 @@ func (s *IntegrationTestSuite) TestQueryParams() { require.NoError(s.T(), params.Validate()) } -func (s *IntegrationTestSuite) TestMempoolService() { +func (s *E2ETestSuite) TestMempoolService() { resp, err := QueryMempool(s.T(), s.chain) s.Require().NoError(err) s.Require().Len(resp.Distribution, 3) @@ -136,7 +137,7 @@ func (s *IntegrationTestSuite) TestMempoolService() { // 2. All transactions execute as expected. // 3. The balance of the escrow account should be updated correctly. // 4. Top of block bids will be included in block proposals before other transactions -func (s *IntegrationTestSuite) TestValidBids() { +func (s *E2ETestSuite) TestValidBids() { params := QueryAuctionParams(s.T(), s.chain) escrowAddr := sdk.AccAddress(params.EscrowAccountAddress).String() @@ -383,7 +384,7 @@ func (s *IntegrationTestSuite) TestValidBids() { // that are included in the same block. // 5. If there is a block that has multiple valid bids with timeouts that are sufficiently far apart, // the bids should be executed respecting the highest bids until the timeout is reached. -func (s *IntegrationTestSuite) TestMultipleBids() { +func (s *E2ETestSuite) TestMultipleBids() { params := QueryAuctionParams(s.T(), s.chain) escrowAddr := sdk.AccAddress(params.EscrowAccountAddress).String() @@ -515,7 +516,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() { }) } -func (s *IntegrationTestSuite) TestInvalidBids() { +func (s *E2ETestSuite) TestInvalidBids() { params := QueryAuctionParams(s.T(), s.chain) s.Run("searcher is attempting to submit a bundle that includes another bid tx", func() { @@ -853,7 +854,7 @@ func (s *IntegrationTestSuite) TestInvalidBids() { // // 1. Transactions that qualify as free should not be deducted any fees. // 2. Transactions that do not qualify as free should be deducted the correct fees. -func (s *IntegrationTestSuite) TestFreeLane() { +func (s *E2ETestSuite) TestFreeLane() { validators := QueryValidators(s.T(), s.chain.(*cosmos.CosmosChain)) require.True(s.T(), len(validators) > 0) @@ -977,7 +978,7 @@ func (s *IntegrationTestSuite) TestFreeLane() { }) } -func (s *IntegrationTestSuite) TestLanes() { +func (s *E2ETestSuite) TestLanes() { validators := QueryValidators(s.T(), s.chain.(*cosmos.CosmosChain)) require.True(s.T(), len(validators) > 0) @@ -1276,7 +1277,7 @@ func (s *IntegrationTestSuite) TestLanes() { }) } -func (s *IntegrationTestSuite) TestNetwork() { +func (s *E2ETestSuite) TestNetwork() { amountToTest := time.NewTicker(time.Second * 30) defer amountToTest.Stop() diff --git a/tests/integration/chain_setup.go b/tests/e2e/chain_setup.go similarity index 93% rename from tests/integration/chain_setup.go rename to tests/e2e/chain_setup.go index e4bc41ee..137d36db 100644 --- a/tests/integration/chain_setup.go +++ b/tests/e2e/chain_setup.go @@ -1,4 +1,4 @@ -package integration +package e2e import ( "archive/tar" @@ -90,7 +90,7 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc } // CreateTx creates a new transaction to be signed by the given user, including a provided set of messages -func (s *IntegrationTestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, seqIncrement, height uint64, GasPrice int64, msgs ...sdk.Msg) []byte { +func (s *E2ETestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, seqIncrement, height uint64, GasPrice int64, msgs ...sdk.Msg) []byte { // create tx factory + Client Context txf, err := s.bc.GetFactory(ctx, user) s.Require().NoError(err) @@ -127,7 +127,7 @@ func (s *IntegrationTestSuite) CreateTx(ctx context.Context, chain *cosmos.Cosmo return bz } -func (s *IntegrationTestSuite) CreateDummyAuctionBidTx( +func (s *E2ETestSuite) CreateDummyAuctionBidTx( height uint64, searcher ibc.Wallet, bid sdk.Coin, @@ -148,7 +148,7 @@ func (s *IntegrationTestSuite) CreateDummyAuctionBidTx( } } -func (s *IntegrationTestSuite) CreateDummyNormalTx( +func (s *E2ETestSuite) CreateDummyNormalTx( from, to ibc.Wallet, coins sdk.Coins, sequenceOffset uint64, @@ -170,7 +170,7 @@ func (s *IntegrationTestSuite) CreateDummyNormalTx( } } -func (s *IntegrationTestSuite) CreateDummyFreeTx( +func (s *E2ETestSuite) CreateDummyFreeTx( user ibc.Wallet, validator sdk.ValAddress, delegation sdk.Coin, @@ -193,7 +193,7 @@ func (s *IntegrationTestSuite) CreateDummyFreeTx( } // SimulateTx simulates the provided messages, and checks whether the provided failure condition is met -func (s *IntegrationTestSuite) SimulateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg) { +func (s *E2ETestSuite) SimulateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg) { // create tx factory + Client Context txf, err := s.bc.GetFactory(ctx, user) s.Require().NoError(err) @@ -226,7 +226,7 @@ type Tx struct { } // CreateAuctionBidMsg creates a new AuctionBid tx signed by the given user, the order of txs in the MsgAuctionBid will be determined by the contents + order of the MessageForUsers -func (s *IntegrationTestSuite) CreateAuctionBidMsg(ctx context.Context, searcher cosmos.User, chain *cosmos.CosmosChain, bid sdk.Coin, txsPerUser []Tx) (*auctiontypes.MsgAuctionBid, [][]byte) { +func (s *E2ETestSuite) CreateAuctionBidMsg(ctx context.Context, searcher cosmos.User, chain *cosmos.CosmosChain, bid sdk.Coin, txsPerUser []Tx) (*auctiontypes.MsgAuctionBid, [][]byte) { // for each MessagesForUser get the signed bytes txs := make([][]byte, len(txsPerUser)) for i, tx := range txsPerUser { @@ -248,7 +248,7 @@ func (s *IntegrationTestSuite) CreateAuctionBidMsg(ctx context.Context, searcher // BroadcastTxs broadcasts the given messages for each user. This function returns the broadcasted txs. If a message // is not expected to be included in a block, set SkipInclusionCheck to true and the method // will not block on the tx's inclusion in a block, otherwise this method will block on the tx's inclusion -func (s *IntegrationTestSuite) BroadcastTxs(ctx context.Context, chain *cosmos.CosmosChain, txs []Tx) [][]byte { +func (s *E2ETestSuite) BroadcastTxs(ctx context.Context, chain *cosmos.CosmosChain, txs []Tx) [][]byte { return s.BroadcastTxsWithCallback(ctx, chain, txs, nil) } @@ -256,7 +256,7 @@ func (s *IntegrationTestSuite) BroadcastTxs(ctx context.Context, chain *cosmos.C // is not expected to be included in a block, set SkipInclusionCheck to true and the method // will not block on the tx's inclusion in a block, otherwise this method will block on the tx's inclusion. The callback // function is called for each tx that is included in a block. -func (s *IntegrationTestSuite) BroadcastTxsWithCallback( +func (s *E2ETestSuite) BroadcastTxsWithCallback( ctx context.Context, chain *cosmos.CosmosChain, txs []Tx, @@ -455,7 +455,7 @@ func TxHash(tx []byte) string { return strings.ToUpper(hex.EncodeToString(comettypes.Tx(tx).Hash())) } -func (s *IntegrationTestSuite) setupBroadcaster() { +func (s *E2ETestSuite) setupBroadcaster() { bc := cosmos.NewBroadcaster(s.T(), s.chain.(*cosmos.CosmosChain)) if s.broadcasterOverrides == nil { @@ -487,7 +487,7 @@ func (s *IntegrationTestSuite) setupBroadcaster() { } // sniped from here: https://github.com/strangelove-ventures/interchaintest ref: 9341b001214d26be420f1ca1ab0f15bad17faee6 -func (s *IntegrationTestSuite) keyringDirFromNode() string { +func (s *E2ETestSuite) keyringDirFromNode() string { node := s.chain.(*cosmos.CosmosChain).Nodes()[0] // create a temp-dir diff --git a/tests/integration/go.mod b/tests/e2e/go.mod similarity index 99% rename from tests/integration/go.mod rename to tests/e2e/go.mod index 2267cb02..fcf14ae8 100644 --- a/tests/integration/go.mod +++ b/tests/e2e/go.mod @@ -1,4 +1,4 @@ -module github.com/skip-mev/block-sdk/tests/integration +module github.com/skip-mev/block-sdk/tests/e2e go 1.21 diff --git a/tests/integration/go.sum b/tests/e2e/go.sum similarity index 100% rename from tests/integration/go.sum rename to tests/e2e/go.sum