e2e

package module
v1.1.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

README

Block SDK E2E Tests

Integrating/Running Tests In Your Project

The Block SDK E2E tests are built around interchaintest. To run the full set of predefined test cases using your chain you can follow the steps below:

Integrate the Block SDK into your project

You will need to pull in the Block SDK as a dependency of your project. You can follow the guides located in our integration docs or this README for detailed instructions.
You can refer to this PR as one example of how the Block SDK can be integrated into an application. Be aware that each chain will have different requirements and this example may not be fully applicable to yours. Additionally, future versions may introduce new requirements.

Define a container image

Interchaintest will require a Docker image in order to spin up your chain's application. If you do not already have a container build setup that launches your application's binary you will need to define one.
An example of the Block SDK's test app's Docker build can be referenced here.

Create an InterchainTest Chain Spec

The test suite uses the interchaintest.ChainSpec to define the specifics around running your application. You'll need to define the number of validator and full node containers to run, the docker image, the genesis state, encoding config, and various other variables.
Some examples of ChainSpecs follow:

Instantiate the test suite and run the tests

You will need to pull the Block SDK's tests into your project as a separate dependency. It might be useful to do this in a separate go submodule specifically for running these tests (for example)

github.com/skip-mev/block-sdk/tests/integration {vLatest}

The following snippet is usually suitable.

func TestBlockSDKSuite(t *testing.T) {
	s := integration.NewIntegrationTestSuiteFromSpec(spec)
	s.WithDenom(denom)
	s.WithKeyringOptions(encodingConfig.Codec, keyring.Option())
	suite.Run(t, s)
Run the tests

Add a separate makefile target to run your tests.

go test -v -race -run TestBlockSDKSuite

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Block

func Block(t *testing.T, chain *cosmos.CosmosChain, height int64) *rpctypes.ResultBlock

Block returns the block at the given height

func BuildInterchain

func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interchaintest.Interchain

BuildInterchain creates a new Interchain testing env with the configured Block SDK CosmosChain

func ChainBuilderFromChainSpec

func ChainBuilderFromChainSpec(t *testing.T, spec *interchaintest.ChainSpec) ibc.Chain

ChainBuilderFromChainSpec creates an interchaintest chain builder factory given a ChainSpec and returns the associated chain

func QueryAccountBalance

func QueryAccountBalance(t *testing.T, chain ibc.Chain, address, denom string) int64

QueryAccountBalance queries a given account's balance on the chain

func QueryAccountSequence

func QueryAccountSequence(t *testing.T, chain *cosmos.CosmosChain, address string) uint64

QueryAccountSequence

func QueryAuctionParams

func QueryAuctionParams(t *testing.T, chain ibc.Chain) auctiontypes.Params

QueryAuctionParams queries the x/auction module's params

func QueryMempool

func QueryMempool(t *testing.T, chain ibc.Chain) (*servicetypes.GetTxDistributionResponse, error)

QueryMempool queries the mempool of the given chain

func QueryValidators

func QueryValidators(t *testing.T, chain *cosmos.CosmosChain) []sdk.ValAddress

QueryValidators queries for all of the network's validators

func TxHash

func TxHash(tx []byte) string

func VerifyBlockWithExpectedBlock

func VerifyBlockWithExpectedBlock(t *testing.T, chain *cosmos.CosmosChain, height uint64, txs [][]byte)

VerifyBlockWithExpectedBlock takes in a list of raw tx bytes and compares each tx hash to the tx hashes in the block. The expected block is the block that should be returned by the chain at the given height.

func WaitForHeight

func WaitForHeight(t *testing.T, chain *cosmos.CosmosChain, height uint64)

WaitForHeight waits for the chain to reach the given height

Types

type E2ETestSuite

type E2ETestSuite struct {
	suite.Suite
	// contains filtered or unexported fields
}

E2ETestSuite runs the Block SDK e2e test-suite against a given interchaintest specification

func NewE2ETestSuiteFromSpec

func NewE2ETestSuiteFromSpec(spec *interchaintest.ChainSpec) *E2ETestSuite

func (*E2ETestSuite) BroadcastTxs

func (s *E2ETestSuite) BroadcastTxs(ctx context.Context, chain *cosmos.CosmosChain, txs []Tx) [][]byte

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 (*E2ETestSuite) BroadcastTxsWithCallback

func (s *E2ETestSuite) BroadcastTxsWithCallback(
	ctx context.Context,
	chain *cosmos.CosmosChain,
	txs []Tx,
	cb func(tx []byte, resp *rpctypes.ResultTx),
) [][]byte

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. The callback function is called for each tx that is included in a block.

func (*E2ETestSuite) CreateAuctionBidMsg

func (s *E2ETestSuite) CreateAuctionBidMsg(ctx context.Context, searcher cosmos.User, chain *cosmos.CosmosChain, bid sdk.Coin, txsPerUser []Tx) (*auctiontypes.MsgAuctionBid, [][]byte)

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 (*E2ETestSuite) CreateDummyAuctionBidTx

func (s *E2ETestSuite) CreateDummyAuctionBidTx(
	height uint64,
	searcher ibc.Wallet,
	bid sdk.Coin,
) Tx

func (*E2ETestSuite) CreateDummyFreeTx

func (s *E2ETestSuite) CreateDummyFreeTx(
	user ibc.Wallet,
	validator sdk.ValAddress,
	delegation sdk.Coin,
	sequenceOffset uint64,
) Tx

func (*E2ETestSuite) CreateDummyNormalTx

func (s *E2ETestSuite) CreateDummyNormalTx(
	from, to ibc.Wallet,
	coins sdk.Coins,
	sequenceOffset uint64,
	gasPrice int64,
) Tx

func (*E2ETestSuite) CreateTx

func (s *E2ETestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, seqIncrement, height uint64, GasPrice int64, msgs ...sdk.Msg) []byte

CreateTx creates a new transaction to be signed by the given user, including a provided set of messages

func (*E2ETestSuite) SetupSubTest

func (s *E2ETestSuite) SetupSubTest()

func (*E2ETestSuite) SetupSuite

func (s *E2ETestSuite) SetupSuite()

func (*E2ETestSuite) SimulateTx

func (s *E2ETestSuite) SimulateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg)

SimulateTx simulates the provided messages, and checks whether the provided failure condition is met

func (*E2ETestSuite) TearDownSuite

func (s *E2ETestSuite) TearDownSuite()

func (*E2ETestSuite) TestFreeLane

func (s *E2ETestSuite) TestFreeLane()

TestFreeLane tests that the application correctly handles free lanes. There are a few invariants that are tested:

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 (*E2ETestSuite) TestInvalidBids

func (s *E2ETestSuite) TestInvalidBids()

func (*E2ETestSuite) TestLanes

func (s *E2ETestSuite) TestLanes()

func (*E2ETestSuite) TestMempoolService

func (s *E2ETestSuite) TestMempoolService()

func (*E2ETestSuite) TestMultipleBids

func (s *E2ETestSuite) TestMultipleBids()

TestMultipleBids tests the execution of various valid auction bids in the same block. There are a few invariants that are tested:

  1. The order of transactions in a bundle is preserved when bids are valid.
  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 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 (*E2ETestSuite) TestNetwork

func (s *E2ETestSuite) TestNetwork()

func (*E2ETestSuite) TestQueryParams

func (s *E2ETestSuite) TestQueryParams()

func (*E2ETestSuite) TestValidBids

func (s *E2ETestSuite) TestValidBids()

TestValidBids tests the execution of various valid auction bids. There are a few invariants that are tested:

  1. The order of transactions in a bundle is preserved when bids are valid.
  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 (*E2ETestSuite) WithDenom

func (s *E2ETestSuite) WithDenom(denom string) *E2ETestSuite

func (*E2ETestSuite) WithKeyringOptions

func (s *E2ETestSuite) WithKeyringOptions(cdc codec.Codec, opts keyring.Option)

type KeyringOverride

type KeyringOverride struct {
	// contains filtered or unexported fields
}

type Tx

type Tx struct {
	User               cosmos.User
	Msgs               []sdk.Msg
	GasPrice           int64
	SequenceIncrement  uint64
	Height             uint64
	SkipInclusionCheck bool
	ExpectFail         bool
	IgnoreChecks       bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL