Skip to content

Commit

Permalink
fix: change non nil relayer check to non empty (backport cosmos#1774) (
Browse files Browse the repository at this point in the history
…cosmos#1790)

* fix: change non nil relayer check to non empty (cosmos#1774)

* change non nil relayer check to non empty

Change relayers != nil to len(relayers) != 0
Rename ErrRelayersNotNil to ErrRelayersNotEmpty
Add test cases

* add changelog entry

(cherry picked from commit 126ab2d)

# Conflicts:
#	CHANGELOG.md

* fix changelog conflicts

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
2 people authored and ulbqb committed Jul 31, 2023
1 parent 0b08666 commit 9f0aa16
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (apps/29-fee) [\#1774](https://github.com/cosmos/ibc-go/pull/1774) Change non nil relayer assertion to non empty to avoid import/export issues for genesis upgrades.
* (apps/29-fee) [\#1278](https://github.com/cosmos/ibc-go/pull/1278) The URI path for the query to get all incentivized packets for a specific channel did not follow the same format as the rest of queries.

## [v3.1.0](https://github.com/cosmos/ibc-go/releases/tag/v3.1.0) - 2022-04-16
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address")
ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address")
ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID")
ErrRelayersNotNil = sdkerrors.Register(ModuleName, 6, "relayers must be nil. This feature is not supported")
ErrRelayersNotEmpty = sdkerrors.Register(ModuleName, 6, "relayers must not be set. This feature is not supported")
ErrCounterpartyPayeeEmpty = sdkerrors.Register(ModuleName, 7, "counterparty payee must not be empty")
ErrForwardRelayerAddressNotFound = sdkerrors.Register(ModuleName, 8, "forward relayer address not found")
ErrFeeNotEnabled = sdkerrors.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled")
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/29-fee/types/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (p PacketFee) Validate() error {
return sdkerrors.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress")
}

// enforce relayer is nil
if p.Relayers != nil {
return ErrRelayersNotNil
// enforce relayers are not set
if len(p.Relayers) != 0 {
return ErrRelayersNotEmpty
}

if err := p.Fee.Validate(); err != nil {
Expand Down
18 changes: 16 additions & 2 deletions modules/apps/29-fee/types/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func TestPacketFeeValidation(t *testing.T) {
func() {},
true,
},
{
"success with empty slice for Relayers",
func() {
packetFee.Relayers = []string{}
},
true,
},
{
"should fail when refund address is invalid",
func() {
Expand Down Expand Up @@ -102,6 +109,13 @@ func TestPacketFeeValidation(t *testing.T) {
},
false,
},
{
"should fail with non empty Relayers",
func() {
packetFee.Relayers = []string{"relayer"}
},
false,
},
}

for _, tc := range testCases {
Expand All @@ -113,9 +127,9 @@ func TestPacketFeeValidation(t *testing.T) {
err := packetFee.Validate()

if tc.expPass {
require.NoError(t, err)
require.NoError(t, err, tc.name)
} else {
require.Error(t, err)
require.Error(t, err, tc.name)
}
}
}
6 changes: 3 additions & 3 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func (msg MsgPayPacketFee) ValidateBasic() error {
return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress")
}

// enforce relayer is nil
if msg.Relayers != nil {
return ErrRelayersNotNil
// enforce relayer is not set
if len(msg.Relayers) != 0 {
return ErrRelayersNotEmpty
}

if err := msg.Fee.Validate(); err != nil {
Expand Down
22 changes: 18 additions & 4 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ func TestMsgPayPacketFeeValidation(t *testing.T) {
func() {},
true,
},
{
"success with empty relayers",
func() {
msg.Relayers = []string{}
},
true,
},
{
"invalid channelID",
func() {
Expand Down Expand Up @@ -210,9 +217,9 @@ func TestMsgPayPacketFeeValidation(t *testing.T) {
err := msg.ValidateBasic()

if tc.expPass {
require.NoError(t, err)
require.NoError(t, err, tc.name)
} else {
require.Error(t, err)
require.Error(t, err, tc.name)
}
}
}
Expand Down Expand Up @@ -257,6 +264,13 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
func() {},
true,
},
{
"success with empty relayers",
func() {
msg.PacketFee.Relayers = []string{}
},
true,
},
{
"invalid channelID",
func() {
Expand Down Expand Up @@ -354,9 +368,9 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
err := msg.ValidateBasic()

if tc.expPass {
require.NoError(t, err)
require.NoError(t, err, tc.name)
} else {
require.Error(t, err)
require.Error(t, err, tc.name)
}
}
}
Expand Down

0 comments on commit 9f0aa16

Please sign in to comment.