mock

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MPL-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package mock provides utility methods to ease writing tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBlock

func ApplyBlock(t *testing.T, app *baseapp.BaseApp, height int64, txs []auth.StdTx) (newHeight int64)

func ApplyEmptyBlocks

func ApplyEmptyBlocks(t *testing.T, app *baseapp.BaseApp, height int64, blockNum int) (newHeight int64)

func CheckBalance

func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins)

CheckBalance checks the balance of an account.

func CheckGenTx

func CheckGenTx(
	t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64,
	seq []int64, expPass bool, priv ...crypto.PrivKey,
) sdk.Result

CheckGenTx checks a generated signed transaction. The result of the check is compared against the parameter 'expPass'. A test assertion is made using the parameter 'expPass' against the result. A corresponding result is returned.

func CreateGenAccounts

func CreateGenAccounts(numAccs int, genCoins sdk.Coins) (genAccs []sdk.Account, addrs []sdk.AccAddress, pubKeys []crypto.PubKey, privKeys []crypto.PrivKey)

CreateGenAccounts generates genesis accounts loaded with coins, and returns their addresses, pubkeys, and privkeys.

func GenSequenceOfTxs

func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, initSeqNums []int64, numToGenerate int, priv ...crypto.PrivKey) []auth.StdTx

GenSequenceOfTxs generates a set of signed transactions of messages, such that they differ only by having the sequence numbers incremented between every transaction.

func GenSimTxs

func GenSimTxs(
	t *testing.T, app *App, msgs []sdk.Msg, expSimPass bool, privs ...crypto.PrivKey,
) (txs []auth.StdTx)

func GenTx

func GenTx(msgs []sdk.Msg, accnums []int64, seq []int64, priv ...crypto.PrivKey) auth.StdTx

GenTx generates a signed mock transaction.

func GeneratePrivKeyAddressPairs

func GeneratePrivKeyAddressPairs(n int) (keys []crypto.PrivKey, addrs []sdk.AccAddress)

GeneratePrivKeyAddressPairs generates a total of n private key, address pairs.

func GeneratePrivKeyAddressPairsFromRand

func GeneratePrivKeyAddressPairsFromRand(rand *rand.Rand, n int) (keys []crypto.PrivKey, addrs []sdk.AccAddress)

GeneratePrivKeyAddressPairsFromRand generates a total of n private key, address pairs using the provided randomness source.

func GeneratePrivKeys

func GeneratePrivKeys(n int) (keys []crypto.PrivKey)

GeneratePrivKeys generates a total n Ed25519 private keys.

func GetAccount

func GetAccount(app *App, addr sdk.AccAddress) sdk.Account

func GetAllAccounts

func GetAllAccounts(mapper auth.AccountKeeper, ctx sdk.Context) []sdk.Account

GetAllAccounts returns all accounts in the accountKeeper.

func RandFromBigInterval

func RandFromBigInterval(r *rand.Rand, intervals []BigInterval) sdk.Int

RandFromBigInterval chooses an interval uniformly from the provided list of BigIntervals, and then chooses an element from an interval uniformly at random.

func RandomSetGenesis

func RandomSetGenesis(r *rand.Rand, app *App, addrs []sdk.AccAddress, denoms []string)

RandomSetGenesis set genesis accounts with random coin values using the provided addresses and coin denominations. nolint: errcheck

func SetGenesis

func SetGenesis(app *App, accs []sdk.Account)

SetGenesis sets the mock app genesis accounts.

func SignCheckDeliver

func SignCheckDeliver(
	t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64,
	seq []int64, expSimPass, expPass bool, priv ...crypto.PrivKey,
) sdk.Result

SignCheckDeliver checks a generated signed transaction and simulates a block commitment with the given transaction. A test assertion is made using the parameter 'expPass' against the result. A corresponding result is returned.

Types

type App

type App struct {
	*bam.BaseApp
	Cdc        *codec.Codec // Cdc is public since the codec is passed into the module anyways
	KeyMain    *sdk.KVStoreKey
	KeyAccount *sdk.KVStoreKey

	// TODO: Abstract this out from not needing to be auth specifically
	AccountKeeper auth.AccountKeeper

	GenesisAccounts  []sdk.Account
	TotalCoinsSupply sdk.Coins
}

App extends an ABCI application, but with most of its parameters exported. They are exported for convenience in creating helper functions, as object capabilities aren't needed for testing.

func NewApp

func NewApp() *App

NewApp partially constructs a new app on the memstore for module and genesis testing.

func (*App) CompleteSetup

func (app *App) CompleteSetup(newKeys ...sdk.StoreKey) error

CompleteSetup completes the application setup after the routes have been registered.

func (*App) InitChainer

func (app *App) InitChainer(ctx sdk.Context, _ abci.RequestInitChain) abci.ResponseInitChain

InitChainer performs custom logic for initialization. nolint: errcheck

type BigInterval

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

BigInterval is a representation of the interval [lo, hi), where lo and hi are both of type sdk.Int

Directories

Path Synopsis
Package simulation implements a simulation framework for any state machine built on the SDK which utilizes auth.
Package simulation implements a simulation framework for any state machine built on the SDK which utilizes auth.

Jump to

Keyboard shortcuts

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