testutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastTxBytes

func BroadcastTxBytes(app *app.BounceBit, txEncoder sdk.TxEncoder, tx sdk.Tx) (abci.ResponseDeliverTx, error)

BroadcastTxBytes encodes a transaction and calls DeliverTx on the app.

func CheckEthTx

func CheckEthTx(
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	msgs ...sdk.Msg,
) (abci.ResponseCheckTx, error)

CheckEthTx checks a Ethereum tx for a given set of msgs

func CheckEthTxResponse

func CheckEthTxResponse(r abci.ResponseDeliverTx, cdc codec.Codec) ([]*evm.MsgEthereumTxResponse, error)

CheckEthTxResponse checks that the transaction was executed successfully

func CheckTx

func CheckTx(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	gasPrice *sdkmath.Int,
	msgs ...sdk.Msg,
) (abci.ResponseCheckTx, error)

CheckTx checks a cosmos tx for a given set of msgs

func Commit

func Commit(ctx sdk.Context, app *app.BounceBit, t time.Duration, vs *tmtypes.ValidatorSet) (sdk.Context, error)

Commit commits a block at a given time. Reminder: At the end of each Tendermint Consensus round the following methods are run

  1. BeginBlock
  2. DeliverTx
  3. EndBlock
  4. Commit

func CommitAndCreateNewCtx

func CommitAndCreateNewCtx(ctx sdk.Context, app *app.BounceBit, t time.Duration, vs *tmtypes.ValidatorSet) (sdk.Context, error)

CommitAndCreateNewCtx commits a block at a given time creating a ctx with the current settings This is useful to keep test settings that could be affected by EndBlockers, e.g. setting a baseFee == 0 and expecting this condition to continue after commit

func CreateValidator

func CreateValidator(ctx sdk.Context, t *testing.T, pubKey cryptotypes.PubKey, sk stakingkeeper.Keeper, stakeAmt math.Int)

CreateValidator creates a validator with the provided public key and stake amount

func Delegate

func Delegate(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv *ethsecp256k1.PrivKey,
	delegateAmount sdk.Coin,
	validator stakingtypes.Validator,
) (abci.ResponseDeliverTx, error)

Delegate delivers a delegate tx

func DeliverEthTx

func DeliverEthTx(
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	msgs ...sdk.Msg,
) (abci.ResponseDeliverTx, error)

DeliverEthTx generates and broadcasts a Cosmos Tx populated with MsgEthereumTx messages. If a private key is provided, it will attempt to sign all messages with the given private key, otherwise, it will assume the messages have already been signed.

func DeliverEthTxWithoutCheck

func DeliverEthTxWithoutCheck(
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	msgs ...sdk.Msg,
) (abci.ResponseDeliverTx, error)

DeliverEthTxWithoutCheck generates and broadcasts a Cosmos Tx populated with MsgEthereumTx messages. If a private key is provided, it will attempt to sign all messages with the given private key, otherwise, it will assume the messages have already been signed. It does not check if the Eth tx is successful or not.

func DeliverTx

func DeliverTx(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	gasPrice *sdkmath.Int,
	msgs ...sdk.Msg,
) (abci.ResponseDeliverTx, error)

DeliverTx delivers a cosmos tx for a given set of msgs

func DeployContract

func DeployContract(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	queryClientEvm evm.QueryClient,
	contract evm.CompiledContract,
	constructorArgs ...interface{},
) (common.Address, error)

DeployContract deploys a contract with the provided private key, compiled contract data and constructor arguments

func DeployContractWithFactory

func DeployContractWithFactory(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv cryptotypes.PrivKey,
	factoryAddress common.Address,
) (common.Address, abci.ResponseDeliverTx, error)

DeployContractWithFactory deploys a contract using a contract factory with the provided factoryAddress

func FundAccount

func FundAccount(ctx sdk.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amounts sdk.Coins) error

FundAccount is a utility function that funds an account by minting and sending the coins to the address.

func FundAccountWithBaseDenom

func FundAccountWithBaseDenom(ctx sdk.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amount int64) error

FundAccountWithBaseDenom is a utility function that uses the FundAccount function

func FundModuleAccount

func FundModuleAccount(ctx sdk.Context, bankKeeper bankkeeper.Keeper, recipientMod string, amounts sdk.Coins) error

FundModuleAccount is a utility function that funds a module account by minting and sending the coins to the address.

func GetTotalDelegationRewards

func GetTotalDelegationRewards(ctx sdk.Context, distributionKeeper distributionkeeper.Keeper, addr sdk.AccAddress) (sdk.DecCoins, error)

GetTotalDelegationRewards returns the total delegation rewards that are currently outstanding for the given address.

func NewHeader

func NewHeader(
	height int64,
	blockTime time.Time,
	chainID string,
	proposer sdk.ConsAddress,
	appHash,
	validatorHash []byte,
) tmproto.Header

NewHeader creates a new Tendermint header for testing purposes.

func NextFn

func NextFn(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error)

NextFn is a no-op function that returns the context and no error in order to mock the next function in the AnteHandler chain.

It can be used in unit tests when calling a decorator's AnteHandle method, e.g. `dec.AnteHandle(ctx, tx, false, NextFn)`

func PrepareAccountsForDelegationRewards

func PrepareAccountsForDelegationRewards(t *testing.T, ctx sdk.Context, app *app.BounceBit, addr sdk.AccAddress, balance math.Int, rewards ...math.Int) (sdk.Context, error)

PrepareAccountsForDelegationRewards prepares the test suite for testing to withdraw delegation rewards.

Balance is the amount of tokens that will be left in the account after the setup is done. For each defined reward, a validator is created and tokens are allocated to it using the distribution keeper, such that the given amount of tokens is outstanding as a staking reward for the account.

The setup is done in the following way:

  • Fund the account with the given address with the given balance.
  • If the given balance is zero, the account will be created with zero balance.

For every reward defined in the rewards argument, the following steps are executed:

  • Set up a validator with zero commission and delegate to it -> the account delegation will be 50% of the total delegation.
  • Allocate rewards to the validator.

The function returns the updated context along with a potential error.

func SubmitProposal

func SubmitProposal(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	pk *ethsecp256k1.PrivKey,
	content govv1beta1.Content,
	eventNum int,
) (id uint64, err error)

SubmitProposal delivers a submit proposal tx for a given gov content. Depending on the content type, the eventNum needs to specify submit_proposal event.

func ValidateAnteForMsgs

func ValidateAnteForMsgs(ctx sdk.Context, dec sdk.AnteDecorator, msgs ...sdk.Msg) error

ValidateAnteForMsgs is a helper function, which takes in an AnteDecorator as well as 1 or more messages, builds a transaction containing these messages, and returns any error that the AnteHandler might return.

func Vote

func Vote(
	ctx sdk.Context,
	bbApp *app.BounceBit,
	priv *ethsecp256k1.PrivKey,
	proposalID uint64,
	voteOption govv1beta1.VoteOption,
) (abci.ResponseDeliverTx, error)

Vote delivers a vote tx with the VoteOption "yes"

Types

type ContractArgs

type ContractArgs struct {
	// Addr is the address of the contract to call.
	Addr common.Address
	// ABI is the ABI of the contract to call.
	ABI abi.ABI
	// MethodName is the name of the method to call.
	MethodName string
	// Args are the arguments to pass to the method.
	Args []interface{}
}

ContractArgs are the params used for calling a smart contract.

type ContractCallArgs

type ContractCallArgs struct {
	// Contract are the contract-specific arguments required for the contract call.
	Contract ContractArgs
	// Nonce is the nonce to use for the transaction.
	Nonce *big.Int
	// Amount is the bit amount to send in the transaction.
	Amount *big.Int
	// GasLimit to use for the transaction
	GasLimit uint64
	// PrivKey is the private key to be used for the transaction.
	PrivKey cryptotypes.PrivKey
}

ContractCallArgs is the arguments for calling a smart contract.

type IntegrationKeyring

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

IntegrationKeyring is a keyring designed for integration tests.

func (*IntegrationKeyring) AddKey

func (kr *IntegrationKeyring) AddKey() int

AddKey adds a new account to the keyring. It returns the index for the key

func (*IntegrationKeyring) GetAccAddr

func (kr *IntegrationKeyring) GetAccAddr(index int) sdktypes.AccAddress

GetAccAddr returns the sdk address of the specified account.

func (*IntegrationKeyring) GetAddr

func (kr *IntegrationKeyring) GetAddr(index int) common.Address

GetAddr returns the address of the specified account.

func (*IntegrationKeyring) GetAllAccAddrs

func (kr *IntegrationKeyring) GetAllAccAddrs() []sdktypes.AccAddress

GetAllAccAddrs returns all the sdk addresses of the accounts in the keyring.

func (*IntegrationKeyring) GetKey

func (kr *IntegrationKeyring) GetKey(index int) Key

GetKey returns the key specified by index

func (*IntegrationKeyring) GetPrivKey

func (kr *IntegrationKeyring) GetPrivKey(index int) cryptotypes.PrivKey

GetPrivKey returns the private key of the specified account.

func (*IntegrationKeyring) Sign

func (kr *IntegrationKeyring) Sign(index int, msg []byte) ([]byte, error)

Sign signs message with the specified key.

type Key

type Key struct {
	Addr    common.Address
	AccAddr sdktypes.AccAddress
	Priv    cryptotypes.PrivKey
}

func NewKey

func NewKey() Key

type Keyring

type Keyring interface {
	// GetPrivKey returns the private key of the account at the given keyring index.
	GetPrivKey(index int) cryptotypes.PrivKey
	// GetAddr returns the address of the account at the given keyring index.
	GetAddr(index int) common.Address
	// GetAccAddr returns the SDK address of the account at the given keyring index.
	GetAccAddr(index int) sdktypes.AccAddress
	// GetAllAccAddrs returns all the SDK addresses of the accounts in the keyring.
	GetAllAccAddrs() []sdktypes.AccAddress
	// GetKey returns the key at the given keyring index
	GetKey(index int) Key

	// AddKey adds a new account to the keyring
	AddKey() int

	// Sign signs message with the specified account.
	Sign(index int, msg []byte) ([]byte, error)
}

func NewKeyring

func NewKeyring(nAccs int) Keyring

New returns a new keyring with nAccs accounts.

Directories

Path Synopsis
Package network implements and exposes a fully operational in-process Tendermint test network that consists of at least one or potentially many validators.
Package network implements and exposes a fully operational in-process Tendermint test network that consists of at least one or potentially many validators.

Jump to

Keyboard shortcuts

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