testutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FundedAccountName = "whale"
	// use coin type 60 so we are compatible with accounts from `nemo 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

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

	EncodingConfig nemoparams.EncodingConfig

	Auth      authtypes.QueryClient
	Bank      banktypes.QueryClient
	Committee committeetypes.QueryClient
	Community communitytypes.QueryClient
	Earn      earntypes.QueryClient
	Evm       evmtypes.QueryClient
	Evmutil   evmutiltypes.QueryClient
	Tm        tmservice.ServiceClient
	Tx        txtypes.ServiceClient
	Upgrade   upgradetypes.QueryClient
	// 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) GetAccount

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

GetAccount returns the account with the given name or fails.

func (*Chain) GetErc20Balance

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

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

func (*Chain) GetModuleBalances

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) QuerySdkForBalances

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

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

func (*Chain) RegisterErc20

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

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

type DeployedErc20 struct {
	Address     common.Address
	CosmosDenom 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.NemoErc20Address 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 an earn vault denom These requirements are checked in InitNemoEvmData().

type E2eTestSuite

type E2eTestSuite struct {
	suite.Suite

	Nemo *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 Nemo.

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) FundNemoErc20Balance

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

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

func (*E2eTestSuite) InitNemoEvmData

func (suite *E2eTestSuite) InitNemoEvmData()

InitNemoEvmData 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) NemoHomePath

func (suite *E2eTestSuite) NemoHomePath() string

NemoHomePath returns the OS-specific filepath for the nemo home directory Assumes network is running with nmtool installed from the sub-repository in tests/e2e/nmtool

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) SetupLiveNetworkNodeRunner

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

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

func (*E2eTestSuite) SetupNmtoolNodeRunner

func (suite *E2eTestSuite) SetupNmtoolNodeRunner() *runner.NmtoolRunner

SetupNmtoolNodeRunner is a helper method for building a NmtoolRunnerConfig 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) 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 Nmtool 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 LiveNetworkConfig

type LiveNetworkConfig struct {
	NemoRpcUrl    string
	NemoGrpcUrl   string
	NemoEvmRpcUrl string
}

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

func ParseLiveNetworkConfig

func ParseLiveNetworkConfig() LiveNetworkConfig

ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.

type NmtoolConfig

type NmtoolConfig struct {
	// The nemo.configTemplate flag to be passed to nmtool, usually "master".
	// This allows one to change the base genesis used to start the chain.
	NemoConfigTemplate 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.
	NemoUpgradeName string
	// Height upgrade will be applied to the test chain, if upgrade is enabled.
	NemoUpgradeHeight int64
	// Tag of nemo docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
	NemoUpgradeBaseImageTag string
}

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

func ParseNmtoolConfig

func ParseNmtoolConfig() NmtoolConfig

ParseNmtoolConfig builds a NmtoolConfig 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

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

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

func (*SigningAccount) NextNonce

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) SignAndBroadcastNemoTx

func (a *SigningAccount) SignAndBroadcastNemoTx(req util.NemoMsgRequest) util.NemoMsgResponse

SignAndBroadcastNemoTx 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

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 nmtool local networks for the test run
	Nmtool *NmtoolConfig
	// 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
	NemoErc20Address 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