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

ICS 29: Fee Middleware #276

Merged
merged 87 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
18feadf
scaffolding for 29-fee (#274)
colin-axner Jul 21, 2021
4b9a832
feat: adding proto files for fee payment middleware (#272)
seantking Jul 26, 2021
158a251
fix: removing unncessary fields MsgEscrow & adding query params (#300)
seantking Jul 27, 2021
c63af4a
Merge branch 'main' into ics29-fee-middleware
colin-axner Aug 12, 2021
e3704c6
feat: #258 Register Counterparty Address (#376)
seantking Sep 8, 2021
70c58af
fix: remove comments for imports (#385)
seantking Sep 9, 2021
dd4f8c7
feat: Add handshake logic to ics29 (#307)
AdityaSripal Sep 27, 2021
67bd594
Fee Middleware: Escrow logic (#465)
seantking Nov 5, 2021
405f193
feat: update protos, grpc queries (#488)
charleenfei Nov 10, 2021
8ebbe18
store refund address in IdentifiedPacketFee (#546)
AdityaSripal Nov 18, 2021
d419972
29-Fee: Genesis (#557)
seantking Nov 24, 2021
4dbc83e
feat: adding genesis validation + tests (#561)
seantking Nov 24, 2021
c4dff6c
feat: add incentivised ack proto (#564)
charleenfei Nov 29, 2021
edd11c6
Fee Closing Handshake (#551)
AdityaSripal Nov 29, 2021
885fb9a
Fee Middleware: Add ICS4 wrapper (#562)
seantking Dec 1, 2021
a737132
feat: ics 29 packet callbacks (#357)
charleenfei Dec 21, 2021
53b2f67
Merge branch 'main' of github.com:cosmos/ibc-go into ics29-fee-middle…
colin-axner Jan 12, 2022
e0cc81a
update imports to v3
colin-axner Jan 12, 2022
120fd76
regenerate proto files
colin-axner Jan 12, 2022
0fbc6bb
fix build
colin-axner Jan 12, 2022
dbda885
update ics29 to tip of main (#716)
colin-axner Jan 12, 2022
9285133
fix: event caching for fee distribution (#661)
charleenfei Jan 12, 2022
f3e9f95
ics4 callbacks fee middleware (#580)
seantking Jan 12, 2022
26731ce
chore: making PacketId non nullable (#737)
seantking Jan 18, 2022
764df84
nits: proto spacing + naming (#739)
seantking Jan 20, 2022
d761982
sean/fix-proto-identified-fee-not-null (#746)
seantking Jan 20, 2022
f552fb2
nits: more ics29 nits (#741)
seantking Jan 20, 2022
16e452b
nit: update err syntax (#747)
seantking Jan 20, 2022
b16353e
feat: adding Route, Type, GetSignBytes for all messages (#743)
seantking Jan 21, 2022
b618f02
hygiene: add validate fn for Fee (#748)
seantking Jan 21, 2022
13f77de
fix: app.go (#789)
seantking Jan 26, 2022
6cb4a38
refactor: ics29 json encoded version metadata (#883)
damiannolan Feb 9, 2022
e0161a7
Merge branch 'main' of github.com:cosmos/ibc-go into ics29-fee-middle…
colin-axner Feb 10, 2022
dedbb57
chore: bump ics29 to tip of main (#900)
colin-axner Feb 10, 2022
6f19978
fix: return nil on OnRecvPacket for async pay (#911)
seantking Feb 15, 2022
ea2984b
nit: ics29 comments (#910)
seantking Feb 15, 2022
323c574
Merge branch 'main' into ics29-fee-middleware
colin-axner Feb 15, 2022
fb243c6
chore: Add transfer test for ics29 (#901)
colin-axner Feb 16, 2022
8d226de
refactor: ics29 OnChanOpenInit callback tests now use mock module (#924)
colin-axner Feb 16, 2022
2c1ff0b
feat: allow multiple addrs to incentivize packets (#915)
damiannolan Feb 16, 2022
39ef8d7
chore: remove spec directory from ics29 (#934)
colin-axner Feb 17, 2022
1fb4b5a
refactor: use mock module for ics29 closing handshakes (#926)
colin-axner Feb 17, 2022
9895948
refactor: use mock module for ics29 grpc_query_test.go (#933)
colin-axner Feb 17, 2022
acc699d
refactor: readjust keeper_test.go to use mock module (#930)
colin-axner Feb 17, 2022
9b2d96d
fix: fields for genesis should be non nullable (#938)
seantking Feb 17, 2022
06f2730
refactor: use mock module for ics29 escrow_test.go (#932)
colin-axner Feb 17, 2022
ff15335
refactor: use mock module for ics29 genesis_test.go (#931)
colin-axner Feb 17, 2022
d8b9821
ics29:feat: emit event escrow (#914)
seantking Feb 17, 2022
adc66d2
refactor: OnRecvPacket to use mock module (#927)
colin-axner Feb 18, 2022
4326c14
refactor: ics29 OnChanOpenTry/Ack use mock module for testing instead…
colin-axner Feb 18, 2022
ad7827f
refactor: use mock module for OnAcknowledgePacket callback testing (#…
colin-axner Feb 21, 2022
7c6076f
refactor: OnTimeoutPacket to use mock module (#928)
colin-axner Feb 21, 2022
179c4f4
chore: add packet id arg to EscrowPacketFee (#951)
damiannolan Feb 21, 2022
c14d2b4
chore: remove legacy testing functions (#954)
colin-axner Feb 21, 2022
99db143
fix:ics29: WriteAck update + adding success bool to IncentivizedAck (…
seantking Feb 21, 2022
74afccd
chore: add cli cmd to incentivize existing packet (async) (#965)
colin-axner Feb 22, 2022
6928af7
ics29:fix: counterparty addr must contain channelID (#937)
seantking Feb 22, 2022
6999e10
chore: fix err msg (#971)
colin-axner Feb 22, 2022
4fb6d18
ics29:fix: store source address for query later on WriteAck (#912)
seantking Feb 23, 2022
b02d193
refactor: make fee storage more efficient (#956)
damiannolan Feb 23, 2022
15fa37b
chore: update ics29 genesis state to support multiple packet fees (#957)
damiannolan Feb 23, 2022
9350d53
chore: update MsgPayPacketFeeAsync fields (#979)
damiannolan Feb 24, 2022
f1ba06f
chore: add ParseKeyFeesInEscrow helper function (#998)
colin-axner Feb 24, 2022
fcea26d
chore: update grpc queries to handle multiple fees (#967)
damiannolan Feb 24, 2022
9c508d2
feat: CLI cmd for MsgRegisterCounterpartyAddress (#987)
seantking Feb 24, 2022
7991f79
fix: ics29: switch source with destintion for chan/port IDs (#961)
seantking Feb 25, 2022
9ece5da
test: cleanup 29-fee/types tests (#1006)
damiannolan Feb 25, 2022
f8b4345
feat: grpc query total recv packet fees (#1015)
damiannolan Mar 1, 2022
e51e2c9
chore: switch code ordering (#1025)
colin-axner Mar 1, 2022
5f8fc9f
feat: Add ParseKeyFeeEnabled and rename FeeEnabledKey -> KeyFeeEnable…
colin-axner Mar 1, 2022
4623772
feat: ics29 cli for query total recv fees (#1035)
damiannolan Mar 1, 2022
8d380ba
feat: grpc query total ack fees (#1032)
damiannolan Mar 1, 2022
9137084
feat: grpc query total timeout fees (#1033)
damiannolan Mar 2, 2022
d788adf
feat: adding clis for total ack and timeout queries (#1043)
damiannolan Mar 2, 2022
478db4f
add ParseKeyForwardRelayerAddress function + test (#1046)
charleenfei Mar 2, 2022
71167c4
chore: remove unused ics29 keeper funcs (#1044)
damiannolan Mar 3, 2022
4bf859a
chore: add gRPC for querying incentivized packets for a specific chan…
colin-axner Mar 3, 2022
b33b0a7
add function EscrowAccountHasBalance (#1042)
colin-axner Mar 3, 2022
f3ee8de
feat: ParseKeyCounterpartyRelayer function (#1047)
charleenfei Mar 3, 2022
db88c84
chore: adding queries to cmd builder (#1057)
damiannolan Mar 3, 2022
637652d
chore: update ics29 protodocs (#1055)
damiannolan Mar 4, 2022
4a0e00c
Merge branch 'main' into ics29-fee-middleware
crodriguezvega Mar 22, 2022
ab90f07
add counter party channel ID to argument list of on channel open ack …
crodriguezvega Mar 22, 2022
3ab2251
ADR 004: Fee module locking in the presence of severe bugs (#1060)
colin-axner Mar 29, 2022
e1cca36
nit: packetID var name (#1214)
seantking Apr 5, 2022
e65e881
Merge branch 'main' into ics29-fee-middleware
crodriguezvega Apr 6, 2022
39d4c56
ics29: update with changes from main (#1221)
seantking Apr 6, 2022
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
Prev Previous commit
Next Next commit
feat: #258 Register Counterparty Address (#376)
* feat: adding MsgServer for RegisterCounterPartyAddress &
EscrowPacketFree

* test: adding test for ValidateBasic

* fix: removing validate basic check

* fix: removing empty file

* Update modules/apps/29-fee/keeper/msg_server.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* Update modules/apps/29-fee/types/msgs.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* Update modules/apps/29-fee/types/keys.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* Update modules/apps/29-fee/keeper/keeper.go

Co-authored-by: Aditya <adityasripal@gmail.com>

* fix: fixing typos, variable names, comments

* fix: updating import comments

* test: adding test for KeyRelayerAddress

* update: comments & key_test

* Update modules/apps/29-fee/keeper/msg_server.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* fix: error message

* docs: updating RegisterCounterpartyAddress fn description

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Aditya <adityasripal@gmail.com>
  • Loading branch information
3 people authored Sep 8, 2021
commit e3704c683eb171a4c74658af631a1b7a6d035c4d
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
4 changes: 2 additions & 2 deletions modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cli

import (
"github.com/spf13/cobra"

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

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

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

// external library imports
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
"github.com/tendermint/tendermint/libs/log"

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

Expand All @@ -25,7 +25,6 @@ type Keeper struct {
scopedKeeper capabilitykeeper.ScopedKeeper
}


// NewKeeper creates a new 29-fee Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
Expand All @@ -49,6 +48,7 @@ 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 @@ -62,12 +62,6 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}

// 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))
}

// 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)
Expand All @@ -85,3 +79,22 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}
*/

// 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: 3 additions & 14 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package keeper_test

/*
import (
// standard library importsn
"testing"

// external library imports
"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"
// ibc-go imports
ibctesting "github.com/cosmos/ibc-go/testing"
)

Expand All @@ -31,15 +29,6 @@ func (suite *KeeperTestSuite) SetupTest() {
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like a global API, as I do not see the channelEnd being specified anywhere. But in a multi-chain setting, a relayer usually use the same wallet to relay from multiple chains. We cannot use the same counterparty address address for all channels that are relayed by the same relayer wallet, as the relayer's counterparty address for each chain is different.

ctx := sdk.UnwrapSDKContext(goCtx)

k.SetCounterpartyAddress(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to validate that msg.Address is a valid address for the local chain.

On the other hand, we cannot really validate msg.CounterpartyAddress, as the counterparty address format may be different on a counterparty chain. However we may want to place some limitation on the format and length of the counterparty address to prevent potential attacks. The counterparty address can also potentially be used for XSS attack if its value is used by clients to display it on some UI, or in logs such as the line following this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to validate that msg.Address is a valid address for the local chain.

This will already be checked during antehandler, since address must sign message.

Do you have suggestions on Counterparty address validation?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do basic validation with an acceptable address format for the majority of blockchains that exist today. Something like \w{1,100} should work, unless there are exotic addresses that include special characters like -, _, :, , \n, etc.

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

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

// ibc-go imports
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 +49,3 @@ type ConnectionKeeper interface {
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
}
*/
14 changes: 14 additions & 0 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package types

// standard library imports
import "fmt"

const (
// ModuleName defines the 29-fee name
ModuleName = "ibcfee"

// 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

// QuerierRoute is the querier route for IBC transfer
QuerierRoute = ModuleName

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

// 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))
}
38 changes: 25 additions & 13 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package types

/*
import (
"strings"

// external library imports
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/modules/core/24-host"
)

// NewMsg
func NewMsg() *Msg {
return &Msg{
// msg types
const (
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress"
)

// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress
func NewMsgRegisterCounterpartyAddress(address, counterpartyAddress string) *MsgRegisterCounterpartyAddress {
return &MsgRegisterCounterpartyAddress{
Address: address,
CounterpartyAddress: counterpartyAddress,
}
}

// ValidateBasic performs a basic check of the Msg fields.
func (msg Msg) ValidateBasic() error {
// ValidateBasic performs a basic check of the MsgRegisterCounterpartyAddress fields
func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress")
}

_, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress)
if err != nil {
return sdkerrors.Wrap(err, "failed to convert msg.CounterpartyAddress into sdk.AccAddress")
}

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgTransfer) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Sender)
func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
*/
38 changes: 19 additions & 19 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package types

/*
import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/secp256k1"
)

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
var (
validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
invalidAddr = "invalid_address"
)

func (suite *TypesTestSuite) TestMsgValidateBasic() {
// TestMsgTransferValidation tests ValidateBasic for MsgTransfer
func TestMsgRegisterCountepartyAddressValidation(t *testing.T) {
testCases := []struct {
name string
msg *types.Msg
msg *MsgRegisterCounterpartyAddress
expPass bool
}{
{"", types.NewMsg(), true},
{"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true},
{"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false},
{"validate with incorrect counterparty relayer address", NewMsgRegisterCounterpartyAddress(validAddr, invalidAddr), false},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
err := tc.msg.ValidateBasic()
if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
for i, tc := range testCases {
err := tc.msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name)
} else {
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name)
}
}
}
*/
Loading