mock

package
v0.0.0-...-f498596 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0, Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package mock provides utility methods to ease writing tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 []uint64,
	seq []uint64, expPass bool, priv ...crypto.PrivKey,
) (sdk.GasInfo, *sdk.Result, error)

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 []authexported.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 GenTx

func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, 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 secp256k1 private keys.

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.

func SetGenesis

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

SetGenesis sets the mock app genesis accounts.

func SignCheckDeliver

func SignCheckDeliver(
	t *testing.T, cdc *codec.Codec, app *baseapp.BaseApp, header abci.Header, msgs []sdk.Msg,
	accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey,
) (sdk.GasInfo, *sdk.Result, error)

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 AddrKeys

type AddrKeys struct {
	Address sdk.AccAddress
	PubKey  crypto.PubKey
	PrivKey crypto.PrivKey
}

Type that combines an Address with the privKey and pubKey to that address

func NewAddrKeys

func NewAddrKeys(address sdk.AccAddress, pubKey crypto.PubKey,
	privKey crypto.PrivKey) AddrKeys

type AddrKeysSlice

type AddrKeysSlice []AddrKeys

implement `Interface` in sort package.

func (AddrKeysSlice) Len

func (b AddrKeysSlice) Len() int

func (AddrKeysSlice) Less

func (b AddrKeysSlice) Less(i, j int) bool

Sorts lexographically by Address

func (AddrKeysSlice) Swap

func (b AddrKeysSlice) Swap(i, j int)

type App

type App struct {
	*bam.BaseApp
	Cdc        *codec.CodecProxy // Cdc is public since the codec is passed into the module anyways
	KeyMain    *sdk.KVStoreKey
	KeyAccount *sdk.KVStoreKey
	KeyAccMpt  *sdk.KVStoreKey
	KeyParams  *sdk.KVStoreKey
	TKeyParams *sdk.TransientStoreKey

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

	GenesisAccounts  []authexported.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.

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

type DummySupplyKeeper

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

DummySupplyKeeper defines a supply keeper used only for testing to avoid circle dependencies

func NewDummySupplyKeeper

func NewDummySupplyKeeper(ak auth.AccountKeeper) DummySupplyKeeper

NewDummySupplyKeeper creates a DummySupplyKeeper instance

func (DummySupplyKeeper) GetModuleAccount

func (sk DummySupplyKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI

GetModuleAccount for dummy supply keeper

func (DummySupplyKeeper) GetModuleAddress

func (sk DummySupplyKeeper) GetModuleAddress(moduleName string) sdk.AccAddress

GetModuleAddress for dummy supply keeper

func (DummySupplyKeeper) SendCoinsFromAccountToModule

func (sk DummySupplyKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, fromAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

SendCoinsFromAccountToModule for the dummy supply keeper

func (DummySupplyKeeper) SendCoinsFromModuleToAccount

func (sk DummySupplyKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error

Jump to

Keyboard shortcuts

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