testutil

package
v0.1.4-2023090122-mfury.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

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

	Auth      authtypes.QueryClient
	Bank      banktypes.QueryClient
	Cdp       cdptypes.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

	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.FuryErc20Address 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 InitFuryEvmData().

type E2eTestSuite

type E2eTestSuite struct {
	suite.Suite

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

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

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

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

func (*E2eTestSuite) FuryHomePath

func (suite *E2eTestSuite) FuryHomePath() string

FuryHomePath returns the OS-specific filepath for the fury home directory Assumes network is running with futool installed from the sub-repository in tests/e2e/futool

func (*E2eTestSuite) InitFuryEvmData

func (suite *E2eTestSuite) InitFuryEvmData()

InitFuryEvmData 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) SetupFutoolNodeRunner

func (suite *E2eTestSuite) SetupFutoolNodeRunner() *runner.FutoolRunner

SetupFutoolNodeRunner is a helper method for building a FutoolRunnerConfig from the suite config.

func (*E2eTestSuite) SetupLiveNetworkNodeRunner

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) 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 Futool 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 FutoolConfig

type FutoolConfig struct {
	// The fury.configTemplate flag to be passed to futool, usually "master".
	// This allows one to change the base genesis used to start the chain.
	FuryConfigTemplate 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.
	FuryUpgradeName string
	// Height upgrade will be applied to the test chain, if upgrade is enabled.
	FuryUpgradeHeight int64
	// Tag of fury docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
	FuryUpgradeBaseImageTag string
}

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

func ParseFutoolConfig

func ParseFutoolConfig() FutoolConfig

ParseFutoolConfig builds a FutoolConfig from environment variables.

type LiveNetworkConfig

type LiveNetworkConfig struct {
	FuryRpcUrl    string
	FuryGrpcUrl   string
	FuryEvmRpcUrl string
}

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

func ParseLiveNetworkConfig

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

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

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

func (a *SigningAccount) SignAndBroadcastFuryTx(req util.FuryMsgRequest) util.FuryMsgResponse

SignAndBroadcastFuryTx 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 futool local networks for the test run
	Futool *FutoolConfig
	// 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
	FuryErc20Address 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