Documentation ¶
Index ¶
- Constants
- func ApplyMockIO(c *cobra.Command) (BufferReader, BufferWriter)
- func DefaultContext(key, tkey storetypes.StoreKey) sdk.Context
- func DefaultContextWithKeys(keys map[string]*storetypes.KVStoreKey, ...) sdk.Context
- func DiffCollectionsMigration(ctx sdk.Context, storeKey *storetypes.KVStoreKey, iterations int, ...) error
- func GenerateCoinKey(algo keyring.SignatureAlgo, cdc codec.Codec) (sdk.AccAddress, string, error)
- func GenerateSaveCoinKey(keybase keyring.Keyring, keyName, mnemonic string, overwrite bool, ...) (sdk.AccAddress, string, error)
- func GetRequest(url string) ([]byte, error)
- func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error)
- func GetTempDir(tb testing.TB) string
- func PostRequest(url, contentType string, data []byte) ([]byte, error)
- func RandSliceElem[E any](r *rand.Rand, elems []E) (E, bool)
- func RequireProtoDeepEqual(t *testing.T, p1, p2 interface{})
- func TempFile(tb testing.TB) *os.File
- func WriteToNewTempFile(tb testing.TB, s string) *os.File
- type BufferReader
- type BufferWriter
- type TestAccount
- type TestContext
Constants ¶
const ( AccountsModuleName = "accounts" AuthModuleName = "auth" AuthzModuleName = "authz" BankModuleName = "bank" CircuitModuleName = "circuit" DistributionModuleName = "distribution" EvidenceModuleName = "evidence" FeegrantModuleName = "feegrant" GovModuleName = "gov" GroupModuleName = "group" MintModuleName = "mint" NFTModuleName = "nft" ParamsModuleName = "params" ProtocolPoolModuleName = "protocolpool" SlashingModuleName = "slashing" StakingModuleName = "staking" TxModuleName = "tx" UpgradeModuleName = "upgrade" EpochsModuleName = "epochs" )
Variables ¶
This section is empty.
Functions ¶
func ApplyMockIO ¶
func ApplyMockIO(c *cobra.Command) (BufferReader, BufferWriter)
ApplyMockIO replaces stdin/out/err with buffers that can be used during testing. Returns an input BufferReader and an output BufferWriter.
func DefaultContext ¶ added in v0.43.0
func DefaultContext(key, tkey storetypes.StoreKey) sdk.Context
DefaultContext creates a sdk.Context with a fresh MemDB that can be used in tests.
func DefaultContextWithKeys ¶ added in v0.50.0
func DefaultContextWithKeys( keys map[string]*storetypes.KVStoreKey, transKeys map[string]*storetypes.TransientStoreKey, memKeys map[string]*storetypes.MemoryStoreKey, ) sdk.Context
DefaultContextWithKeys creates a sdk.Context with a fresh MemDB, mounting the providing keys for usage in the multistore. This function is intended to be used for testing purposes only.
func DiffCollectionsMigration ¶ added in v0.50.0
func DiffCollectionsMigration( ctx sdk.Context, storeKey *storetypes.KVStoreKey, iterations int, writeElem func(int64), targetHash string, ) error
DiffCollectionsMigration is meant to aid in the migration from the previous store solution to collections. It takes a few steps to use it:
- Write a test function that writes elements using the old store solution.
- Run the test function and copy the hash that it outputs (run it a couple of times to make sure no non-deterministic data is being used).
- Change the code to use collections and run the test function again to make sure the hash didn't change.
First we write it as such:
func TestMigrateStore(t *testing.T) { DiffCollectionsMigration( ctx, storeKey, 100, func(i int64) { err := SetPreviousProposerConsAddr(ctx, addrs[i]) require.NoError(t, err) }, "abcdef0123456789", ) }
Then after we change the code to use collections, we modify the writeElem function:
func TestMigrateStore(t *testing.T) { DiffCollectionsMigration( ctx, storeKey, 100, func(i int64) { err := keeper.PreviousProposer.Set(ctx, addrs[i]) require.NoError(t, err) }, "abcdef0123456789", ) }
func GenerateCoinKey ¶ added in v0.45.0
func GenerateCoinKey(algo keyring.SignatureAlgo, cdc codec.Codec) (sdk.AccAddress, string, error)
GenerateCoinKey generates a new key mnemonic along with its address.
func GenerateSaveCoinKey ¶ added in v0.45.0
func GenerateSaveCoinKey( keybase keyring.Keyring, keyName, mnemonic string, overwrite bool, algo keyring.SignatureAlgo, hdPath string, ) (sdk.AccAddress, string, error)
GenerateSaveCoinKey generates a new key mnemonic with its address. If mnemonic is provided then it's used for key generation. The key is saved in the keyring. The function returns error if overwrite=true and the key already exists.
func GetRequest ¶ added in v0.47.0
GetRequest defines a wrapper around an HTTP GET request with a provided URL. An error is returned if the request or reading the body fails.
func GetRequestWithHeaders ¶
GetRequestWithHeaders defines a wrapper around an HTTP GET request with a provided URL and custom headers An error is returned if the request or reading the body fails.
func GetTempDir ¶ added in v0.46.0
GetTempDir returns a writable temporary director for the test to use.
func PostRequest ¶ added in v0.47.0
PostRequest defines a wrapper around an HTTP POST request with a provided URL and data. An error is returned if the request or reading the body fails.
func RequireProtoDeepEqual ¶ added in v0.50.0
RequireProtoDeepEqual fails the test t if p1 and p2 are not equivalent protobuf messages. Where p1 and p2 are proto.Message or slices of proto.Message.
Types ¶
type BufferReader ¶
BufferReader is implemented by types that read from a string buffer.
func ApplyMockIODiscardOutErr ¶
func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader
ApplyMockIODiscardOutErr replaces a cobra.Command output and error streams with a dummy io.Writer. Replaces and returns the io.Reader associated to the cobra.Command input stream.
type BufferWriter ¶
BufferWriter is implemented by types that write to a buffer.
type TestAccount ¶ added in v0.47.0
type TestAccount struct { Name string Address types.AccAddress }
func CreateKeyringAccounts ¶ added in v0.47.0
type TestContext ¶ added in v0.47.0
func DefaultContextWithDB ¶ added in v0.47.0
func DefaultContextWithDB(tb testing.TB, key, tkey storetypes.StoreKey) TestContext
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cmdtest contains a framework for testing cobra Commands within Go unit tests.
|
Package cmdtest contains a framework for testing cobra Commands within Go unit tests. |
Integration contains the integration test setup used for SDK modules.
|
Integration contains the integration test setup used for SDK modules. |
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
Package network implements and exposes a fully operational in-process CometBFT test network that consists of at least one or potentially many validators.
|
Package network implements and exposes a fully operational in-process CometBFT test network that consists of at least one or potentially many validators. |
x
|
|
counter/testutil
Package testutil is a generated GoMock package.
|
Package testutil is a generated GoMock package. |