Documentation ¶
Index ¶
- Constants
- func BurnCoinsEvents(moduleName string, amount sdk.Coins) sdk.Events
- func BurnCoinsEventsStrs(moduleAddr, amount string) sdk.Events
- func Cleanup(n *testnet.Network, t *testing.T)
- func DefaultTestNetworkConfig() testnet.Config
- func FailedSendCoinsEvents(from sdk.AccAddress, amount sdk.Coins) sdk.Events
- func FailedSendCoinsEventsStrs(from, amount string) sdk.Events
- 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 MintCoinsEvents(moduleName string, amount sdk.Coins) sdk.Events
- func MintCoinsEventsStrs(moduleAddr, amount string) sdk.Events
- 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 SendCoinsEvents(from, to sdk.AccAddress, amount sdk.Coins) sdk.Events
- func SendCoinsEventsStrs(from, to, amount string) sdk.Events
- func UnsetTestnetEnvVar() func()
- 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 EventsBuilder
- func (b *EventsBuilder) AddBurnCoins(moduleName string, amount sdk.Coins) *EventsBuilder
- func (b *EventsBuilder) AddBurnCoinsStrs(moduleAddr, amount string) *EventsBuilder
- func (b *EventsBuilder) AddEvent(events ...sdk.Event) *EventsBuilder
- func (b *EventsBuilder) AddEvents(events sdk.Events) *EventsBuilder
- func (b *EventsBuilder) AddFailedSendCoins(from sdk.AccAddress, amount sdk.Coins) *EventsBuilder
- func (b *EventsBuilder) AddFailedSendCoinsStrs(from, amount string) *EventsBuilder
- func (b *EventsBuilder) AddMintCoins(moduleName string, amount sdk.Coins) *EventsBuilder
- func (b *EventsBuilder) AddMintCoinsStrs(moduleAddr, amount string) *EventsBuilder
- func (b *EventsBuilder) AddSendCoins(from, to sdk.AccAddress, amount sdk.Coins) *EventsBuilder
- func (b *EventsBuilder) AddSendCoinsStrs(from, to, amount string) *EventsBuilder
- func (b *EventsBuilder) AddTypedEvent(tevs ...proto.Message) *EventsBuilder
- func (b *EventsBuilder) Build() sdk.Events
- 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 ¶
const TestnetEnvVar = "PIO_TESTNET"
Variables ¶
This section is empty.
Functions ¶
func BurnCoinsEvents ¶ added in v1.20.0
BurnCoinsEvents creates the events emitted during BurnCoins.
func BurnCoinsEventsStrs ¶ added in v1.20.0
BurnCoinsEventsStrs creates the events emitted during BurnCoins, but takes in the values as strings. Note that the first argument should be the bech32 address string of the module account (not the module name).
func DefaultTestNetworkConfig ¶
DefaultTestNetworkConfig creates a network configuration for inproc testing
func FailedSendCoinsEvents ¶ added in v1.20.0
FailedSendCoinsEvents creates the events emitted during SendCoins when there's an error from the send restrictions.
func FailedSendCoinsEventsStrs ¶ added in v1.20.0
FailedSendCoinsEventsStrs creates the events emitted during SendCoins when there's an error from the send restrictions, but takes in the values as strings.
func GenerateTestingAccounts ¶ added in v1.19.0
func GenerateTestingAccounts(t *testing.T, ctx sdk.Context, app *app.App, r *rand.Rand, n int) []simtypes.Account
GenerateTestingAccounts generates n new accounts, creates them (in state) and gives each 1 million power worth of bond tokens.
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 MintCoinsEvents ¶ added in v1.20.0
MintCoinsEvents creates the events emitted during MintCoins.
func MintCoinsEventsStrs ¶ added in v1.20.0
MintCoinsEventsStrs creates the events emitted during MintCoins, but takes in the values as strings. Note that the first argument should be the bech32 address string of the module account (not the module name).
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 SendCoinsEvents ¶ added in v1.20.0
SendCoinsEvents creates the events emitted during SendCoins.
func SendCoinsEventsStrs ¶ added in v1.20.0
SendCoinsEventsStrs creates the events emitted during SendCoins, but takes in the values as strings.
func UnsetTestnetEnvVar ¶ added in v1.20.0
func UnsetTestnetEnvVar() func()
UnsetTestnetEnvVar will unset the PIO_TESTNET environment variable and return a deferrable that will put it back.
Go runs tests inside an environment that might already have some environment variables defined. E.g. if you have `export PIO_TESTNET=true` in your environment, and run `make test`, then, when a test runs, it will start with a `PIO_TESTNET` value of `true`. But that can mess up some tests that expect to start without a PIO_TESTNET env var set.
For individual test cases, you should use t.Setenv for changing environment variables. This exists because t.Setenv can't be used to unset an environment variable.
Standard usage: defer testutil.UnsetTestnetEnvVar()()
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 EventsBuilder ¶ added in v1.20.0
EventsBuilder helps put together a list of events for testing purposes. Create one using NewEventsBuilder, then add events using the methods like AddEvent or AddSendCoins. Once everything has been added, use Build() to get the final list of events.
func NewEventsBuilder ¶ added in v1.20.0
func NewEventsBuilder(t *testing.T) *EventsBuilder
NewEventsBuilder creates a new EventsBuilder that will use the provided T for error checking. If a T is provided, errors will cause test failures, otherwise errors will cause panics.
func (*EventsBuilder) AddBurnCoins ¶ added in v1.20.0
func (b *EventsBuilder) AddBurnCoins(moduleName string, amount sdk.Coins) *EventsBuilder
AddBurnCoins adds the events emitted during BurnCoins.
func (*EventsBuilder) AddBurnCoinsStrs ¶ added in v1.20.0
func (b *EventsBuilder) AddBurnCoinsStrs(moduleAddr, amount string) *EventsBuilder
AddBurnCoinsStrs adds the events emitted during BurnCoins, but takes in the values as strings. Note that the first argument should be the bech32 address string of the module account (not the module name).
func (*EventsBuilder) AddEvent ¶ added in v1.20.0
func (b *EventsBuilder) AddEvent(events ...sdk.Event) *EventsBuilder
AddEvent adds one or more sdk.Event entries to this builder.
func (*EventsBuilder) AddEvents ¶ added in v1.20.0
func (b *EventsBuilder) AddEvents(events sdk.Events) *EventsBuilder
AddEvents adds all of the provided sdk.Events to this builder.
func (*EventsBuilder) AddFailedSendCoins ¶ added in v1.20.0
func (b *EventsBuilder) AddFailedSendCoins(from sdk.AccAddress, amount sdk.Coins) *EventsBuilder
AddFailedSendCoins adds the events emitted during SendCoins when there's an error from the send restrictions.
func (*EventsBuilder) AddFailedSendCoinsStrs ¶ added in v1.20.0
func (b *EventsBuilder) AddFailedSendCoinsStrs(from, amount string) *EventsBuilder
AddFailedSendCoinsStrs adds the events emitted during SendCoins when there's an error from the send restrictions, but takes in the values as strings.
func (*EventsBuilder) AddMintCoins ¶ added in v1.20.0
func (b *EventsBuilder) AddMintCoins(moduleName string, amount sdk.Coins) *EventsBuilder
AddMintCoins adds the events emitted during MintCoins.
func (*EventsBuilder) AddMintCoinsStrs ¶ added in v1.20.0
func (b *EventsBuilder) AddMintCoinsStrs(moduleAddr, amount string) *EventsBuilder
AddMintCoinsStrs adds the events emitted during MintCoins, but takes in the values as strings. Note that the first argument should be the bech32 address string of the module account (not the module name).
func (*EventsBuilder) AddSendCoins ¶ added in v1.20.0
func (b *EventsBuilder) AddSendCoins(from, to sdk.AccAddress, amount sdk.Coins) *EventsBuilder
AddSendCoins adds the events emitted during SendCoins.
func (*EventsBuilder) AddSendCoinsStrs ¶ added in v1.20.0
func (b *EventsBuilder) AddSendCoinsStrs(from, to, amount string) *EventsBuilder
AddSendCoinsStrs adds the events emitted during SendCoins, but takes in the values as strings.
func (*EventsBuilder) AddTypedEvent ¶ added in v1.20.0
func (b *EventsBuilder) AddTypedEvent(tevs ...proto.Message) *EventsBuilder
AddTypedEvent converts each of the provided events into an sdk.Event then adds it to this builder.
func (*EventsBuilder) Build ¶ added in v1.20.0
func (b *EventsBuilder) Build() sdk.Events
Build returns the list of Events built so far.
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 }
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".