Documentation
¶
Index ¶
- func Cleanup(n *testnet.Network, t *testing.T)
- func DefaultTestNetworkConfig() testnet.Config
- func GenerateTestingAccounts(t *testing.T, ctx sdk.Context, app *app.App, r *rand.Rand, n int) []simtypes.Account
- func GenerateTestingAccountsWithPower(t *testing.T, ctx sdk.Context, app *app.App, r *rand.Rand, n int, power int64) []simtypes.Account
- func GetKeyringEntryAddresses(entries []TestKeyringEntry) []sdk.AccAddress
- func LatestHeight(n *testnet.Network) (int64, error)
- func LogOperationMsg(t *testing.T, operationMsg simtypes.OperationMsg, msg string, ...)
- func MutateGenesisState[G proto.Message](t *testing.T, cfg *testnet.Config, moduleName string, emptyState G, ...)
- func NewAppConstructor() testnet.AppConstructor
- func NewTestKeyring(t *testing.T, codec codec.Codec) keyring.Keyring
- func RunGetSignersTests[R []M, M sdk.Msg](t *testing.T, allRequestMsgs R, msgMakers []MsgMaker, ...)
- func WaitForHeight(n *testnet.Network, h int64) (int64, error)
- func WaitForHeightWithTimeout(n *testnet.Network, h int64, t time.Duration) (int64, error)
- func WaitForNBlocks(n *testnet.Network, count int) error
- func WaitForNextBlock(n *testnet.Network) error
- type ExpectedOp
- type ExpectedProposalMsg
- type ExpectedWeightedOp
- type MsgMaker
- type MsgMakerMulti
- type SimTestHelper
- func (a SimTestHelper) AssertMsgSimulatorFn(expected sdk.Msg, simFnMaker func() simtypes.MsgSimulatorFn) (sdk.Msg, bool)
- func (a SimTestHelper) AssertProposalMsgs(expected []ExpectedProposalMsg, ...) bool
- func (a SimTestHelper) AssertSimOp(expected ExpectedOp, opMaker func() simtypes.Operation, opDesc string) (sdk.Msg, []simtypes.FutureOperation, bool)
- func (a SimTestHelper) AssertWeightedOperations(expected []ExpectedWeightedOp, wOpsFn func() simulation.WeightedOperations) bool
- func (a SimTestHelper) WithAccs(accs []simtypes.Account) *SimTestHelper
- func (a SimTestHelper) WithApp(app *app.App) *SimTestHelper
- func (a SimTestHelper) WithCtx(ctx sdk.Context) *SimTestHelper
- func (a SimTestHelper) WithR(r *rand.Rand) *SimTestHelper
- func (a SimTestHelper) WithT(t *testing.T) *SimTestHelper
- func (a SimTestHelper) WithTestingAccounts(n int) *SimTestHelper
- func (a SimTestHelper) WithTestingAccountsWithPower(n int, power int64) *SimTestHelper
- type TestKeyringEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTestNetworkConfig ¶
DefaultTestNetworkConfig creates a network configuration for inproc testing
func GenerateTestingAccounts ¶ added in v1.19.0
func GenerateTestingAccountsWithPower ¶ added in v1.19.0
func GenerateTestingAccountsWithPower(t *testing.T, ctx sdk.Context, app *app.App, r *rand.Rand, n int, power int64) []simtypes.Account
GenerateTestingAccountsWithPower generates n new accounts, creates them (in state) and gives each the provided power worth of bond tokens.
func GetKeyringEntryAddresses ¶ added in v1.19.0
func GetKeyringEntryAddresses(entries []TestKeyringEntry) []sdk.AccAddress
GetKeyringEntryAddresses gets the AccAddress of each entry.
func LatestHeight ¶ added in v1.19.0
LatestHeight returns the latest height of the network or an error if the query fails or no validators exist.
This is similar to Network.LatestHeight() except that this one doesn't wait for a first tick before trying to get the current height (so it can return earlier). It also checks every 500ms instead of every 1s.
func LogOperationMsg ¶ added in v1.19.0
func LogOperationMsg(t *testing.T, operationMsg simtypes.OperationMsg, msg string, args ...interface{})
LogOperationMsg outputs an OperationMsg to test logs. The provided msg and args are included first in the output.
func MutateGenesisState ¶ added in v1.19.0
func MutateGenesisState[G proto.Message](t *testing.T, cfg *testnet.Config, moduleName string, emptyState G, mutator func(state G) G)
MutateGenesisState will extract a GenesisState object from the provided config and run it through the provided mutator. Then it will update the config to have that new genesis state.
G is the type of the specific genesis state struct being used here.
func NewAppConstructor ¶
func NewAppConstructor() testnet.AppConstructor
NewAppConstructor returns a new provenanceapp AppConstructor
func NewTestKeyring ¶ added in v1.19.0
NewTestKeyring creates a new in-memory keyring for use in tests. Use GenerateTestAccountsInKeyring to add entries to the keyring.
func RunGetSignersTests ¶ added in v1.19.0
func RunGetSignersTests[R []M, M sdk.Msg](t *testing.T, allRequestMsgs R, msgMakers []MsgMaker, msgMakersMulti []MsgMakerMulti)
RunGetSignersTests make sure that we can get signers from all msgs. Also ensures that all entries in allRequestMsgs have one maker provided, and that all msg types returned by the makers are in allRequestMsgs.
func WaitForHeight ¶ added in v1.19.0
WaitForHeight performs a blocking check where it waits for a block to be committed after a given block. If that height is not reached within a timeout, an error is returned. Regardless, the latest height queried is returned.
This is similar to Network.WaitForHeight(h) except that this one doesn't wait for a first tick before trying to get the current height (so it can return earlier). It also checks every 500ms instead of every 1s.
func WaitForHeightWithTimeout ¶ added in v1.19.0
WaitForHeightWithTimeout is the same as WaitForHeight except the caller can provide a custom timeout.
This is similar to Network.WaitForHeightWithTimeout(h, t) except that this one doesn't wait for a first tick before trying to get the current height (so it can return earlier). It also checks every 500ms instead of every 1s.
func WaitForNBlocks ¶ added in v1.19.0
WaitForNBlocks waits for the next count blocks to be committed, returning an error upon failure.
func WaitForNextBlock ¶ added in v1.19.0
WaitForNextBlock waits for the next block to be committed, returning an error upon failure.
This is similar to Network.WaitForNextBlock(h, t) except that this one doesn't wait for a first tick before trying to get the current height (so it can return earlier). It also checks every 500ms instead of every 1s.
Types ¶
type ExpectedOp ¶ added in v1.19.0
type ExpectedOp struct { // FutureOpCount is the exected length of the []FutureOperation returned by the Operation. FutureOpCount int // Err is the error expected from the Operation. Err string // Route is the expected OperationMsg.Route value (usually the module name). Route string // EmptyMsg serves two purposes: // 1. The OperationMsg.Name is expected to be the sdk.MsgTypeURL of this field. // 2. The OperationMsg.Msg will be unmarshalled into this field if possible. EmptyMsg sdk.Msg // Comment is the expected OperationMsg.Comment value. Comment string // OK is the expected OperationMsg.OK value. OK bool }
ExpectedOp is the various aspects of a simulation.Operation to check.
type ExpectedProposalMsg ¶ added in v1.19.0
type ExpectedProposalMsg struct { // Key is the expected WeightedProposalMsg.AppParamsKey() Key string // Weight is the expected WeightedProposalMsg.DefaultWeight() Weight int // MsgType is a Msg with the same type that is expected to be returned by the WeightedProposalMsg.MsgSimulatorFn(). // No assertion is made that the returned Msg equals this message, only that they both have the same result from sdk.MsgTypeURL. MsgType sdk.Msg }
ExpectedProposalMsg is the various aspects of a simulation.WeightedProposalMsg to check.
type ExpectedWeightedOp ¶ added in v1.19.0
type ExpectedWeightedOp struct { // Weight is the expected WeightedOperation.Weight. Weight int // Route is the expected WeightedOperation.Route. Route string // MsgType is a Msg with the same type that is expected to be returned by the WeightedOperation.Op() function. // No assertion is made that the returned Msg equals this message, only that they both have the same result from sdk.MsgTypeURL. MsgType sdk.Msg }
GenerateTestingAccounts generates n new accounts, creates them (in state) and gives each 1 million power worth of bond tokens. ExpectedWeightedOp is the various aspects of a simulation.WeightedOperation to check.
type MsgMaker ¶ added in v1.19.0
MsgMaker is a function that returns a new message that has the provided signer. If your Msg can have multiple signers, use a MsgMakerMulti.
type MsgMakerMulti ¶ added in v1.19.0
MsgMakerMulti is a function that returns a new message that has the provided signers. If your Msg can only have one signer, use a MsgMaker.
type SimTestHelper ¶ added in v1.19.0
type SimTestHelper struct { // T is the testing.T to use for the tests. T *testing.T // Ctx is the context to provide to the various simulation-related functions. Ctx sdk.Context // R is the randomizer to provide to the various simulation-related functions. R *rand.Rand // App is the app object used in some of the simulation-related functions, and also used to create test accounts. App *app.App // Accs are the accounts to provide to the various simulation-related funtions. Accs []simtypes.Account }
SimTestHelper contains various things needed to check most of the simulation-related stuff.
func NewSimTestHelper ¶ added in v1.19.0
NewSimTestHelper creates a new SimTestHelper with the provided aspects. You'll probably want to call either WithAccs or WithTestingAccounts on the result to finish setting it up.
func (SimTestHelper) AssertMsgSimulatorFn ¶ added in v1.19.0
func (a SimTestHelper) AssertMsgSimulatorFn(expected sdk.Msg, simFnMaker func() simtypes.MsgSimulatorFn) (sdk.Msg, bool)
AssertMsgSimulatorFn tests that a MsgSimulatorFn generates the expected Msg. The returned bool is true iff everything is as expected. The returned Msg might be nil regardless of the returned bool value.
func (SimTestHelper) AssertProposalMsgs ¶ added in v1.19.0
func (a SimTestHelper) AssertProposalMsgs(expected []ExpectedProposalMsg, proposalMsgsFn func() []simtypes.WeightedProposalMsg) bool
AssertProposalMsgs tests that the results of a ProposalMsgs function are as expected. The returned bool is true iff everything is as expected.
func (SimTestHelper) AssertSimOp ¶ added in v1.19.0
func (a SimTestHelper) AssertSimOp(expected ExpectedOp, opMaker func() simtypes.Operation, opDesc string) (sdk.Msg, []simtypes.FutureOperation, bool)
AssertSimOp tests that a simulation Operation is as expected. The returned bool is true iff everything is as expected. The msg and future ops are returned even if things aren't as expected.
func (SimTestHelper) AssertWeightedOperations ¶ added in v1.19.0
func (a SimTestHelper) AssertWeightedOperations(expected []ExpectedWeightedOp, wOpsFn func() simulation.WeightedOperations) bool
AssertWeightedOperations tests that the results of a WeightedOperations function are as expected. The returned bool is true iff everything is as expected.
func (SimTestHelper) WithAccs ¶ added in v1.19.0
func (a SimTestHelper) WithAccs(accs []simtypes.Account) *SimTestHelper
WithAccs returns a copy of this SimTestHelper, but with the provided Accs.
func (SimTestHelper) WithApp ¶ added in v1.19.0
func (a SimTestHelper) WithApp(app *app.App) *SimTestHelper
WithApp returns a copy of this SimTestHelper, but with a different App.
func (SimTestHelper) WithCtx ¶ added in v1.19.0
func (a SimTestHelper) WithCtx(ctx sdk.Context) *SimTestHelper
WithCtx returns a copy of this SimTestHelper, but with a different Ctx.
func (SimTestHelper) WithR ¶ added in v1.19.0
func (a SimTestHelper) WithR(r *rand.Rand) *SimTestHelper
WithR returns a copy of this SimTestHelper, but with a different R.
func (SimTestHelper) WithT ¶ added in v1.19.0
func (a SimTestHelper) WithT(t *testing.T) *SimTestHelper
WithT returns a copy of this SimTestHelper, but with a different T.
func (SimTestHelper) WithTestingAccounts ¶ added in v1.19.0
func (a SimTestHelper) WithTestingAccounts(n int) *SimTestHelper
WithTestingAccounts returns a copy of this SimTestHelper, but with n randomized Accs.
func (SimTestHelper) WithTestingAccountsWithPower ¶ added in v1.19.0
func (a SimTestHelper) WithTestingAccountsWithPower(n int, power int64) *SimTestHelper
WithTestingAccountsWithPower returns a copy of this SimTestHelper, but with n randomized Accs having the provided power.
type TestKeyringEntry ¶ added in v1.19.0
type TestKeyringEntry struct { keyring.Record AccAddress sdk.AccAddress Mnemonic string }
TestKeyringEntry is a keyring.Record plus some extra fields that might be needed for unit tests.
func GenerateTestAccountsInKeyring ¶ added in v1.19.0
GenerateTestAccountsInKeyring adds count entries to the keyring. The names of the entries will be like "test_key_01".
Counting starts at 1 + the number of entries already in the keyring. E.g. If there aren't any yet, the first one will be "test_key_01". E.g. If there are five already in there, the first one added here will be "test_key_06".
Only newly created entries are returned.
func GenerateTestKeyring ¶ added in v1.19.0
func GenerateTestKeyring(t *testing.T, count int, codec codec.Codec) ([]TestKeyringEntry, keyring.Keyring)
GenerateTestKeyring creates an in-memory keyring and adds count entries to it. The names of the entries will be incrementing, starting at "test_key_01".