testutil

package
v2.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: BSD-2-Clause Imports: 35 Imported by: 0

README

Testutil Directory

The x/nutil/testutil directory is not a Cosmos SDK module itself. It is a collection of test utilities for testing the other x/modules.

For app-backed tests, prefer the helpers in testapp for app and context setup. Use table-driven tests or testify suites for structure, and use the block helpers in testapp/block.go when tests need to advance block height or time.

Documentation

Overview

Package nullify provides methods to init nil values structs for test assertion.

Index

Constants

View Source
const (
	ADDR_GUARD_CREAM = "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"
	ADDR_SUDO_ROOT   = "nibi1qqx5reauy4glpskmppy88pz25qp2py5yxvpxdt"
)

Variables

View Source
var Latin = TypeLatin{
	Letters:    "abcdefghijklmnopqrstuvwxyz",
	CapLetters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	Numbers:    "0123456789",
}

Functions

func AssertEventPresent

func AssertEventPresent(events sdk.Events, eventType string) error

AssertEventPresent: Errors if the given event type is not present in events

func AssertEventsPresent

func AssertEventsPresent(events sdk.Events, eventTypes []string) (err error)

AssertEventsPresent: Errors if the given event types are not present in events

func BlankContext

func BlankContext(storeKeyName string) sdk.Context

func EventHasAttributeValue

func EventHasAttributeValue(abciEvent sdk.Event, key string, want string) error

EventHasAttributeValue parses the given ABCI event at a key to see if it matches (contains) the wanted value.

Args:

  • abciEvent: The event under test
  • key: The key for which we'll check the value
  • want: The desired value

func Fill

func Fill(x any) any

Fill analyze all struct fields and slices with reflection and initialize the nil and empty slices, structs, and pointers.

func FilterNewEvents

func FilterNewEvents(beforeEvents, afterEvents sdk.Events) sdk.Events

FilterNewEvents returns only the new events from afterEvents that were not present in beforeEvents

func FindAbciEventsOfType

func FindAbciEventsOfType(events []abci.Event, eventType string) []abci.Event

FindAbciEventsOfType searches through events to find types you care about.

func FindEventsOfType

func FindEventsOfType(events sdk.Events, eventType string) []sdk.Event

FindEventsOfType searches through events to find types you care about.

func GetPackageDir

func GetPackageDir() (string, error)

GetPackageDir: Returns the absolute path of the Golang package that calls this function.

func GovModuleAddr

func GovModuleAddr() sdk.AccAddress

func NewAccAddress added in v2.14.0

func NewAccAddress() sdk.AccAddress

NewAccAddress returns a sample address (sdk.NewAccAddress) created using secp256k1. Note that NewAccAddress().String() can be used to get a string representation.

func NewPrivKey added in v2.14.0

func NewPrivKey() (*secp256k1.PrivKey, sdk.AccAddress)

NewPrivKey returns a private key and corresponding on-chain address.

func PrivKeyAddressPairs

func PrivKeyAddressPairs(n int) (keys []cryptotypes.PrivKey, addrs []sdk.AccAddress)

PrivKeyAddressPairs generates (deterministically) a total of n private keys and addresses.

func RandLetters

func RandLetters(n int) string

func RequireContainsTypedEvent

func RequireContainsTypedEvent(t require.TestingT, ctx sdk.Context, event proto.Message)

func RequireNotHasTypedEvent

func RequireNotHasTypedEvent(t require.TestingT, ctx sdk.Context, event proto.Message)

RequireNotHasTypedEvent: Error if an event type matches the proto.Message name

func RunFunctionTestSuite

func RunFunctionTestSuite(s *suite.Suite, testCases []FunctionTestCase)

func RunFunctionTests

func RunFunctionTests(t *testing.T, testCases []FunctionTestCase)

func SetupClientCtx

func SetupClientCtx(t *testing.T) context.Context

SetupClientCtx configures the client and server contexts and returns the resultant 'context.Context'. This is useful for executing CLI commands.

Types

type FunctionTestCase

type FunctionTestCase struct {
	Name string
	Test func()
}

type FunctionTestCases

type FunctionTestCases = []FunctionTestCase

type LogRoutingSuite

type LogRoutingSuite struct {
	suite.Suite
}

LogRoutingSuite routes standard library log output through the active testify suite's testing.T, so log.Print* calls show up with `go test -v`.

Embed this suite in tests that need routed log output. If the embedding suite defines its own SetupSuite, testify will call that method instead of the embedded one, so the suite must call s.LogRoutingSuite.SetupSuite() itself.

func (*LogRoutingSuite) SetupSuite

func (s *LogRoutingSuite) SetupSuite()

SetupSuite configures the global standard library logger to write through the suite. Call this explicitly from user-defined SetupSuite methods on suites that embed LogRoutingSuite.

func (*LogRoutingSuite) Write

func (s *LogRoutingSuite) Write(p []byte) (int, error)

type TypeLatin

type TypeLatin struct {
	Letters    string
	CapLetters string
	Numbers    string
}

Directories

Path Synopsis
Package localnet provides test helpers for connecting Go tests to an already- running Nibiru localnet.
Package localnet provides test helpers for connecting Go tests to an already- running Nibiru localnet.

Jump to

Keyboard shortcuts

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