testutil

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FundedAccountName = "whale"
	// use coin type 60 so we are compatible with accounts from `kava add keys --eth <name>`
	// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
	// to manage both sdk & evm txs.
	Bip44CoinType = 60

	IbcPort    = "transfer"
	IbcChannel = "channel-0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	StakingDenom string
	ChainID      string
	Keyring      keyring.Keyring

	EvmClient     *ethclient.Client
	ContractAddrs map[string]common.Address

	EncodingConfig kavaparams.EncodingConfig

	TmSignClient tmclient.SignClient

	Grpc *grpc.KavaGrpcClient
	// contains filtered or unexported fields
}

Chain wraps query clients & accounts for a network

func NewChain

func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic string) (*Chain, error)

NewChain creates the query clients & signing account management for a chain run on a set of ports. A signing client for the fundedAccountMnemonic is initialized. This account is referred to in the code as "whale" and it is used to supply funds to all new accounts.

func (*Chain) AddNewSigningAccount

func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, chainId, mnemonic string) *SigningAccount

AddNewSigningAccount sets up a new account with a signer for SDK and EVM transactions.

func (*Chain) AddNewSigningAccountFromPrivKey added in v0.25.0

func (chain *Chain) AddNewSigningAccountFromPrivKey(
	name string,
	privKey cryptotypes.PrivKey,
	mnemonic string,
	chainId string,
) *SigningAccount

AddNewSigningAccountFromPrivKey sets up a new account with a signer for SDK and EVM transactions, using the given private key.

func (*Chain) GetAccount

func (chain *Chain) GetAccount(name string) *SigningAccount

GetAccount returns the account with the given name or fails.

func (*Chain) GetBeginBlockEvents added in v0.25.0

func (chain *Chain) GetBeginBlockEvents(ctx context.Context, height int64) (sdk.StringEvents, error)

func (*Chain) GetBeginBlockEventsFromQuery added in v0.25.0

func (chain *Chain) GetBeginBlockEventsFromQuery(
	ctx context.Context,
	query string,
) (sdk.StringEvents, int64, error)

func (*Chain) GetErc20Balance added in v0.24.0

func (chain *Chain) GetErc20Balance(contract, address common.Address) *big.Int

GetErc20Balance fetches the ERC20 balance of `contract` for `address`.

func (*Chain) GetModuleBalances added in v0.24.0

func (chain *Chain) GetModuleBalances(moduleName string) sdk.Coins

GetModuleBalances returns the balance of a requested module account

func (*Chain) NewFundedAccount

func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccount

NewFundedAccount creates a SigningAccount for a random account & funds the account from the whale.

func (*Chain) QueryBlock added in v0.25.0

func (chain *Chain) QueryBlock(ctx context.Context, query string) ([]*coretypes.ResultBlock, error)

func (*Chain) QuerySdkForBalances

func (chain *Chain) QuerySdkForBalances(addr sdk.AccAddress) sdk.Coins

QuerySdkForBalances gets the balance of a particular address on this Chain.

func (*Chain) RegisterErc20 added in v0.25.0

func (chain *Chain) RegisterErc20(address common.Address)

RegisterErc20 is a method to record the address of erc20s on this chain. The full balances of each registered erc20 will be returned to the funded account when ReturnAllFunds is called.

func (*Chain) ReturnAllFunds added in v0.25.0

func (chain *Chain) ReturnAllFunds()

ReturnAllFunds loops through all SigningAccounts and sends all their funds back to the initially funded account.

func (*Chain) Shutdown

func (chain *Chain) Shutdown()

Shutdown performs closes all the account request channels for this chain.

type DeployedErc20 added in v0.25.0

type DeployedErc20 struct {
	Address     common.Address
	CosmosDenom string

	CdpCollateralType string
}

DeployedErc20 is a type that wraps the details of the pre-deployed erc20 used by the e2e test suite. The Address comes from SuiteConfig.KavaErc20Address The CosmosDenom is fetched from the EnabledConversionPairs param of x/evmutil. The tests expect the following: - the funded account has a nonzero balance of the erc20 - the erc20 is enabled for conversion to sdk.Coin - the corresponding sdk.Coin is enabled as a cdp collateral type These requirements are checked in InitKavaEvmData().

type E2eTestSuite

type E2eTestSuite struct {
	suite.Suite

	Kava *Chain
	Ibc  *Chain

	UpgradeHeight int64
	DeployedErc20 DeployedErc20
	// contains filtered or unexported fields
}

E2eTestSuite is a testify test suite for running end-to-end integration tests on Kava.

func (*E2eTestSuite) BigIntsEqual

func (suite *E2eTestSuite) BigIntsEqual(expected *big.Int, actual *big.Int, msg string)

BigIntsEqual is a helper method for comparing the equality of two big ints

func (*E2eTestSuite) FundKavaErc20Balance

func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse

FundKavaErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.

func (*E2eTestSuite) InitKavaEvmData

func (suite *E2eTestSuite) InitKavaEvmData()

InitKavaEvmData is run after the chain is running, but before the tests are run. It is used to initialize some EVM state, such as deploying contracts.

func (*E2eTestSuite) NewEip712TxBuilder

func (suite *E2eTestSuite) NewEip712TxBuilder(
	acc *SigningAccount, chain *Chain, gas uint64, gasAmount sdk.Coins, msgs []sdk.Msg, memo string,
) client.TxBuilder

NewEip712TxBuilder is a helper method for creating an EIP712 signed tx A tx like this is what a user signing cosmos messages with Metamask would broadcast.

func (*E2eTestSuite) SetupKvtoolNodeRunner added in v0.25.0

func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner

SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.

func (*E2eTestSuite) SetupLiveNetworkNodeRunner added in v0.25.0

func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner

SetupLiveNetworkNodeRunner is a helper method for building a LiveNodeRunner from the suite config.

func (*E2eTestSuite) SetupSuite

func (suite *E2eTestSuite) SetupSuite()

SetupSuite is run before all tests. It initializes chain connections and sets up the account used for funding accounts in the tests.

func (*E2eTestSuite) SkipIfIbcDisabled

func (suite *E2eTestSuite) SkipIfIbcDisabled()

SkipIfIbcDisabled should be called at the start of tests that require IBC. It gracefully skips the current test if IBC tests are disabled.

func (*E2eTestSuite) SkipIfKvtoolDisabled added in v0.25.0

func (suite *E2eTestSuite) SkipIfKvtoolDisabled()

SkipIfKvtoolDisabled should be called at the start of tests that require kvtool.

func (*E2eTestSuite) SkipIfUpgradeDisabled

func (suite *E2eTestSuite) SkipIfUpgradeDisabled()

SkipIfUpgradeDisabled should be called at the start of tests that require automated upgrades. It gracefully skips the current test if upgrades are dissabled. Note: automated upgrade tests are currently only enabled for Kvtool suite runs.

func (*E2eTestSuite) TearDownSuite

func (suite *E2eTestSuite) TearDownSuite()

TearDownSuite is run after all tests have run. In the event of a panic during the tests, it is run after testify recovers.

type EvmTxResponse

type EvmTxResponse struct {
	util.EvmTxResponse
	Receipt *ethtypes.Receipt
}

EvmTxResponse is util.EvmTxResponse that also includes the Receipt, if available

type KvtoolConfig added in v0.25.0

type KvtoolConfig struct {
	// The kava.configTemplate flag to be passed to kvtool, usually "master".
	// This allows one to change the base genesis used to start the chain.
	KavaConfigTemplate string

	// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
	IncludeAutomatedUpgrade bool
	// Name of the upgrade, if upgrade is enabled.
	KavaUpgradeName string
	// Height upgrade will be applied to the test chain, if upgrade is enabled.
	KavaUpgradeHeight int64
	// Tag of kava docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
	KavaUpgradeBaseImageTag string
}

KvtoolConfig wraps configuration options for running the end-to-end test suite against a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.

func ParseKvtoolConfig added in v0.25.0

func ParseKvtoolConfig() KvtoolConfig

ParseKvtoolConfig builds a KvtoolConfig from environment variables.

type LiveNetworkConfig added in v0.25.0

type LiveNetworkConfig struct {
	KavaRpcUrl    string
	KavaGrpcUrl   string
	KavaEvmRpcUrl string

	UpgradeHeight int64
}

LiveNetworkConfig wraps configuration options for running the end-to-end test suite against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.

func ParseLiveNetworkConfig added in v0.25.0

func ParseLiveNetworkConfig() LiveNetworkConfig

ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.

type SigningAccount

type SigningAccount struct {
	EvmAuth *bind.TransactOpts

	EvmAddress common.Address
	SdkAddress sdk.AccAddress
	// contains filtered or unexported fields
}

SigningAccount wraps details about an account and its private keys. It exposes functionality for signing and broadcasting transactions.

func (*SigningAccount) BankSend added in v0.25.0

func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.KavaMsgResponse

BankSend is a helper method for sending funds via x/bank's MsgSend

func (*SigningAccount) NextNonce added in v0.24.0

func (a *SigningAccount) NextNonce() (uint64, error)

GetNonce fetches the next nonce / sequence number for the account.

func (*SigningAccount) SignAndBroadcastEvmTx

func (a *SigningAccount) SignAndBroadcastEvmTx(req util.EvmTxRequest) EvmTxResponse

SignAndBroadcastEvmTx sends a request to the signer and awaits its response.

func (*SigningAccount) SignAndBroadcastKavaTx

func (a *SigningAccount) SignAndBroadcastKavaTx(req util.KavaMsgRequest) util.KavaMsgResponse

SignAndBroadcastKavaTx sends a request to the signer and awaits its response.

func (*SigningAccount) SignRawEvmData

func (a *SigningAccount) SignRawEvmData(msg []byte) ([]byte, types.PubKey, error)

SignRawEvmData signs raw evm data with the SigningAccount's private key. It does not broadcast the signed data.

func (*SigningAccount) TransferErc20 added in v0.25.0

func (a *SigningAccount) TransferErc20(contract, to common.Address, amount *big.Int) (EvmTxResponse, error)

TransferErc20 is a helper method for sending an erc20 token

type SuiteConfig

type SuiteConfig struct {
	// A funded account used to fnd all other accounts.
	FundedAccountMnemonic string

	// A config for using kvtool local networks for the test run
	Kvtool *KvtoolConfig
	// A config for connecting to a running network
	LiveNetwork *LiveNetworkConfig

	// Whether or not to start an IBC chain. Use `suite.SkipIfIbcDisabled()` in IBC tests in IBC tests.
	IncludeIbcTests bool

	// The contract address of a deployed ERC-20 token
	KavaErc20Address string

	// When true, the chains will remain running after tests complete (pass or fail)
	SkipShutdown bool
}

SuiteConfig wraps configuration details for running the end-to-end test suite.

func ParseSuiteConfig

func ParseSuiteConfig() SuiteConfig

ParseSuiteConfig builds a SuiteConfig from environment variables.

Jump to

Keyboard shortcuts

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