mock

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 25 Imported by: 0

README

This package is only intended to be used for testing core IBC. In order to maintain secure testing, we need to do message passing and execution which requires connecting an IBC application module that fulfills all the callbacks. We cannot connect to ibc-transfer which does not support all channel types so instead we create a mock application module which does nothing. It simply return nil in all cases so no error ever occurs. It is intended to be as minimal and lightweight as possible and should never import simapp.

Documentation

Overview

This package is only intended to be used for testing core IBC. In order to maintain secure testing, we need to do message passing and execution which requires connecting an IBC application module that fulfills all the callbacks. We cannot connect to ibc-transfer which does not support all channel types so instead we create a mock application module which does nothing. It simply return nil in all cases so no error ever occurs. It is intended to be as minimal and lightweight as possible and should never import simapp.

Index

Constants

View Source
const (
	ModuleName = "mock"

	PortID  = ModuleName
	Version = "mock-version"
)

Variables

View Source
var (
	MockAcknowledgement             = channeltypes.NewResultAcknowledgement([]byte("mock acknowledgement"))
	MockFailAcknowledgement         = channeltypes.NewErrorAcknowledgement(fmt.Errorf("mock failed acknowledgement"))
	MockPacketData                  = []byte("mock packet data")
	MockFailPacketData              = []byte("mock failed packet data")
	MockAsyncPacketData             = []byte("mock async packet data")
	MockRecvCanaryCapabilityName    = "mock receive canary capability name"
	MockAckCanaryCapabilityName     = "mock acknowledgement canary capability name"
	MockTimeoutCanaryCapabilityName = "mock timeout canary capability name"
)

Functions

func GetMockAckCanaryCapabilityName added in v0.1.4

func GetMockAckCanaryCapabilityName(packet channeltypes.Packet) string

GetMockAckCanaryCapabilityName generates a capability name for OnAcknowledgementPacket functionality.

func GetMockRecvCanaryCapabilityName added in v0.1.4

func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string

GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality.

func GetMockTimeoutCanaryCapabilityName added in v0.1.4

func GetMockTimeoutCanaryCapabilityName(packet channeltypes.Packet) string

GetMockTimeoutCanaryCapabilityName generates a capability name for OnTimeoutacket functionality.

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule represents the AppModule for the mock module.

func NewAppModule

func NewAppModule(pk PortKeeper) AppModule

NewAppModule returns a mock AppModule instance.

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)

BeginBlock implements the AppModule interface

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

ConsensusVersion implements AppModule/ConsensusVersion.

func (AppModule) EndBlock

func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate

EndBlock implements the AppModule interface

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage

ExportGenesis implements the AppModule interface.

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis implements the AppModule interface.

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry)

RegisterInvariants implements the AppModule interface.

func (AppModule) RegisterServices

func (am AppModule) RegisterServices(module.Configurator)

RegisterServices implements the AppModule interface.

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic is the mock AppModuleBasic.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage

DefaultGenesis implements AppModuleBasic interface.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd() *cobra.Command

GetQueryCmd implements AppModuleBasic interface.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd() *cobra.Command

GetTxCmd implements AppModuleBasic interface.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name implements AppModuleBasic interface.

func (AppModuleBasic) RegisterGRPCGatewayRoutes

func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux)

RegisterGRPCGatewayRoutes implements AppModuleBasic interface.

func (AppModuleBasic) RegisterInterfaces

func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)

RegisterInterfaces implements AppModuleBasic interface.

func (AppModuleBasic) RegisterLegacyAminoCodec

func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino)

RegisterLegacyAminoCodec implements AppModuleBasic interface.

func (AppModuleBasic) ValidateGenesis

ValidateGenesis implements the AppModuleBasic interface.

type EmptyAcknowledgement added in v0.1.4

type EmptyAcknowledgement struct {
	Response []byte
}

EmptyAcknowledgement implements the exported.Acknowledgement interface and always returns an empty byte string as Response

func NewEmptyAcknowledgement added in v0.1.4

func NewEmptyAcknowledgement() EmptyAcknowledgement

NewEmptyAcknowledgement returns a new instance of EmptyAcknowledgement

func (EmptyAcknowledgement) Acknowledgement added in v0.1.4

func (ack EmptyAcknowledgement) Acknowledgement() []byte

Acknowledgement implements the Acknowledgement interface

func (EmptyAcknowledgement) Success added in v0.1.4

func (ack EmptyAcknowledgement) Success() bool

Success implements the Acknowledgement interface

type IBCApp added in v0.1.4

type IBCApp struct {
	PortID       string
	ScopedKeeper capabilitykeeper.ScopedKeeper

	OnChanOpenInit func(
		ctx sdk.Context,
		order channeltypes.Order,
		connectionHops []string,
		portID string,
		channelID string,
		channelCap *capabilitytypes.Capability,
		counterparty channeltypes.Counterparty,
		version string,
	) (string, error)

	OnChanOpenTry func(
		ctx sdk.Context,
		order channeltypes.Order,
		connectionHops []string,
		portID,
		channelID string,
		channelCap *capabilitytypes.Capability,
		counterparty channeltypes.Counterparty,
		counterpartyVersion string,
	) (version string, err error)

	OnChanOpenAck func(
		ctx sdk.Context,
		portID,
		channelID string,
		counterpartyChannelID string,
		counterpartyVersion string,
	) error

	OnChanOpenConfirm func(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	OnChanCloseInit func(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	OnChanCloseConfirm func(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	// OnRecvPacket must return an acknowledgement that implements the Acknowledgement interface.
	// In the case of an asynchronous acknowledgement, nil should be returned.
	// If the acknowledgement returned is successful, the state changes on callback are written,
	// otherwise the application state changes are discarded. In either case the packet is received
	// and the acknowledgement is written (in synchronous cases).
	OnRecvPacket func(
		ctx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
	) exported.Acknowledgement

	OnAcknowledgementPacket func(
		ctx sdk.Context,
		packet channeltypes.Packet,
		acknowledgement []byte,
		relayer sdk.AccAddress,
	) error

	OnTimeoutPacket func(
		ctx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
	) error
}

IBCApp contains IBC application module callbacks as defined in 05-port.

func NewIBCApp added in v0.1.4

func NewIBCApp(portID string, scopedKeeper capabilitykeeper.ScopedKeeper) *IBCApp

NewIBCApp returns a IBCApp. An empty PortID indicates the mock app doesn't bind/claim ports.

type IBCModule added in v0.1.4

type IBCModule struct {
	IBCApp *IBCApp // base application of an IBC middleware stack
	// contains filtered or unexported fields
}

IBCModule implements the ICS26 callbacks for testing/mock.

func NewIBCModule added in v0.1.4

func NewIBCModule(appModule *AppModule, app *IBCApp) IBCModule

NewIBCModule creates a new IBCModule given the underlying mock IBC application and scopedKeeper.

func (IBCModule) OnAcknowledgementPacket added in v0.1.4

func (im IBCModule) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error

OnAcknowledgementPacket implements the IBCModule interface.

func (IBCModule) OnChanCloseConfirm added in v0.1.4

func (im IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error

OnChanCloseConfirm implements the IBCModule interface.

func (IBCModule) OnChanCloseInit added in v0.1.4

func (im IBCModule) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error

OnChanCloseInit implements the IBCModule interface.

func (IBCModule) OnChanOpenAck added in v0.1.4

func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyChannelID string, counterpartyVersion string) error

OnChanOpenAck implements the IBCModule interface.

func (IBCModule) OnChanOpenConfirm added in v0.1.4

func (im IBCModule) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error

OnChanOpenConfirm implements the IBCModule interface.

func (IBCModule) OnChanOpenInit added in v0.1.4

func (im IBCModule) OnChanOpenInit(
	ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string,
	channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string,
) (string, error)

OnChanOpenInit implements the IBCModule interface.

func (IBCModule) OnChanOpenTry added in v0.1.4

func (im IBCModule) OnChanOpenTry(
	ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string,
	channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string,
) (version string, err error)

OnChanOpenTry implements the IBCModule interface.

func (IBCModule) OnRecvPacket added in v0.1.4

func (im IBCModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement

OnRecvPacket implements the IBCModule interface.

func (IBCModule) OnTimeoutPacket added in v0.1.4

func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error

OnTimeoutPacket implements the IBCModule interface.

type KeyPath added in v0.1.4

type KeyPath struct{}

KeyPath defines a placeholder struct which implements the exported.Path interface

func (KeyPath) Empty added in v0.1.4

func (KeyPath) Empty() bool

Empty implements the exported.Path interface

func (KeyPath) String added in v0.1.4

func (KeyPath) String() string

String implements the exported.Path interface

type PV

type PV struct {
	PrivKey cryptotypes.PrivKey
}

MockPV implements PrivValidator without any safety or persistence. Only use it for testing.

func NewPV

func NewPV() PV

func (PV) GetPubKey

func (pv PV) GetPubKey() (crypto.PubKey, error)

GetPubKey implements PrivValidator interface

func (PV) SignProposal

func (pv PV) SignProposal(chainID string, proposal *tmproto.Proposal) error

SignProposal implements PrivValidator interface

func (PV) SignVote

func (pv PV) SignVote(chainID string, vote *tmproto.Vote) error

SignVote implements PrivValidator interface

type PortKeeper

type PortKeeper interface {
	BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
	IsBound(ctx sdk.Context, portID string) bool
}

Expected Interface PortKeeper defines the expected IBC port keeper

Jump to

Keyboard shortcuts

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