Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding msg_server test for 29-fee #391

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
- [ibc/applications/fee/v1/tx.proto](#ibc/applications/fee/v1/tx.proto)
- [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee)
- [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse)
- [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse)
- [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress)
- [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse)

- [Msg](#ibc.applications.fee.v1.Msg)

Expand Down Expand Up @@ -915,16 +915,6 @@ MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee



<a name="ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse"></a>

### MsgRegisterCounterPartyAddressResponse
MsgRegisterCounterPartyAddressResponse defines the Msg/RegisterCounteryPartyAddress response type






<a name="ibc.applications.fee.v1.MsgRegisterCounterpartyAddress"></a>

### MsgRegisterCounterpartyAddress
Expand All @@ -940,6 +930,16 @@ MsgRegisterCounterpartyAddress is the request type for registering the counter p




<a name="ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse"></a>

### MsgRegisterCounterpartyAddressResponse
MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type





<!-- end messages -->

<!-- end enums -->
Expand All @@ -954,7 +954,7 @@ Msg defines the ibc/fee Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `RegisterCounterPartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
| `EscrowPacketFee` | [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) | [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) | EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of the given packet. | |

<!-- end services -->
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cli

import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

// GetQueryCmd returns the query commands for 29-fee
Expand Down
30 changes: 25 additions & 5 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package keeper

import (
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
"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 @@ -62,11 +63,30 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
// GetPort returns the portID for the transfer module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.PortKey))
return string(store.Get(transfertypes.PortKey))
}

// 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(types.PortKey, []byte(portID))
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
func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress))
}

// GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address
func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyRelayerAddress(address.String())

if !store.Has(key) {
return []byte{}, false
}

return store.Get(key), true
}
17 changes: 1 addition & 16 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package keeper_test

/*
import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/testing"
)

Expand All @@ -25,21 +20,11 @@ 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 NewFeePath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = ibctesting.FeePort
path.EndpointB.ChannelConfig.PortID = ibctesting.FeePort

return path
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
*/
33 changes: 31 additions & 2 deletions modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
package keeper

// TODO
//var _ types.MsgServer = Keeper{}
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

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

var _ types.MsgServer = Keeper{}

// RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying
// This ensures they will be properly compensated for forward relaying on the source chain since the destination chain must send back relayer's source address (counterparty address) in acknowledgement
// This function may be called more than once by relayers, in which case, the previous counterparty address will be overwritten by the new counterparty address
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

k.SetCounterpartyAddress(
ctx, msg.Address, msg.CounterpartyAddress,
)

k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress)

return &types.MsgRegisterCounterpartyAddressResponse{}, nil
}

// EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee
// EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to
// incentivize the relaying of the given packet.
func (k Keeper) EscrowPacketFee(goCtx context.Context, msg *types.MsgEscrowPacketFee) (*types.MsgEscrowPacketFeeResponse, error) {
return &types.MsgEscrowPacketFeeResponse{}, nil
}
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)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

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: 1 addition & 2 deletions modules/apps/29-fee/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package types

/*
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/modules/core/exported"
Expand Down Expand Up @@ -47,4 +47,3 @@ type ConnectionKeeper interface {
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
}
*/
8 changes: 8 additions & 0 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ const (
Version = "fee29-1"

KeyAppCapability = "app_capabilities"

// RelayerAddressKeyPrefix is the key prefix for relayer address mapping
RelayerAddressKeyPrefix = "relayerAddress"
)

func AppCapabilityName(portID, channelID string) string {
return fmt.Sprintf("%s/%s/%s", KeyAppCapability, channelID, portID)
}

// KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping
func KeyRelayerAddress(address string) []byte {
return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address))
}
19 changes: 19 additions & 0 deletions modules/apps/29-fee/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package types_test

import (
fmt "fmt"
"testing"

"github.com/stretchr/testify/require"

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

func TestKeyRelayerAddress(t *testing.T) {
var (
relayerAddress = "relayer_address"
)

key := types.KeyRelayerAddress(relayerAddress)
require.Equal(t, string(key), fmt.Sprintf("%s/relayer_address", types.RelayerAddressKeyPrefix))
}
Loading