From cc889d4aaac5dccaa861c6ec8b0426a4b0692e66 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 27 Jul 2023 14:03:47 +0200 Subject: [PATCH 01/10] feat(core/port): added PacketDataUnmarshaler interface --- modules/core/05-port/types/module.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 33465bf6f98..a8306f73064 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -138,3 +138,10 @@ type Middleware interface { IBCModule ICS4Wrapper } + +// PacketDataUnmarshaler defines an optional interface which allows a middleware to +// request the packet data to be unmarshaled by the base application. +type PacketDataUnmarshaler interface { + // UnmarshalPacketData unmarshals the packet data into a concrete type + UnmarshalPacketData([]byte) (interface{}, error) +} From 692c0944b57ec3df560bfd17761393cffc149a8f Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 27 Jul 2023 14:10:48 +0200 Subject: [PATCH 02/10] feat(transfer): implemented PacketDataUnmarshaler interface in transfer --- modules/apps/transfer/ibc_module.go | 17 +++++++ modules/apps/transfer/ibc_module_test.go | 60 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index 613315bacc3..29f76b3d19b 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -19,6 +19,11 @@ import ( ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) +var ( + _ porttypes.IBCModule = (*IBCModule)(nil) + _ porttypes.PacketDataUnmarshaler = (*IBCModule)(nil) +) + // IBCModule implements the ICS26 interface for transfer given the transfer keeper. type IBCModule struct { keeper keeper.Keeper @@ -301,3 +306,15 @@ func (im IBCModule) OnTimeoutPacket( return nil } + +// UnmarshalPacketData attempts to unmarshal the provided packet data bytes +// into a FungibleTokenPacketData. This function implements the optional +// PacketDataUnmarshaler interface required for ADR 008 support. +func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) { + var packetData types.FungibleTokenPacketData + if err := types.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil { + return nil, err + } + + return packetData, nil +} diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index deed17c37c6..866ffdfee95 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -1,8 +1,12 @@ package transfer_test import ( + "fmt" "math" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -238,3 +242,59 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() { }) } } + +func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { + var ( + sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + srcCallbackAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + destCallbackAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + denom = "transfer/channel-0/atom" + amount = "100" + + data []byte + expPacketData types.FungibleTokenPacketData + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success: both callbacks", + func() { + expPacketData = types.FungibleTokenPacketData{ + Denom: denom, + Amount: amount, + Sender: sender, + Receiver: receiver, + Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, srcCallbackAddr, destCallbackAddr), + } + data = expPacketData.GetBytes() + }, + true, + }, + { + "failure: invalid packet data", + func() { + data = []byte("invalid packet data") + }, + false, + }, + } + + for _, tc := range testCases { + tc.malleate() + + packetData, err := transfer.IBCModule{}.UnmarshalPacketData(data) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().Equal(expPacketData, packetData) + } else { + suite.Require().Error(err) + suite.Require().Nil(packetData) + } + } +} From 2e08e88b18373a13531c445f98ebabf6943c59bb Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 27 Jul 2023 14:14:56 +0200 Subject: [PATCH 03/10] feat(ica/controller): implemented PacketDataUnmarshaler interface --- .../controller/ibc_middleware.go | 17 +++++++++++++- .../controller/ibc_middleware_test.go | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 1338b3f252f..2c9bcead23a 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -17,7 +17,10 @@ import ( ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) -var _ porttypes.Middleware = (*IBCMiddleware)(nil) +var ( + _ porttypes.Middleware = (*IBCMiddleware)(nil) + _ porttypes.PacketDataUnmarshaler = (*IBCMiddleware)(nil) +) // IBCMiddleware implements the ICS26 callbacks for the fee middleware given the // ICA controller keeper and the underlying application. @@ -253,3 +256,15 @@ func (im IBCMiddleware) WriteAcknowledgement( func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { return im.keeper.GetAppVersion(ctx, portID, channelID) } + +// UnmarshalPacketData attempts to unmarshal the provided packet data bytes +// into an InterchainAccountPacketData. This function implements the optional +// PacketDataUnmarshaler interface required for ADR 008 support. +func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) { + var packetData icatypes.InterchainAccountPacketData + if err := icatypes.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil { + return nil, err + } + + return packetData, nil +} diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index cf049e3ae50..071d6695868 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -918,3 +918,26 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer( err = path.EndpointB.ChanOpenConfirm() suite.Require().NoError(err) } + +func (suite *InterchainAccountsTestSuite) TestPacketDataUnmarshalerInterface() { + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + expPacketData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: []byte("data"), + Memo: "", + } + + packetData, err := controller.IBCMiddleware{}.UnmarshalPacketData(expPacketData.GetBytes()) + suite.Require().NoError(err) + suite.Require().Equal(expPacketData, packetData) + + // test invalid packet data + invalidPacketData := []byte("invalid packet data") + packetData, err = controller.IBCMiddleware{}.UnmarshalPacketData(invalidPacketData) + suite.Require().Error(err) + suite.Require().Nil(packetData) +} From 678878422dff582e2ccfac2bbf0c7fe077e798c5 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 27 Jul 2023 14:18:18 +0200 Subject: [PATCH 04/10] feat(fee): implemented PacketDataUnmarshaler interface --- modules/apps/29-fee/ibc_middleware.go | 17 +++++++++++++- modules/apps/29-fee/ibc_middleware_test.go | 26 ++++++++++++++++++++++ modules/apps/29-fee/types/errors.go | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 5b260ad7be9..1390d816386 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -16,7 +16,10 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/exported" ) -var _ porttypes.Middleware = (*IBCMiddleware)(nil) +var ( + _ porttypes.Middleware = (*IBCMiddleware)(nil) + _ porttypes.PacketDataUnmarshaler = (*IBCMiddleware)(nil) +) // IBCMiddleware implements the ICS26 callbacks for the fee middleware given the // fee keeper and the underlying application. @@ -348,3 +351,15 @@ func (im IBCMiddleware) WriteAcknowledgement( func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { return im.keeper.GetAppVersion(ctx, portID, channelID) } + +// UnmarshalPacketData attempts to use the underlying app to unmarshal the packet data. +// If the underlying app does not support the PacketDataUnmarshaler interface, an error is returned. +// This function implements the optional PacketDataUnmarshaler interface required for ADR 008 support. +func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) { + unmarshaler, ok := im.app.(porttypes.PacketDataUnmarshaler) + if !ok { + return nil, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil)) + } + + return unmarshaler.UnmarshalPacketData(bz) +} diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index ee1d0ed228a..5348335b26a 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -3,15 +3,18 @@ package fee_test import ( "fmt" + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" fee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" + feekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v7/testing" @@ -1080,3 +1083,26 @@ func (suite *FeeTestSuite) TestGetAppVersion() { }) } } + +func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterface() { + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort) + suite.Require().NoError(err) + + cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + + feeModule, ok := cbs.(porttypes.PacketDataUnmarshaler) + suite.Require().True(ok) + + packetData, err := feeModule.UnmarshalPacketData(ibcmock.MockPacketData) + suite.Require().NoError(err) + suite.Require().Equal(ibcmock.MockPacketData, packetData) +} + +func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterfaceError() { + // test the case when the underlying application cannot be casted to a PacketDataUnmarshaler + mockFeeMiddleware := fee.NewIBCMiddleware(nil, feekeeper.Keeper{}) + + _, err := mockFeeMiddleware.UnmarshalPacketData(ibcmock.MockPacketData) + suite.Require().ErrorIs(err, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil))) +} diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 26167c71016..22dd35000a2 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -16,4 +16,5 @@ var ( ErrFeeNotEnabled = errorsmod.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") ErrRelayerNotFoundForAsyncAck = errorsmod.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") ErrFeeModuleLocked = errorsmod.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") + ErrUnsupportedAction = errorsmod.Register(ModuleName, 12, "unsupported action") ) From ff95701e1f91e01a9696d1c6fd2a2acb57b26db1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 27 Jul 2023 14:34:39 +0200 Subject: [PATCH 05/10] feat(mock): implemented PacketDataUnmarshaler interface --- testing/mock/ibc_module.go | 16 ++++++++++++++++ testing/mock/mock.go | 1 + 2 files changed, 17 insertions(+) diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index ec03110e164..1d83c556003 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -3,6 +3,7 @@ package mock import ( "bytes" "fmt" + "reflect" "strconv" "strings" @@ -10,10 +11,16 @@ import ( capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) +var ( + _ porttypes.IBCModule = (*IBCModule)(nil) + _ porttypes.PacketDataUnmarshaler = (*IBCModule)(nil) +) + // IBCModule implements the ICS26 callbacks for testing/mock. type IBCModule struct { appModule *AppModule @@ -162,6 +169,15 @@ func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, return nil } +// UnmarshalPacketData returns the MockPacketData. This function implements the optional +// PacketDataUnmarshaler interface required for ADR 008 support. +func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) { + if reflect.DeepEqual(bz, MockPacketData) { + return MockPacketData, nil + } + return nil, ErrorMock +} + // GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality. func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string { return fmt.Sprintf("%s%s%s%s", MockRecvCanaryCapabilityName, packet.GetDestPort(), packet.GetDestChannel(), strconv.Itoa(int(packet.GetSequence()))) diff --git a/testing/mock/mock.go b/testing/mock/mock.go index ca6e9c49eee..6fc8a18810d 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -35,6 +35,7 @@ const ( var ( MockAcknowledgement = channeltypes.NewResultAcknowledgement([]byte("mock acknowledgement")) MockFailAcknowledgement = channeltypes.NewErrorAcknowledgement(fmt.Errorf("mock failed acknowledgement")) + ErrorMock = fmt.Errorf("mock failed acknowledgement") MockPacketData = []byte("mock packet data") MockFailPacketData = []byte("mock failed packet data") MockAsyncPacketData = []byte("mock async packet data") From 1bfa6e1d1793d3c99c288808dcec328576f30b99 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 28 Jul 2023 12:33:55 +0200 Subject: [PATCH 06/10] imp(transfer_test): removed explicit use of callbacks in tests --- modules/apps/transfer/ibc_module_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 866ffdfee95..59c69c396b5 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -1,7 +1,6 @@ package transfer_test import ( - "fmt" "math" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -247,8 +246,6 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { var ( sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - srcCallbackAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - destCallbackAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() denom = "transfer/channel-0/atom" amount = "100" @@ -269,7 +266,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { Amount: amount, Sender: sender, Receiver: receiver, - Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, srcCallbackAddr, destCallbackAddr), + Memo: "some memo", } data = expPacketData.GetBytes() }, From 53367704942fb3ca15bf3c5b7015880a44aa5d36 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 28 Jul 2023 13:05:52 +0200 Subject: [PATCH 07/10] style(transfer_test): ran golangci-lint --- modules/apps/transfer/ibc_module_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 59c69c396b5..6fd0335d503 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -244,10 +244,10 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() { func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { var ( - sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - denom = "transfer/channel-0/atom" - amount = "100" + sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + denom = "transfer/channel-0/atom" + amount = "100" data []byte expPacketData types.FungibleTokenPacketData From fc1d9fb0e16f9897c3991bee4320003a09fd022f Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 28 Jul 2023 13:34:03 +0200 Subject: [PATCH 08/10] imp(testing/mock): removed ErrorMock for the upstreamed error --- testing/mock/ibc_module.go | 2 +- testing/mock/mock.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 505897db99f..f2834e435a6 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -182,7 +182,7 @@ func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) { if reflect.DeepEqual(bz, MockPacketData) { return MockPacketData, nil } - return nil, ErrorMock + return nil, MockApplicationCallbackError } // GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality. diff --git a/testing/mock/mock.go b/testing/mock/mock.go index b6350be403b..20c2641512c 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -35,7 +35,6 @@ const ( var ( MockAcknowledgement = channeltypes.NewResultAcknowledgement([]byte("mock acknowledgement")) MockFailAcknowledgement = channeltypes.NewErrorAcknowledgement(fmt.Errorf("mock failed acknowledgement")) - ErrorMock = fmt.Errorf("mock failed acknowledgement") MockPacketData = []byte("mock packet data") MockFailPacketData = []byte("mock failed packet data") MockAsyncPacketData = []byte("mock async packet data") From 6026235c3d87d81c092ba2c2c3ef49aa597bb291 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 28 Jul 2023 13:37:10 +0200 Subject: [PATCH 09/10] style(fee_test): improved test readability --- modules/apps/29-fee/ibc_middleware_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 5348335b26a..a36f9c6a381 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -1104,5 +1104,6 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterfaceError() { mockFeeMiddleware := fee.NewIBCMiddleware(nil, feekeeper.Keeper{}) _, err := mockFeeMiddleware.UnmarshalPacketData(ibcmock.MockPacketData) - suite.Require().ErrorIs(err, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil))) + expError := errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil)) + suite.Require().ErrorIs(err, expError) } From 4144525378221ef7687bd521fde8c2d936209c88 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 28 Jul 2023 13:43:19 +0200 Subject: [PATCH 10/10] imp(transfer_test): improved test styling and added new test case --- modules/apps/transfer/ibc_module_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 6fd0335d503..d8e532632a4 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -246,8 +246,6 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { var ( sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - denom = "transfer/channel-0/atom" - amount = "100" data []byte expPacketData types.FungibleTokenPacketData @@ -259,11 +257,11 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { expPass bool }{ { - "success: both callbacks", + "success: valid packet data with memo", func() { expPacketData = types.FungibleTokenPacketData{ - Denom: denom, - Amount: amount, + Denom: ibctesting.TestCoin.Denom, + Amount: ibctesting.TestCoin.Amount.String(), Sender: sender, Receiver: receiver, Memo: "some memo", @@ -272,6 +270,20 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { }, true, }, + { + "success: valid packet data without memo", + func() { + expPacketData = types.FungibleTokenPacketData{ + Denom: ibctesting.TestCoin.Denom, + Amount: ibctesting.TestCoin.Amount.String(), + Sender: sender, + Receiver: receiver, + Memo: "", + } + data = expPacketData.GetBytes() + }, + true, + }, { "failure: invalid packet data", func() {