mock

package
v0.0.0-...-1ab191f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 35 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"
)
View Source
const ExtensionTypeURL = "/mock.Extension"

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"
)
View Source
var (
	ErrInvalidLengthMockExtension        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowMockExtension          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupMockExtension = fmt.Errorf("proto: unexpected end of group")
)

Functions

func GetMockAckCanaryCapabilityName

func GetMockAckCanaryCapabilityName(packet channeltypes.Packet) string

GetMockAckCanaryCapabilityName generates a capability name for OnAcknowledgementPacket functionality.

func GetMockRecvCanaryCapabilityName

func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string

GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality.

func GetMockTimeoutCanaryCapabilityName

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 ClassMetadata

type ClassMetadata struct {
	Creator          string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"`
	Schema           string `protobuf:"bytes,2,opt,name=schema,proto3" json:"schema,omitempty"`
	MintRestricted   bool   `protobuf:"varint,3,opt,name=mint_restricted,json=mintRestricted,proto3" json:"mint_restricted,omitempty"`
	UpdateRestricted bool   `protobuf:"varint,4,opt,name=update_restricted,json=updateRestricted,proto3" json:"update_restricted,omitempty"`
	Data             string `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
}

ClassMetadata defines a struct for the class metadata

func (*ClassMetadata) Descriptor

func (*ClassMetadata) Descriptor() ([]byte, []int)

func (*ClassMetadata) Equal

func (this *ClassMetadata) Equal(that interface{}) bool

func (*ClassMetadata) GetCreator

func (m *ClassMetadata) GetCreator() string

func (*ClassMetadata) GetData

func (m *ClassMetadata) GetData() string

func (*ClassMetadata) GetMintRestricted

func (m *ClassMetadata) GetMintRestricted() bool

func (*ClassMetadata) GetSchema

func (m *ClassMetadata) GetSchema() string

func (*ClassMetadata) GetUpdateRestricted

func (m *ClassMetadata) GetUpdateRestricted() bool

func (*ClassMetadata) Marshal

func (m *ClassMetadata) Marshal() (dAtA []byte, err error)

func (*ClassMetadata) MarshalTo

func (m *ClassMetadata) MarshalTo(dAtA []byte) (int, error)

func (*ClassMetadata) MarshalToSizedBuffer

func (m *ClassMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*ClassMetadata) ProtoMessage

func (*ClassMetadata) ProtoMessage()

func (*ClassMetadata) Reset

func (m *ClassMetadata) Reset()

func (*ClassMetadata) Size

func (m *ClassMetadata) Size() (n int)

func (*ClassMetadata) String

func (m *ClassMetadata) String() string

func (*ClassMetadata) Unmarshal

func (m *ClassMetadata) Unmarshal(dAtA []byte) error

func (*ClassMetadata) XXX_DiscardUnknown

func (m *ClassMetadata) XXX_DiscardUnknown()

func (*ClassMetadata) XXX_Marshal

func (m *ClassMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ClassMetadata) XXX_Merge

func (m *ClassMetadata) XXX_Merge(src proto.Message)

func (*ClassMetadata) XXX_Size

func (m *ClassMetadata) XXX_Size() int

func (*ClassMetadata) XXX_Unmarshal

func (m *ClassMetadata) XXX_Unmarshal(b []byte) error

type ClassMetadataResolver

type ClassMetadataResolver interface {
	MarshalClassMetadata(any *codectypes.Any) (string, error)
	UnmarshalClassMetadata(bz string) (*codectypes.Any, error)
}

type EmptyAcknowledgement

type EmptyAcknowledgement struct {
	Response []byte
}

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

func NewEmptyAcknowledgement

func NewEmptyAcknowledgement() EmptyAcknowledgement

NewEmptyAcknowledgement returns a new instance of EmptyAcknowledgement

func (EmptyAcknowledgement) Acknowledgement

func (ack EmptyAcknowledgement) Acknowledgement() []byte

Acknowledgement implements the Acknowledgement interface

func (EmptyAcknowledgement) Success

func (ack EmptyAcknowledgement) Success() bool

Success implements the Acknowledgement interface

type Extension

type Extension struct {
	Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
}

Extension defines a data structure for storing data types that the system cannot recognize

func (*Extension) Descriptor

func (*Extension) Descriptor() ([]byte, []int)

func (*Extension) Equal

func (this *Extension) Equal(that interface{}) bool

func (*Extension) GetData

func (m *Extension) GetData() string

func (*Extension) Marshal

func (m *Extension) Marshal() (dAtA []byte, err error)

func (*Extension) MarshalTo

func (m *Extension) MarshalTo(dAtA []byte) (int, error)

func (*Extension) MarshalToSizedBuffer

func (m *Extension) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Extension) ProtoMessage

func (*Extension) ProtoMessage()

func (*Extension) Reset

func (m *Extension) Reset()

func (*Extension) Size

func (m *Extension) Size() (n int)

func (*Extension) String

func (m *Extension) String() string

func (*Extension) Unmarshal

func (m *Extension) Unmarshal(dAtA []byte) error

func (*Extension) XXX_DiscardUnknown

func (m *Extension) XXX_DiscardUnknown()

func (*Extension) XXX_Marshal

func (m *Extension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Extension) XXX_Merge

func (m *Extension) XXX_Merge(src proto.Message)

func (*Extension) XXX_Size

func (m *Extension) XXX_Size() int

func (*Extension) XXX_Unmarshal

func (m *Extension) XXX_Unmarshal(b []byte) error

type IBCApp

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

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

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

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

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

func (IBCModule) OnAcknowledgementPacket

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

OnAcknowledgementPacket implements the IBCModule interface.

func (IBCModule) OnChanCloseConfirm

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

OnChanCloseConfirm implements the IBCModule interface.

func (IBCModule) OnChanCloseInit

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

OnChanCloseInit implements the IBCModule interface.

func (IBCModule) OnChanOpenAck

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

OnChanOpenAck implements the IBCModule interface.

func (IBCModule) OnChanOpenConfirm

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

OnChanOpenConfirm implements the IBCModule interface.

func (IBCModule) OnChanOpenInit

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

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

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

OnRecvPacket implements the IBCModule interface.

func (IBCModule) OnTimeoutPacket

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

OnTimeoutPacket implements the IBCModule interface.

type MockNFTKeeper

type MockNFTKeeper struct {
	// contains filtered or unexported fields
}

func Wrap

func (MockNFTKeeper) Burn

func (w MockNFTKeeper) Burn(ctx sdk.Context, classID string, tokenID string) error

func (MockNFTKeeper) CreateOrUpdateClass

func (w MockNFTKeeper) CreateOrUpdateClass(ctx sdk.Context,
	classID,
	classURI,
	classData string,
) error

func (MockNFTKeeper) GetClass

func (w MockNFTKeeper) GetClass(ctx sdk.Context, classID string) (nfttransfer.Class, bool)

func (MockNFTKeeper) GetNFT

func (w MockNFTKeeper) GetNFT(ctx sdk.Context, classID, tokenID string) (nfttransfer.NFT, bool)

func (MockNFTKeeper) GetOwner

func (w MockNFTKeeper) GetOwner(ctx sdk.Context, classID string, tokenID string) sdk.AccAddress

func (MockNFTKeeper) HasClass

func (w MockNFTKeeper) HasClass(ctx sdk.Context, classID string) bool

func (MockNFTKeeper) MarshalClassMetadata

func (w MockNFTKeeper) MarshalClassMetadata(any *codectypes.Any) (string, error)

MarshalClassMetadata is responsible for serializing ClassMetadata

func (MockNFTKeeper) MarshalTokenMetadata

func (w MockNFTKeeper) MarshalTokenMetadata(any *codectypes.Any) (string, error)

MarshalTokenMetadata is responsible for serializing tokendata

func (MockNFTKeeper) Mint

func (w MockNFTKeeper) Mint(ctx sdk.Context,
	classID,
	tokenID,
	tokenURI,
	tokenData string,
	receiver sdk.AccAddress,
) error

func (MockNFTKeeper) Transfer

func (w MockNFTKeeper) Transfer(ctx sdk.Context,
	classID,
	tokenID string,
	tokenData string,
	receiver sdk.AccAddress,
) error

func (MockNFTKeeper) UnmarshalClassMetadata

func (w MockNFTKeeper) UnmarshalClassMetadata(data string) (*codectypes.Any, error)

UnmarshalClassMetadata is responsible for deserializing Metadata. Notice: If it is an unregistered type in this system, this method will save the original data in the `Extension` type, which is compatible with the definition of other chain Metadata types.

func (MockNFTKeeper) UnmarshalTokenMetadata

func (w MockNFTKeeper) UnmarshalTokenMetadata(data string) (*codectypes.Any, error)

Unmarshal is responsible for deserializing tokendata. Notice: If it is an unregistered type in this system, this method will save the original data in the `UnknownTokenData` type, which is compatible with the definition of other chain Tokendata types.

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

type TokenMetadata

type TokenMetadata struct {
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}

TokenMetadata defines a struct for the nft metadata

func (*TokenMetadata) Descriptor

func (*TokenMetadata) Descriptor() ([]byte, []int)

func (*TokenMetadata) Equal

func (this *TokenMetadata) Equal(that interface{}) bool

func (*TokenMetadata) GetData

func (m *TokenMetadata) GetData() string

func (*TokenMetadata) GetName

func (m *TokenMetadata) GetName() string

func (*TokenMetadata) Marshal

func (m *TokenMetadata) Marshal() (dAtA []byte, err error)

func (*TokenMetadata) MarshalTo

func (m *TokenMetadata) MarshalTo(dAtA []byte) (int, error)

func (*TokenMetadata) MarshalToSizedBuffer

func (m *TokenMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*TokenMetadata) ProtoMessage

func (*TokenMetadata) ProtoMessage()

func (*TokenMetadata) Reset

func (m *TokenMetadata) Reset()

func (*TokenMetadata) Size

func (m *TokenMetadata) Size() (n int)

func (*TokenMetadata) String

func (m *TokenMetadata) String() string

func (*TokenMetadata) Unmarshal

func (m *TokenMetadata) Unmarshal(dAtA []byte) error

func (*TokenMetadata) XXX_DiscardUnknown

func (m *TokenMetadata) XXX_DiscardUnknown()

func (*TokenMetadata) XXX_Marshal

func (m *TokenMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TokenMetadata) XXX_Merge

func (m *TokenMetadata) XXX_Merge(src proto.Message)

func (*TokenMetadata) XXX_Size

func (m *TokenMetadata) XXX_Size() int

func (*TokenMetadata) XXX_Unmarshal

func (m *TokenMetadata) XXX_Unmarshal(b []byte) error

type TokenMetadataResolver

type TokenMetadataResolver interface {
	MarshalTokenMetadata(any *codectypes.Any) (string, error)
	UnmarshalTokenMetadata(bz string) (*codectypes.Any, error)
}

type WrappedClass

type WrappedClass struct {
	nft.Class
	// contains filtered or unexported fields
}

func (WrappedClass) GetData

func (wc WrappedClass) GetData() string

func (WrappedClass) GetID

func (wc WrappedClass) GetID() string

func (WrappedClass) GetURI

func (wc WrappedClass) GetURI() string

type WrappedNFT

type WrappedNFT struct {
	nft.NFT
	// contains filtered or unexported fields
}

func (WrappedNFT) GetClassID

func (wc WrappedNFT) GetClassID() string

func (WrappedNFT) GetData

func (wc WrappedNFT) GetData() string

func (WrappedNFT) GetID

func (wc WrappedNFT) GetID() string

func (WrappedNFT) GetURI

func (wc WrappedNFT) GetURI() string

Jump to

Keyboard shortcuts

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