Documentation ¶
Overview ¶
Package mock provides functions for creating applications for testing.
This module also features randomized testing, so that various modules can test that their operations are interoperable.
The intended method of using this randomized testing framework is that every module provides TestAndRunTx methods for each of its desired methods of fuzzing its own txs, and it also provides the invariants that it assumes to be true. You then pick and choose from these tx types and invariants. To pick and choose these, you first build a mock app with the correct keepers. Then you call the app.RandomizedTesting method with the set of desired txs, invariants, along with the setups each module requires.
Index ¶
- func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins)
- func CheckGenTx(t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64, ...) sdk.Result
- func CreateGenAccounts(numAccs int, genCoins sdk.Coins) (genAccs []auth.Account, addrs []sdk.AccAddress, pubKeys []crypto.PubKey, ...)
- func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, initSeqNums []int64, numToGenerate int, ...) []auth.StdTx
- func GenTx(msgs []sdk.Msg, accnums []int64, seq []int64, priv ...crypto.PrivKey) auth.StdTx
- func GeneratePrivKeyAddressPairs(n int) (keys []crypto.PrivKey, addrs []sdk.AccAddress)
- func GeneratePrivKeys(n int) (keys []crypto.PrivKey)
- func GetAllAccounts(mapper auth.AccountMapper, ctx sdk.Context) []auth.Account
- func RandFromBigInterval(r *rand.Rand, intervals []BigInterval) sdk.Int
- func RandomSetGenesis(r *rand.Rand, app *App, addrs []sdk.AccAddress, denoms []string)
- func SetGenesis(app *App, accs []auth.Account)
- func SignCheckDeliver(t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64, ...) sdk.Result
- type App
- func (app *App) CompleteSetup(newKeys []*sdk.KVStoreKey) error
- func (app *App) InitChainer(ctx sdk.Context, _ abci.RequestInitChain) abci.ResponseInitChain
- func (app *App) RandomizedTesting(t *testing.T, ops []TestAndRunTx, setups []RandSetup, invariants []Invariant, ...)
- func (app *App) RandomizedTestingFromSeed(t *testing.T, seed int64, ops []TestAndRunTx, setups []RandSetup, ...)
- type BigInterval
- type Invariant
- type RandSetup
- type TestAndRunTx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckBalance ¶
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 []auth.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 GeneratePrivKeyAddressPairs ¶
func GeneratePrivKeyAddressPairs(n int) (keys []crypto.PrivKey, addrs []sdk.AccAddress)
GeneratePrivKeyAddressPairs generates a total of n private key, address pairs.
func GeneratePrivKeys ¶
GeneratePrivKeys generates a total n Ed25519 private keys.
func GetAllAccounts ¶
GetAllAccounts returns all accounts in the accountMapper.
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 ¶
RandomSetGenesis set genesis accounts with random coin values using the provided addresses and coin denominations.
func SetGenesis ¶
SetGenesis sets the mock app genesis accounts.
func SignCheckDeliver ¶
func SignCheckDeliver( t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64, seq []int64, 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 *wire.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 AccountMapper auth.AccountMapper FeeCollectionKeeper auth.FeeCollectionKeeper GenesisAccounts []auth.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.KVStoreKey) 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.
func (*App) RandomizedTesting ¶
func (app *App) RandomizedTesting( t *testing.T, ops []TestAndRunTx, setups []RandSetup, invariants []Invariant, numKeys int, numBlocks int, blockSize int, )
RandomizedTesting tests application by sending random messages.
func (*App) RandomizedTestingFromSeed ¶
func (app *App) RandomizedTestingFromSeed( t *testing.T, seed int64, ops []TestAndRunTx, setups []RandSetup, invariants []Invariant, numKeys int, numBlocks int, blockSize int, )
RandomizedTestingFromSeed tests an application by running the provided operations, testing the provided invariants, but using the provided seed.
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 Invariant ¶
An Invariant is a function which tests a particular invariant. If the invariant has been broken, the function should halt the test and output the log.
type TestAndRunTx ¶
type TestAndRunTx func( t *testing.T, r *rand.Rand, app *App, ctx sdk.Context, privKeys []crypto.PrivKey, log string, ) (action string, err sdk.Error)
TestAndRunTx produces a fuzzed transaction, and ensures the state transition was as expected. It returns a descriptive message "action" about what this fuzzed tx actually did, for ease of debugging.