testing

package
v0.1.1-ibc-go-v7.3-was... Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGasUsed = uint64(1)

Variables

View Source
var (
	// Represents the code of the wasm contract used in the tests with a mock vm.
	WasmMagicNumber                    = []byte("\x00\x61\x73\x6D")
	Code                               = append(WasmMagicNumber, []byte("0123456780123456780123456780")...)
	MockClientStateBz                  = []byte("client-state-data")
	MockConsensusStateBz               = []byte("consensus-state-data")
	MockTendermitClientState           = CreateMockTendermintClientState(clienttypes.NewHeight(1, 10))
	MockTendermintClientHeader         = &ibctm.Header{}
	MockTendermintClientMisbehaviour   = ibctm.NewMisbehaviour("client-id", MockTendermintClientHeader, MockTendermintClientHeader)
	MockTendermintClientConsensusState = ibctm.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("hash")), []byte("nextValsHash"))
	MockValidProofBz                   = []byte("valid proof")
	MockInvalidProofBz                 = []byte("invalid proof")
	MockUpgradedClientStateProofBz     = []byte("upgraded client state proof")
	MockUpgradedConsensusStateProofBz  = []byte("upgraded consensus state proof")

	ErrMockContract = errors.New("mock contract error")
	ErrMockVM       = errors.New("mock vm error")
)

Functions

func AllowWasmClients

func AllowWasmClients(chain *ibctesting.TestChain)

AllowWasmClients adds 08-wasm to the list of allowed clients

func CreateMockClientStateBz

func CreateMockClientStateBz(cdc codec.BinaryCodec, checksum types.Checksum) []byte

CreateMockClientStateBz returns valid client state bytes for use in tests.

func CreateMockContract

func CreateMockContract(code []byte) []byte

CreateMockContract returns a well formed (magic number prefixed) wasm contract the given code.

func CreateMockTendermintClientState

func CreateMockTendermintClientState(height clienttypes.Height) *ibctm.ClientState

CreateMockTendermintClientState returns a valid Tendermint client state for use in tests.

func GenerateString

func GenerateString(length uint) string

GenerateString generates a random string of the given length in bytes

Types

type MockWasmEngine

type MockWasmEngine struct {
	StoreCodeFn          func(code wasmvm.WasmCode) (wasmvm.Checksum, error)
	StoreCodeUncheckedFn func(code wasmvm.WasmCode) (wasmvm.Checksum, error)
	InstantiateFn        func(checksum wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)
	MigrateFn            func(checksum wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)
	GetCodeFn            func(checksum wasmvm.Checksum) (wasmvm.WasmCode, error)
	PinFn                func(checksum wasmvm.Checksum) error
	UnpinFn              func(checksum wasmvm.Checksum) error
	// contains filtered or unexported fields
}

MockWasmEngine implements types.WasmEngine for testing purposes. One or multiple messages can be stubbed. Without a stub function a panic is thrown. ref: https://github.com/CosmWasm/wasmd/blob/v0.42.0/x/wasm/keeper/wasmtesting/mock_engine.go#L19

func NewMockWasmEngine

func NewMockWasmEngine() *MockWasmEngine

NewMockWasmEngine creates and returns a new instance of the mock wasmvm for testing purposes. Each callback method of the mock wasmvm can be overridden to assign specific functionality. Default functionality is assigned for StoreCode, StoreCodeUnchecked and GetCode. Both Pin and Unpin are implemented as no-op methods. All other callbacks stored in the query and sudo callback maps panic. Use RegisterQueryCallback and RegisterSudoCallback methods to assign expected behaviour for test cases.

func (*MockWasmEngine) GetCode

func (m *MockWasmEngine) GetCode(checksum wasmvm.Checksum) (wasmvm.WasmCode, error)

GetCode implements the WasmEngine interface.

func (*MockWasmEngine) Instantiate

func (m *MockWasmEngine) Instantiate(checksum wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)

Instantiate implements the WasmEngine interface.

func (*MockWasmEngine) Migrate

func (m *MockWasmEngine) Migrate(checksum wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)

Migrate implements the WasmEngine interface.

func (*MockWasmEngine) Pin

func (m *MockWasmEngine) Pin(checksum wasmvm.Checksum) error

Pin implements the WasmEngine interface.

func (*MockWasmEngine) Query

func (m *MockWasmEngine) Query(checksum wasmvm.Checksum, env wasmvmtypes.Env, queryMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) ([]byte, uint64, error)

Query implements the WasmEngine interface.

func (*MockWasmEngine) RegisterQueryCallback

func (m *MockWasmEngine) RegisterQueryCallback(queryMessage any, fn queryFn)

RegisterQueryCallback registers a callback for a specific message type.

func (*MockWasmEngine) RegisterSudoCallback

func (m *MockWasmEngine) RegisterSudoCallback(sudoMessage any, fn sudoFn)

RegisterSudoCallback registers a callback for a specific sudo message type.

func (*MockWasmEngine) StoreCode

func (m *MockWasmEngine) StoreCode(code wasmvm.WasmCode) (wasmvm.Checksum, error)

StoreCode implements the WasmEngine interface.

func (*MockWasmEngine) StoreCodeUnchecked

func (m *MockWasmEngine) StoreCodeUnchecked(code wasmvm.WasmCode) (wasmvm.Checksum, error)

StoreCode implements the WasmEngine interface.

func (*MockWasmEngine) Sudo

func (m *MockWasmEngine) Sudo(checksum wasmvm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)

Sudo implements the WasmEngine interface.

func (*MockWasmEngine) Unpin

func (m *MockWasmEngine) Unpin(checksum wasmvm.Checksum) error

Unpin implements the WasmEngine interface.

type WasmEndpoint

type WasmEndpoint struct {
	*ibctesting.Endpoint
}

WasmEndpoint is a wrapper around the ibctesting pkg Endpoint struct. It will override any functions which require special handling for the wasm client.

func NewWasmEndpoint

func NewWasmEndpoint(chain *ibctesting.TestChain) *WasmEndpoint

NewWasmEndpoint returns a wasm endpoint with the default ibctesting pkg Endpoint embedded.

func (*WasmEndpoint) CreateClient

func (endpoint *WasmEndpoint) CreateClient() error

CreateClient creates an wasm client on a mock cometbft chain. The client and consensus states are represented by byte slices and the starting height is 1.

Directories

Path Synopsis
params
Package params defines the simulation parameters in the simapp.
Package params defines the simulation parameters in the simapp.

Jump to

Keyboard shortcuts

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