Skip to content

Commit

Permalink
test: adding msg_server.go tests & codec wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Sep 10, 2021
1 parent 2ea94e6 commit e90d0e1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 25 deletions.
22 changes: 8 additions & 14 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
host "github.com/cosmos/ibc-go/modules/core/24-host"
)

Expand Down Expand Up @@ -46,7 +47,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName)
}

/*
// IsBound checks if the transfer module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
Expand All @@ -60,23 +60,17 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, host.PortPath(portID))
}

// SetPort sets the portID for the transfer module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
// GetPort returns the portID for the transfer module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
store.Set(types.PortKey, []byte(portID))
}
// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
return k.scopedKeeper.AuthenticateCapability(ctx, cap, name)
return string(store.Get(transfertypes.PortKey))
}

// ClaimCapability allows the transfer module that can claim a capability that IBC module
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
// SetPort sets the portID for the transfer module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
store := ctx.KVStore(k.storeKey)
store.Set(transfertypes.PortKey, []byte(portID))
}
*/

// SetCounterpartyAddress maps the destination chain relayer address to the source relayer address
// The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ type KeeperTestSuite struct {
}

func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3)
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2))
}

func TestKeeperTestSuite(t *testing.T) {
Expand Down
32 changes: 32 additions & 0 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper_test

import (
"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
)

func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() {
validAddr := suite.chainA.SenderAccount.GetAddress().String()
validAddr2 := suite.chainB.SenderAccount.GetAddress().String()

testCases := []struct {
msg *types.MsgRegisterCounterpartyAddress
expPass bool
}{
{
types.NewMsgRegisterCounterpartyAddress(validAddr, validAddr2),
true,
},
}

for _, tc := range testCases {
suite.SetupTest()
_, err := suite.chainA.SendMsgs(tc.msg)

if tc.expPass {
suite.Require().NoError(err) // message committed
} else {
suite.Require().Error(err)
}

}
}
4 changes: 2 additions & 2 deletions modules/apps/29-fee/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}

// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// types.RegisterInterfaces(registry)
types.RegisterInterfaces(registry)
}

// DefaultGenesis returns default genesis state as raw bytes for the ibc
Expand Down Expand Up @@ -129,7 +129,7 @@ func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
// types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
// types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}

Expand Down
34 changes: 30 additions & 4 deletions modules/apps/29-fee/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
package types

/*
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

// RegisterLegacyAminoCodec registers the necessary x/ibc 29-fee interfaces and concrete types
// on the provided LegacyAmino codec. These types are used for Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgRegisterCounterpartyAddress{}, "cosmos-sdk/MsgRegisterCounterpartyAddress", nil)
cdc.RegisterConcrete(&MsgEscrowPacketFee{}, "cosmos-sdk/MsgEscrowPacketFee", nil)
}

// RegisterInterfaces register the 29-fee module interfaces to protobuf
// Any.
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// registry.RegisterImplementations((*sdk.Msg)(nil), &Msg{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterCounterpartyAddress{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgEscrowPacketFee{})
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
*/

var (
amino = codec.NewLegacyAmino()

// ModuleCdc references the global x/ibc-transfer module codec. Note, the codec
// should ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc transfer and
// defined at the application level.
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())

// AminoCdc is a amino codec created to support amino json compatible msgs.
AminoCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
amino.Seal()
}
3 changes: 0 additions & 3 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const (
// StoreKey is the store key string for IBC transfer
StoreKey = ModuleName

// PortKey is the port id that is wrapped by fee middleware
PortKey = "feetransfer"

// RouterKey is the message route for IBC transfer
RouterKey = ModuleName

Expand Down
21 changes: 21 additions & 0 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
// msg types
const (
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress"
TypeMsgEscrowPacketFee = "escrowPacketFee"
)

// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress
Expand Down Expand Up @@ -41,3 +42,23 @@ func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{signer}
}

// NewMsgEscrowPacketFee creates a new instance of MsgEscrowPacketFee
func NewMsgEscrowPacketFee(incentivizedPacket *IdentifiedPacketFee, relayers []string) *MsgEscrowPacketFee {
return &MsgEscrowPacketFee{
IncentivizedPacket: incentivizedPacket,
Relayers: relayers,
}
}

// ValidateBasic performs a basic check of the MsgEscrowPacketFee fields
func (msg MsgEscrowPacketFee) ValidateBasic() error {
//TODO
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgEscrowPacketFee) GetSigners() []sdk.AccAddress {
//TODO
return []sdk.AccAddress{}
}

0 comments on commit e90d0e1

Please sign in to comment.