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

nits: more ics29 nits #741

Merged
merged 8 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions modules/apps/29-fee/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (im IBCModule) OnChanOpenInit(
}

// OnChanOpenTry implements the IBCModule interface
// If the channel is not fee enabled the underlying application version will be returned
// If the channel is fee enabled we merge the underlying application version with the ics29 version
func (im IBCModule) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
Expand Down Expand Up @@ -86,11 +88,11 @@ func (im IBCModule) OnChanOpenTry(
return "", err
}

if im.keeper.IsFeeEnabled(ctx, portID, channelID) {
return channeltypes.MergeChannelVersions(types.Version, appVersion), nil
if !im.keeper.IsFeeEnabled(ctx, portID, channelID) {
return appVersion, nil
}

return appVersion, nil
return channeltypes.MergeChannelVersions(types.Version, appVersion), nil
}

// OnChanOpenAck implements the IBCModule interface
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP

hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc)
if hasRefundAcc == nil {
return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc))
return sdkerrors.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", refundAcc)
}

coins := identifiedFee.Fee.RecvFee
Expand Down Expand Up @@ -122,6 +122,7 @@ func (k Keeper) RefundFeesOnChannel(ctx sdk.Context, portID, channelID string) e
refundErr = err
return true
}

err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, refundAccAddr, identifiedFee.Fee.AckFee)
if err != nil {
refundErr = err
Expand Down
13 changes: 8 additions & 5 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"strings"

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

Expand Down Expand Up @@ -28,7 +30,7 @@ func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error {
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress")
}

if msg.CounterpartyAddress == "" {
if strings.TrimSpace(msg.CounterpartyAddress) == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Worth adding an additional test case with a whitespaced empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return ErrCounterpartyAddressEmpty
}

Expand Down Expand Up @@ -82,12 +84,12 @@ func (msg MsgPayPacketFee) ValidateBasic() error {

// if any of the fee's are invalid return an error
if !msg.Fee.AckFee.IsValid() || !msg.Fee.RecvFee.IsValid() || !msg.Fee.TimeoutFee.IsValid() {
return sdkerrors.ErrInvalidCoins
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "contains one or more invalid fees")
}

// if all three fee's are zero or empty return an error
if msg.Fee.AckFee.IsZero() && msg.Fee.RecvFee.IsZero() && msg.Fee.TimeoutFee.IsZero() {
return sdkerrors.ErrInvalidCoins
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "contains one or more invalid fees")
}

return nil
Expand Down Expand Up @@ -119,7 +121,7 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error {

err = msg.IdentifiedPacketFee.Validate()
if err != nil {
return sdkerrors.Wrap(err, "Invalid IdentifiedPacketFee")
return sdkerrors.Wrap(err, "invalid IdentifiedPacketFee")
}

return nil
Expand All @@ -144,11 +146,12 @@ func NewIdentifiedPacketFee(packetId channeltypes.PacketId, fee Fee, refundAddr
}
}

// Validate performs a stateless check of the IdentifiedPacketFee fields
func (fee IdentifiedPacketFee) Validate() error {
// validate PacketId
err := fee.PacketId.Validate()
if err != nil {
return sdkerrors.Wrap(err, "Invalid PacketId")
return sdkerrors.Wrap(err, "invalid PacketId")
}

_, err = sdk.AccAddressFromBech32(fee.RefundAddress)
Expand Down
1 change: 1 addition & 0 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) {
{"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true},
{"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false},
{"invalid counterparty address", NewMsgRegisterCounterpartyAddress(validAddr, ""), false},
{"invalid counterparty address: whitespaced empty string", NewMsgRegisterCounterpartyAddress(validAddr, " "), false},
}

for i, tc := range testCases {
Expand Down