testutil

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const TestnetEnvVar = "PIO_TESTNET"

Variables

This section is empty.

Functions

func BurnCoinsEvents added in v1.20.0

func BurnCoinsEvents(moduleName string, amount sdk.Coins) sdk.Events

BurnCoinsEvents creates the events emitted during BurnCoins.

func BurnCoinsEventsStrs added in v1.20.0

func BurnCoinsEventsStrs(moduleAddr, amount string) sdk.Events

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 Cleanup added in v1.19.0

func Cleanup(n *testnet.Network, t *testing.T)

Cleanup runs the standard cleanup for our test networks.

func DefaultTestNetworkConfig

func DefaultTestNetworkConfig() testnet.Config

DefaultTestNetworkConfig creates a network configuration for inproc testing

func FailedSendCoinsEvents added in v1.20.0

func FailedSendCoinsEvents(from sdk.AccAddress, amount sdk.Coins) sdk.Events

FailedSendCoinsEvents creates the events emitted during SendCoins when there's an error from the send restrictions.

func FailedSendCoinsEventsStrs added in v1.20.0

func FailedSendCoinsEventsStrs(from, amount string) sdk.Events

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

func LatestHeight(n *testnet.Network) (int64, error)

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

func MintCoinsEvents(moduleName string, amount sdk.Coins) sdk.Events

MintCoinsEvents creates the events emitted during MintCoins.

func MintCoinsEventsStrs added in v1.20.0

func MintCoinsEventsStrs(moduleAddr, amount string) sdk.Events

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

func NewTestKeyring(t *testing.T, codec codec.Codec) keyring.Keyring

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

func SendCoinsEvents(from, to sdk.AccAddress, amount sdk.Coins) sdk.Events

SendCoinsEvents creates the events emitted during SendCoins.

func SendCoinsEventsStrs added in v1.20.0

func SendCoinsEventsStrs(from, to, amount string) sdk.Events

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

func WaitForHeight(n *testnet.Network, h int64) (int64, error)

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

func WaitForHeightWithTimeout(n *testnet.Network, h int64, t time.Duration) (int64, error)

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

func WaitForNBlocks(n *testnet.Network, count int) error

WaitForNBlocks waits for the next count blocks to be committed, returning an error upon failure.

func WaitForNextBlock added in v1.19.0

func WaitForNextBlock(n *testnet.Network) error

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

type EventsBuilder struct {
	Events sdk.Events
	T      *testing.T
}

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

type MsgMaker func(signer string) sdk.Msg

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

type MsgMakerMulti func(signers []string) sdk.Msg

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

func NewSimTestHelper(t *testing.T, ctx sdk.Context, r *rand.Rand, app *app.App) *SimTestHelper

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

func GenerateTestAccountsInKeyring(t *testing.T, kr keyring.Keyring, count int) []TestKeyringEntry

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".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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