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

ics29:fix: update genesis type #913

Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 19 additions & 2 deletions modules/apps/29-fee/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package types

import (
"strings"

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

host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
)

// NewGenesisState creates a 29-fee GenesisState instance.
func NewGenesisState(identifiedFees []IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState {
func NewGenesisState(identifiedFees []IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress, forwardRelayers []*ForwardRelayerAddress) *GenesisState {
return &GenesisState{
IdentifiedFees: identifiedFees,
FeeEnabledChannels: feeEnabledChannels,
RegisteredRelayers: registeredRelayers,
ForwardRelayers: forwardRelayers,
}
}

Expand All @@ -22,6 +25,7 @@ func DefaultGenesisState() *GenesisState {
IdentifiedFees: []IdentifiedPacketFee{},
FeeEnabledChannels: []*FeeEnabledChannel{},
RegisteredRelayers: []*RegisteredRelayerAddress{},
ForwardRelayers: []*ForwardRelayerAddress{},
}
}

Expand Down Expand Up @@ -53,10 +57,23 @@ func (gs GenesisState) Validate() error {
return sdkerrors.Wrap(err, "failed to convert source relayer address into sdk.AccAddress")
}

if rel.CounterpartyAddress == "" {
if strings.TrimSpace(rel.CounterpartyAddress) == "" {
return ErrCounterpartyAddressEmpty
}
}

// Validate ForwardRelayers
for _, rel := range gs.ForwardRelayers {
_, err := sdk.AccAddressFromBech32(rel.Address)
if err != nil {
return sdkerrors.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress")
}
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

err = rel.PacketId.Validate()
if err != nil {
return err
}
}
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
40 changes: 32 additions & 8 deletions modules/apps/29-fee/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ var (

func TestValidateGenesis(t *testing.T) {
var (
packetId channeltypes.PacketId
fee types.Fee
refundAcc string
sender string
counterparty string
portID string
channelID string
seq uint64
packetId channeltypes.PacketId
fee types.Fee
refundAcc string
sender string
forwardAddr string
counterparty string
portID string
channelID string
packetChannelID string
seq uint64
)

testCases := []struct {
Expand Down Expand Up @@ -122,11 +124,26 @@ func TestValidateGenesis(t *testing.T) {
},
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
false,
},
{
"invalid ForwardRelayerAddress: invalid forwardAddr",
func() {
forwardAddr = ""
},
false,
},
{
"invalid ForwardRelayerAddress: invalid packet",
func() {
packetChannelID = "1"
},
false,
},
}

for _, tc := range testCases {
portID = transfertypes.PortID
channelID = ibctesting.FirstChannelID
packetChannelID = ibctesting.FirstChannelID
seq = uint64(1)

// build PacketId & Fee
Expand All @@ -146,6 +163,7 @@ func TestValidateGenesis(t *testing.T) {
// relayer addresses
sender = addr1
counterparty = addr2
forwardAddr = addr2

tc.malleate()

Expand All @@ -170,6 +188,12 @@ func TestValidateGenesis(t *testing.T) {
CounterpartyAddress: counterparty,
},
},
ForwardRelayers: []*types.ForwardRelayerAddress{
{
Address: forwardAddr,
PacketId: channeltypes.NewPacketId(packetChannelID, portID, 1),
},
},
}

err := genState.Validate()
Expand Down