From c00b3672645aaaccbabefc6a31c062348fc72870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Quang=20Vinh?= Date: Mon, 8 Jul 2024 01:51:42 +0700 Subject: [PATCH 1/4] Add NoForwarding and EmptyForwardingPacketData helper function to use in tests --- modules/apps/callbacks/ibc_middleware_test.go | 12 +++++------- modules/apps/transfer/types/forwarding.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/apps/callbacks/ibc_middleware_test.go b/modules/apps/callbacks/ibc_middleware_test.go index bfbca027d87..9796d0ea076 100644 --- a/modules/apps/callbacks/ibc_middleware_test.go +++ b/modules/apps/callbacks/ibc_middleware_test.go @@ -25,8 +25,6 @@ import ( ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" ) -var emptyForwardingPacketData = transfertypes.ForwardingPacketData{} - func (s *CallbacksTestSuite) TestNewIBCMiddleware() { testCases := []struct { name string @@ -189,7 +187,7 @@ func (s *CallbacksTestSuite) TestSendPacket() { ibctesting.TestAccAddress, ibctesting.TestAccAddress, fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, simapp.SuccessContract), - emptyForwardingPacketData, + transfertypes.EmptyForwardingPacketData(), ) chanCap := s.path.EndpointA.Chain.GetChannelCapability(s.path.EndpointA.ChannelConfig.PortID, s.path.EndpointA.ChannelID) @@ -331,7 +329,7 @@ func (s *CallbacksTestSuite) TestOnAcknowledgementPacket() { ibctesting.TestAccAddress, ibctesting.TestAccAddress, fmt.Sprintf(`{"src_callback": {"address":"%s", "gas_limit":"%d"}}`, simapp.SuccessContract, userGasLimit), - emptyForwardingPacketData, + transfertypes.EmptyForwardingPacketData(), ) packet = channeltypes.Packet{ @@ -665,7 +663,7 @@ func (s *CallbacksTestSuite) TestOnRecvPacket() { ibctesting.TestAccAddress, s.chainB.SenderAccount.GetAddress().String(), fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"%d"}}`, ibctesting.TestAccAddress, userGasLimit), - emptyForwardingPacketData, + transfertypes.EmptyForwardingPacketData(), ) packet = channeltypes.Packet{ @@ -797,7 +795,7 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() { ibctesting.TestAccAddress, s.chainB.SenderAccount.GetAddress().String(), fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"600000"}}`, ibctesting.TestAccAddress), - emptyForwardingPacketData, + transfertypes.EmptyForwardingPacketData(), ) packet = channeltypes.Packet{ @@ -1021,7 +1019,7 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketDataV1() { Sender: ibctesting.TestAccAddress, Receiver: ibctesting.TestAccAddress, Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, ibctesting.TestAccAddress, ibctesting.TestAccAddress), - Forwarding: emptyForwardingPacketData, + Forwarding: transfertypes.EmptyForwardingPacketData(), } portID := s.path.EndpointA.ChannelConfig.PortID diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index b244b7b840b..cdc8df9ad63 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -18,6 +18,11 @@ func NewForwarding(unwind bool, hops ...Hop) *Forwarding { } } +// NoForwarding is a helper function which returns an Forwarding object with all values empty. +func NoForwarding() Forwarding { + return Forwarding{} +} + // Validate performs a basic validation of the Forwarding fields. func (f Forwarding) Validate() error { if err := validateHops(f.GetHops()); err != nil { @@ -35,6 +40,11 @@ func NewForwardingPacketData(destinationMemo string, hops ...Hop) ForwardingPack } } +// EmptyForwardingPacketData is a helper function which returns an ForwardingPacketData object with all values empty. +func EmptyForwardingPacketData() ForwardingPacketData { + return ForwardingPacketData{} +} + // Validate performs a basic validation of the ForwardingPacketData fields. func (fpd ForwardingPacketData) Validate() error { if err := validateHops(fpd.Hops); err != nil { From 69463834b19fd146d4d13ba6c48a38d22cfdb469 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 8 Jul 2024 12:47:45 +0200 Subject: [PATCH 2/4] use NoForwarding and EmptyForwardingPacketData is a few more places --- modules/apps/transfer/ibc_module_test.go | 2 +- modules/apps/transfer/internal/packet.go | 2 +- modules/apps/transfer/internal/packet_test.go | 20 ++++---- .../apps/transfer/keeper/mbt_relay_test.go | 2 +- .../transfer/keeper/relay_forwarding_test.go | 2 +- modules/apps/transfer/keeper/relay_test.go | 35 ++++++------- modules/apps/transfer/types/forwarding.go | 8 +-- modules/apps/transfer/types/msgs_test.go | 49 +++++++++---------- modules/apps/transfer/types/packet_test.go | 46 +++++++++-------- .../types/transfer_authorization_test.go | 8 +-- 10 files changed, 82 insertions(+), 92 deletions(-) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 5607ce91f42..71b5ac4ecf8 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -367,7 +367,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", - types.ForwardingPacketData{}, + types.EmptyForwardingPacketData(), ) tokensBz, err := json.Marshal(packetData.Tokens) diff --git a/modules/apps/transfer/internal/packet.go b/modules/apps/transfer/internal/packet.go index cc5885523a8..98a70bfc751 100644 --- a/modules/apps/transfer/internal/packet.go +++ b/modules/apps/transfer/internal/packet.go @@ -62,6 +62,6 @@ func packetDataV1ToV2(packetData types.FungibleTokenPacketData) (types.FungibleT Sender: packetData.Sender, Receiver: packetData.Receiver, Memo: packetData.Memo, - Forwarding: types.ForwardingPacketData{}, + Forwarding: types.EmptyForwardingPacketData(), }, nil } diff --git a/modules/apps/transfer/internal/packet_test.go b/modules/apps/transfer/internal/packet_test.go index f9ed72aab42..5ee5dc7e8c6 100644 --- a/modules/apps/transfer/internal/packet_test.go +++ b/modules/apps/transfer/internal/packet_test.go @@ -16,8 +16,6 @@ const ( receiver = "receiver" ) -var emptyForwardingPacketData = types.ForwardingPacketData{} - func TestUnmarshalPacketData(t *testing.T) { var ( packetDataBz []byte @@ -43,7 +41,7 @@ func TestUnmarshalPacketData(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData) + }, sender, receiver, "", types.EmptyForwardingPacketData()) packetDataBz = packetData.GetBytes() version = types.V2 @@ -115,7 +113,7 @@ func TestV2ForwardsCompatibilityFails(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, "sender", "receiver", "", emptyForwardingPacketData, + }, "sender", "receiver", "", types.EmptyForwardingPacketData(), ) packetDataBz = packet.GetBytes() @@ -155,7 +153,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -167,7 +165,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom"), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -179,7 +177,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/withslash", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -191,7 +189,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -203,7 +201,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -215,7 +213,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { @@ -227,7 +225,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, - }, sender, receiver, "", emptyForwardingPacketData), + }, sender, receiver, "", types.EmptyForwardingPacketData()), nil, }, { diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 524bc9e2735..8431816ea30 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -159,7 +159,7 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack AddressFromString(packet.Data.Sender), AddressFromString(packet.Data.Receiver), "", - types.ForwardingPacketData{}, + types.EmptyForwardingPacketData(), ), } } diff --git a/modules/apps/transfer/keeper/relay_forwarding_test.go b/modules/apps/transfer/keeper/relay_forwarding_test.go index 926a1ff155a..0b9b3695b6d 100644 --- a/modules/apps/transfer/keeper/relay_forwarding_test.go +++ b/modules/apps/transfer/keeper/relay_forwarding_test.go @@ -947,7 +947,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() { }, address, receiver.GetAddress().String(), - "", types.ForwardingPacketData{}, + "", types.EmptyForwardingPacketData(), ) packet = channeltypes.NewPacket( diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 9e2dacd35ff..161fe2f2925 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -22,11 +22,6 @@ import ( ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" ) -var ( - emptyForwarding *types.Forwarding - emptyForwardingPacketData = types.ForwardingPacketData{} -) - // TestSendTransfer tests sending from chainA to chainB using both coin // that originate on chainA and coin that originate on chainB. func (suite *KeeperTestSuite) TestSendTransfer() { @@ -201,10 +196,10 @@ func (suite *KeeperTestSuite) TestSendTransfer() { memo = "" timeoutHeight = suite.chainB.GetTimeoutHeight() expEscrowAmount = sdkmath.ZeroInt() - forwarding = emptyForwarding + forwarding = types.NoForwarding() // create IBC token on chainA - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", emptyForwarding) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", types.NoForwarding()) result, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -293,7 +288,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) result, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -314,7 +309,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) res, err := suite.chainB.GetSimApp().TransferKeeper.Transfer(suite.chainB.GetContext(), msg) @@ -420,7 +415,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { // send coin from chainA to chainB coin := sdk.NewCoin(sdk.DefaultBondDenom, amount) - transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, emptyForwarding) + transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) _, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -433,7 +428,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { Denom: types.NewDenom(sdk.DefaultBondDenom, []types.Hop{}...), Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, emptyForwardingPacketData) + }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, types.EmptyForwardingPacketData()) packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -555,7 +550,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { // send coin from chainB to chainA, receive them, acknowledge them coin := ibctesting.TestCoin - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, memo, emptyForwarding) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) res, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -572,7 +567,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { // send coin back from chainA to chainB coin = sdk.NewCoin(denom.IBCDenom(), amount) - transferMsg = types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, emptyForwarding) + transferMsg = types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) _, err = suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -584,7 +579,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, emptyForwardingPacketData) + }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, types.EmptyForwardingPacketData()) packet = channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -662,7 +657,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", emptyForwardingPacketData) + }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) packet := channeltypes.NewPacket( data.GetBytes(), seq, @@ -793,7 +788,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", emptyForwardingPacketData) + }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) preAcknowledgementBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), denom.IBCDenom()) @@ -888,7 +883,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ) packet := channeltypes.NewPacket( data.GetBytes(), @@ -1028,7 +1023,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { Denom: denom, Amount: amount, }, - }, sender, suite.chainB.SenderAccount.GetAddress().String(), "", emptyForwardingPacketData) + }, sender, suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) preTimeoutBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), denom.IBCDenom()) @@ -1114,7 +1109,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI Denom: denom, Amount: amount.String(), }, - }, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", emptyForwardingPacketData) + }, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) packet := channeltypes.NewPacket( data.GetBytes(), seq, @@ -1271,7 +1266,7 @@ func (suite *KeeperTestSuite) TestCreatePacketDataBytesFromVersion() { types.V2, func() {}, func(bz []byte, err error) { - expPacketData := types.NewFungibleTokenPacketDataV2(tokens, sender, receiver, "", emptyForwardingPacketData) + expPacketData := types.NewFungibleTokenPacketDataV2(tokens, sender, receiver, "", types.EmptyForwardingPacketData()) suite.Require().Equal(bz, expPacketData.GetBytes()) suite.Require().NoError(err) }, diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index cdc8df9ad63..d389ea9cded 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -18,9 +18,9 @@ func NewForwarding(unwind bool, hops ...Hop) *Forwarding { } } -// NoForwarding is a helper function which returns an Forwarding object with all values empty. -func NoForwarding() Forwarding { - return Forwarding{} +// NoForwarding is a helper function which returns a Forwarding instance with all values empty. +func NoForwarding() *Forwarding { + return &Forwarding{} } // Validate performs a basic validation of the Forwarding fields. @@ -40,7 +40,7 @@ func NewForwardingPacketData(destinationMemo string, hops ...Hop) ForwardingPack } } -// EmptyForwardingPacketData is a helper function which returns an ForwardingPacketData object with all values empty. +// EmptyForwardingPacketData is a helper function which returns a ForwardingPacketData instance with all values empty. func EmptyForwardingPacketData() ForwardingPacketData { return ForwardingPacketData{} } diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 135472bd2f2..3aa756d31c1 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -47,8 +47,7 @@ var ( invalidDenomCoins = []sdk.Coin{{Denom: "0atom", Amount: sdkmath.NewInt(100)}} zeroCoins = []sdk.Coin{{Denom: "atoms", Amount: sdkmath.NewInt(0)}} - timeoutHeight = clienttypes.NewHeight(0, 10) - emptyForwarding *types.Forwarding + timeoutHeight = clienttypes.NewHeight(0, 10) ) // TestMsgTransferValidation tests ValidateBasic for MsgTransfer @@ -58,31 +57,31 @@ func TestMsgTransferValidation(t *testing.T) { msg *types.MsgTransfer expError error }{ - {"valid msg with base denom", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), nil}, + {"valid msg with base denom", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, {"valid msg with unwind", types.NewMsgTransfer("", "", sdk.NewCoins(coin), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(true)), nil}, - {"valid msg with trace hash", types.NewMsgTransfer(validPort, validChannel, ibcCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), nil}, - {"multidenom", types.NewMsgTransfer(validPort, validChannel, coins.Add(ibcCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), nil}, + {"valid msg with trace hash", types.NewMsgTransfer(validPort, validChannel, ibcCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, + {"multidenom", types.NewMsgTransfer(validPort, validChannel, coins.Add(ibcCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, {"memo with forwarding path hops not empty", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "memo", types.NewForwarding(false, validHop)), nil}, {"memo with forwarding unwind set to true", types.NewMsgTransfer("", "", sdk.NewCoins(coin), sender, receiver, clienttypes.ZeroHeight(), 100, "memo", types.NewForwarding(true)), nil}, - {"invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, invalidIBCCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"too short port id", types.NewMsgTransfer(invalidShortPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"too long port id", types.NewMsgTransfer(invalidLongPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"port id contains non-alpha", types.NewMsgTransfer(invalidPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"too short channel id", types.NewMsgTransfer(validPort, invalidShortChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"too long channel id", types.NewMsgTransfer(validPort, invalidLongChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"too long memo", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, ibctesting.GenerateString(types.MaximumMemoLength+1), emptyForwarding), types.ErrInvalidMemo}, - {"channel id contains non-alpha", types.NewMsgTransfer(validPort, invalidChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), host.ErrInvalidID}, - {"invalid denom", types.NewMsgTransfer(validPort, validChannel, invalidDenomCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"missing sender address", types.NewMsgTransfer(validPort, validChannel, coins, emptyAddr, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidAddress}, - {"missing recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, "", clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidAddress}, - {"too long recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, ibctesting.GenerateString(types.MaximumReceiverLength+1), clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidAddress}, - {"empty coins", types.NewMsgTransfer(validPort, validChannel, sdk.NewCoins(), sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"multidenom: invalid denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidDenomCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"multidenom: invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidIBCCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"multidenom: zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"multidenom: too many coins", types.NewMsgTransfer(validPort, validChannel, make([]sdk.Coin, types.MaximumTokensLength+1), sender, receiver, clienttypes.ZeroHeight(), 100, "", emptyForwarding), ibcerrors.ErrInvalidCoins}, - {"multidenom: both token and tokens are set", &types.MsgTransfer{validPort, validChannel, coin, sender, receiver, clienttypes.ZeroHeight(), 100, "", coins, emptyForwarding}, ibcerrors.ErrInvalidCoins}, + {"invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, invalidIBCCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"too short port id", types.NewMsgTransfer(invalidShortPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"too long port id", types.NewMsgTransfer(invalidLongPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"port id contains non-alpha", types.NewMsgTransfer(invalidPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"too short channel id", types.NewMsgTransfer(validPort, invalidShortChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"too long channel id", types.NewMsgTransfer(validPort, invalidLongChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"too long memo", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, ibctesting.GenerateString(types.MaximumMemoLength+1), types.NoForwarding()), types.ErrInvalidMemo}, + {"channel id contains non-alpha", types.NewMsgTransfer(validPort, invalidChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, + {"invalid denom", types.NewMsgTransfer(validPort, validChannel, invalidDenomCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"missing sender address", types.NewMsgTransfer(validPort, validChannel, coins, emptyAddr, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, + {"missing recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, "", clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, + {"too long recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, ibctesting.GenerateString(types.MaximumReceiverLength+1), clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, + {"empty coins", types.NewMsgTransfer(validPort, validChannel, sdk.NewCoins(), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"multidenom: invalid denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidDenomCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"multidenom: invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidIBCCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"multidenom: zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"multidenom: too many coins", types.NewMsgTransfer(validPort, validChannel, make([]sdk.Coin, types.MaximumTokensLength+1), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, + {"multidenom: both token and tokens are set", &types.MsgTransfer{validPort, validChannel, coin, sender, receiver, clienttypes.ZeroHeight(), 100, "", coins, types.NoForwarding()}, ibcerrors.ErrInvalidCoins}, {"timeout height must be zero if forwarding path hops is not empty", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, timeoutHeight, 100, "memo", types.NewForwarding(false, validHop)), types.ErrInvalidPacketTimeout}, {"invalid forwarding info port", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, types.NewHop(invalidPort, validChannel))), types.ErrInvalidForwarding}, {"invalid forwarding info channel", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, types.NewHop(validPort, invalidChannel))), types.ErrInvalidForwarding}, @@ -111,7 +110,7 @@ func TestMsgTransferValidation(t *testing.T) { // TestMsgTransferGetSigners tests GetSigners for MsgTransfer func TestMsgTransferGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - msg := types.NewMsgTransfer(validPort, validChannel, coins, addr.String(), receiver, timeoutHeight, 0, "", emptyForwarding) + msg := types.NewMsgTransfer(validPort, validChannel, coins, addr.String(), receiver, timeoutHeight, 0, "", types.NoForwarding()) encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 286d7f6e4a5..552e729d4a6 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -19,8 +19,6 @@ const ( invalidLargeAmount = "115792089237316195423570985008687907853269984665640564039457584007913129639936" // 2^256 ) -var emptyForwardingPacketData = types.ForwardingPacketData{} - // TestFungibleTokenPacketDataValidateBasic tests ValidateBasic for FungibleTokenPacketData func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { testCases := []struct { @@ -184,7 +182,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -200,7 +198,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -216,7 +214,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -264,7 +262,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidDenomForTransfer, }, @@ -280,7 +278,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidAmount, }, @@ -291,7 +289,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidAmount, }, @@ -307,7 +305,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidAmount, }, @@ -323,7 +321,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidAmount, }, @@ -339,7 +337,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidAmount, }, @@ -355,7 +353,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { "", receiver, "memo", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), ibcerrors.ErrInvalidAddress, }, @@ -371,7 +369,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, "", "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), ibcerrors.ErrInvalidAddress, }, @@ -387,7 +385,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, ibctesting.GenerateString(types.MaximumMemoLength+1), - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), types.ErrInvalidMemo, }, @@ -511,7 +509,7 @@ func TestGetPacketSender(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), sender, }, @@ -527,7 +525,7 @@ func TestGetPacketSender(t *testing.T) { "", receiver, "abc", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), "", }, @@ -558,7 +556,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, receiver), - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), map[string]interface{}{ @@ -577,7 +575,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"src_callback": {"address": "%s", "gas_limit": "200000"}}`, receiver), - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), map[string]interface{}{ "address": receiver, @@ -596,7 +594,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, `{"src_callback": "string"}`, - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), "string", }, @@ -612,7 +610,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"dest_callback": {"address": "%s", "min_gas": "200000"}}`, receiver), - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -628,7 +626,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -644,7 +642,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, "invalid", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), nil, }, @@ -676,7 +674,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { sender, receiver, "", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), false, }, @@ -692,7 +690,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { sender, receiver, "abc", - emptyForwardingPacketData, + types.EmptyForwardingPacketData(), ), true, }, diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index fa97b7a28f6..f2432c0c220 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -265,7 +265,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) }, func(res authz.AcceptResponse, err error) { @@ -343,7 +343,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) }, func(res authz.AcceptResponse, err error) { @@ -380,7 +380,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) }, func(res authz.AcceptResponse, err error) { @@ -508,7 +508,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - emptyForwarding, + types.NoForwarding(), ) tc.malleate() From e7c7e63134c68c192030d6216f7c21079c4dce13 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 8 Jul 2024 13:40:20 +0200 Subject: [PATCH 3/4] use nil for forwarding and move empty forwarding packet data to testing package --- modules/apps/callbacks/ibc_middleware_test.go | 10 ++-- modules/apps/transfer/ibc_module_test.go | 2 +- modules/apps/transfer/internal/packet.go | 2 +- modules/apps/transfer/internal/packet_test.go | 18 ++++---- .../apps/transfer/keeper/mbt_relay_test.go | 2 +- .../transfer/keeper/relay_forwarding_test.go | 2 +- modules/apps/transfer/keeper/relay_test.go | 29 ++++++------ modules/apps/transfer/types/forwarding.go | 5 -- modules/apps/transfer/types/msgs_test.go | 46 +++++++++---------- modules/apps/transfer/types/packet_test.go | 44 +++++++++--------- .../types/transfer_authorization_test.go | 8 ++-- testing/values.go | 2 + 12 files changed, 83 insertions(+), 87 deletions(-) diff --git a/modules/apps/callbacks/ibc_middleware_test.go b/modules/apps/callbacks/ibc_middleware_test.go index 9796d0ea076..4c0c9a2a7a9 100644 --- a/modules/apps/callbacks/ibc_middleware_test.go +++ b/modules/apps/callbacks/ibc_middleware_test.go @@ -187,7 +187,7 @@ func (s *CallbacksTestSuite) TestSendPacket() { ibctesting.TestAccAddress, ibctesting.TestAccAddress, fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, simapp.SuccessContract), - transfertypes.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) chanCap := s.path.EndpointA.Chain.GetChannelCapability(s.path.EndpointA.ChannelConfig.PortID, s.path.EndpointA.ChannelID) @@ -329,7 +329,7 @@ func (s *CallbacksTestSuite) TestOnAcknowledgementPacket() { ibctesting.TestAccAddress, ibctesting.TestAccAddress, fmt.Sprintf(`{"src_callback": {"address":"%s", "gas_limit":"%d"}}`, simapp.SuccessContract, userGasLimit), - transfertypes.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) packet = channeltypes.Packet{ @@ -663,7 +663,7 @@ func (s *CallbacksTestSuite) TestOnRecvPacket() { ibctesting.TestAccAddress, s.chainB.SenderAccount.GetAddress().String(), fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"%d"}}`, ibctesting.TestAccAddress, userGasLimit), - transfertypes.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) packet = channeltypes.Packet{ @@ -795,7 +795,7 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() { ibctesting.TestAccAddress, s.chainB.SenderAccount.GetAddress().String(), fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"600000"}}`, ibctesting.TestAccAddress), - transfertypes.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) packet = channeltypes.Packet{ @@ -1019,7 +1019,7 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketDataV1() { Sender: ibctesting.TestAccAddress, Receiver: ibctesting.TestAccAddress, Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, ibctesting.TestAccAddress, ibctesting.TestAccAddress), - Forwarding: transfertypes.EmptyForwardingPacketData(), + Forwarding: ibctesting.EmptyForwardingPacketData, } portID := s.path.EndpointA.ChannelConfig.PortID diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 71b5ac4ecf8..3e796a469cf 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -367,7 +367,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) tokensBz, err := json.Marshal(packetData.Tokens) diff --git a/modules/apps/transfer/internal/packet.go b/modules/apps/transfer/internal/packet.go index 98a70bfc751..cc5885523a8 100644 --- a/modules/apps/transfer/internal/packet.go +++ b/modules/apps/transfer/internal/packet.go @@ -62,6 +62,6 @@ func packetDataV1ToV2(packetData types.FungibleTokenPacketData) (types.FungibleT Sender: packetData.Sender, Receiver: packetData.Receiver, Memo: packetData.Memo, - Forwarding: types.EmptyForwardingPacketData(), + Forwarding: types.ForwardingPacketData{}, }, nil } diff --git a/modules/apps/transfer/internal/packet_test.go b/modules/apps/transfer/internal/packet_test.go index 5ee5dc7e8c6..b3f9b2d8578 100644 --- a/modules/apps/transfer/internal/packet_test.go +++ b/modules/apps/transfer/internal/packet_test.go @@ -41,7 +41,7 @@ func TestUnmarshalPacketData(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()) + }, sender, receiver, "", types.ForwardingPacketData{}) packetDataBz = packetData.GetBytes() version = types.V2 @@ -113,7 +113,7 @@ func TestV2ForwardsCompatibilityFails(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, "sender", "receiver", "", types.EmptyForwardingPacketData(), + }, "sender", "receiver", "", types.ForwardingPacketData{}, ) packetDataBz = packet.GetBytes() @@ -153,7 +153,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -165,7 +165,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom"), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -177,7 +177,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/withslash", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -189,7 +189,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/", types.NewHop("transfer", "channel-0")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -201,7 +201,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -213,7 +213,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { @@ -225,7 +225,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, - }, sender, receiver, "", types.EmptyForwardingPacketData()), + }, sender, receiver, "", types.ForwardingPacketData{}), nil, }, { diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 8431816ea30..6dae1bd21e1 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -159,7 +159,7 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack AddressFromString(packet.Data.Sender), AddressFromString(packet.Data.Receiver), "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), } } diff --git a/modules/apps/transfer/keeper/relay_forwarding_test.go b/modules/apps/transfer/keeper/relay_forwarding_test.go index 0b9b3695b6d..fbe3526ac90 100644 --- a/modules/apps/transfer/keeper/relay_forwarding_test.go +++ b/modules/apps/transfer/keeper/relay_forwarding_test.go @@ -947,7 +947,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() { }, address, receiver.GetAddress().String(), - "", types.EmptyForwardingPacketData(), + "", ibctesting.EmptyForwardingPacketData, ) packet = channeltypes.NewPacket( diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 161fe2f2925..8f2556b5e5a 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -196,10 +196,9 @@ func (suite *KeeperTestSuite) TestSendTransfer() { memo = "" timeoutHeight = suite.chainB.GetTimeoutHeight() expEscrowAmount = sdkmath.ZeroInt() - forwarding = types.NoForwarding() // create IBC token on chainA - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", types.NoForwarding()) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", nil) result, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -288,7 +287,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) result, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -309,7 +308,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) res, err := suite.chainB.GetSimApp().TransferKeeper.Transfer(suite.chainB.GetContext(), msg) @@ -415,7 +414,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { // send coin from chainA to chainB coin := sdk.NewCoin(sdk.DefaultBondDenom, amount) - transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) + transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, nil) _, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -428,7 +427,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { Denom: types.NewDenom(sdk.DefaultBondDenom, []types.Hop{}...), Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, types.EmptyForwardingPacketData()) + }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, ibctesting.EmptyForwardingPacketData) packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -550,7 +549,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { // send coin from chainB to chainA, receive them, acknowledge them coin := ibctesting.TestCoin - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, memo, nil) res, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -567,7 +566,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { // send coin back from chainA to chainB coin = sdk.NewCoin(denom.IBCDenom(), amount) - transferMsg = types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, types.NoForwarding()) + transferMsg = types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoins(coin), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo, nil) _, err = suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -579,7 +578,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, types.EmptyForwardingPacketData()) + }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, ibctesting.EmptyForwardingPacketData) packet = channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -657,7 +656,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) + }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", ibctesting.EmptyForwardingPacketData) packet := channeltypes.NewPacket( data.GetBytes(), seq, @@ -788,7 +787,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { Denom: denom, Amount: amount.String(), }, - }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) + }, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", ibctesting.EmptyForwardingPacketData) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) preAcknowledgementBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), denom.IBCDenom()) @@ -883,7 +882,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ) packet := channeltypes.NewPacket( data.GetBytes(), @@ -1023,7 +1022,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { Denom: denom, Amount: amount, }, - }, sender, suite.chainB.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) + }, sender, suite.chainB.SenderAccount.GetAddress().String(), "", ibctesting.EmptyForwardingPacketData) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) preTimeoutBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), denom.IBCDenom()) @@ -1109,7 +1108,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI Denom: denom, Amount: amount.String(), }, - }, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", types.EmptyForwardingPacketData()) + }, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "", ibctesting.EmptyForwardingPacketData) packet := channeltypes.NewPacket( data.GetBytes(), seq, @@ -1266,7 +1265,7 @@ func (suite *KeeperTestSuite) TestCreatePacketDataBytesFromVersion() { types.V2, func() {}, func(bz []byte, err error) { - expPacketData := types.NewFungibleTokenPacketDataV2(tokens, sender, receiver, "", types.EmptyForwardingPacketData()) + expPacketData := types.NewFungibleTokenPacketDataV2(tokens, sender, receiver, "", ibctesting.EmptyForwardingPacketData) suite.Require().Equal(bz, expPacketData.GetBytes()) suite.Require().NoError(err) }, diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index d389ea9cded..0362488882a 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -40,11 +40,6 @@ func NewForwardingPacketData(destinationMemo string, hops ...Hop) ForwardingPack } } -// EmptyForwardingPacketData is a helper function which returns a ForwardingPacketData instance with all values empty. -func EmptyForwardingPacketData() ForwardingPacketData { - return ForwardingPacketData{} -} - // Validate performs a basic validation of the ForwardingPacketData fields. func (fpd ForwardingPacketData) Validate() error { if err := validateHops(fpd.Hops); err != nil { diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 3aa756d31c1..199e225156d 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -57,31 +57,31 @@ func TestMsgTransferValidation(t *testing.T) { msg *types.MsgTransfer expError error }{ - {"valid msg with base denom", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, + {"valid msg with base denom", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), nil}, {"valid msg with unwind", types.NewMsgTransfer("", "", sdk.NewCoins(coin), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(true)), nil}, - {"valid msg with trace hash", types.NewMsgTransfer(validPort, validChannel, ibcCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, - {"multidenom", types.NewMsgTransfer(validPort, validChannel, coins.Add(ibcCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), nil}, + {"valid msg with trace hash", types.NewMsgTransfer(validPort, validChannel, ibcCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), nil}, + {"multidenom", types.NewMsgTransfer(validPort, validChannel, coins.Add(ibcCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), nil}, {"memo with forwarding path hops not empty", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "memo", types.NewForwarding(false, validHop)), nil}, {"memo with forwarding unwind set to true", types.NewMsgTransfer("", "", sdk.NewCoins(coin), sender, receiver, clienttypes.ZeroHeight(), 100, "memo", types.NewForwarding(true)), nil}, - {"invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, invalidIBCCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"too short port id", types.NewMsgTransfer(invalidShortPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"too long port id", types.NewMsgTransfer(invalidLongPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"port id contains non-alpha", types.NewMsgTransfer(invalidPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"too short channel id", types.NewMsgTransfer(validPort, invalidShortChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"too long channel id", types.NewMsgTransfer(validPort, invalidLongChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"too long memo", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, ibctesting.GenerateString(types.MaximumMemoLength+1), types.NoForwarding()), types.ErrInvalidMemo}, - {"channel id contains non-alpha", types.NewMsgTransfer(validPort, invalidChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), host.ErrInvalidID}, - {"invalid denom", types.NewMsgTransfer(validPort, validChannel, invalidDenomCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"missing sender address", types.NewMsgTransfer(validPort, validChannel, coins, emptyAddr, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, - {"missing recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, "", clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, - {"too long recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, ibctesting.GenerateString(types.MaximumReceiverLength+1), clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidAddress}, - {"empty coins", types.NewMsgTransfer(validPort, validChannel, sdk.NewCoins(), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"multidenom: invalid denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidDenomCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"multidenom: invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidIBCCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"multidenom: zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"multidenom: too many coins", types.NewMsgTransfer(validPort, validChannel, make([]sdk.Coin, types.MaximumTokensLength+1), sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NoForwarding()), ibcerrors.ErrInvalidCoins}, - {"multidenom: both token and tokens are set", &types.MsgTransfer{validPort, validChannel, coin, sender, receiver, clienttypes.ZeroHeight(), 100, "", coins, types.NoForwarding()}, ibcerrors.ErrInvalidCoins}, + {"invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, invalidIBCCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"too short port id", types.NewMsgTransfer(invalidShortPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"too long port id", types.NewMsgTransfer(invalidLongPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"port id contains non-alpha", types.NewMsgTransfer(invalidPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"too short channel id", types.NewMsgTransfer(validPort, invalidShortChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"too long channel id", types.NewMsgTransfer(validPort, invalidLongChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"too long memo", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, ibctesting.GenerateString(types.MaximumMemoLength+1), nil), types.ErrInvalidMemo}, + {"channel id contains non-alpha", types.NewMsgTransfer(validPort, invalidChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), host.ErrInvalidID}, + {"invalid denom", types.NewMsgTransfer(validPort, validChannel, invalidDenomCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"missing sender address", types.NewMsgTransfer(validPort, validChannel, coins, emptyAddr, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidAddress}, + {"missing recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, "", clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidAddress}, + {"too long recipient address", types.NewMsgTransfer(validPort, validChannel, coins, sender, ibctesting.GenerateString(types.MaximumReceiverLength+1), clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidAddress}, + {"empty coins", types.NewMsgTransfer(validPort, validChannel, sdk.NewCoins(), sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"multidenom: invalid denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidDenomCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"multidenom: invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidIBCCoins...), sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"multidenom: zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"multidenom: too many coins", types.NewMsgTransfer(validPort, validChannel, make([]sdk.Coin, types.MaximumTokensLength+1), sender, receiver, clienttypes.ZeroHeight(), 100, "", nil), ibcerrors.ErrInvalidCoins}, + {"multidenom: both token and tokens are set", &types.MsgTransfer{validPort, validChannel, coin, sender, receiver, clienttypes.ZeroHeight(), 100, "", coins, nil}, ibcerrors.ErrInvalidCoins}, {"timeout height must be zero if forwarding path hops is not empty", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, timeoutHeight, 100, "memo", types.NewForwarding(false, validHop)), types.ErrInvalidPacketTimeout}, {"invalid forwarding info port", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, types.NewHop(invalidPort, validChannel))), types.ErrInvalidForwarding}, {"invalid forwarding info channel", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, types.NewHop(validPort, invalidChannel))), types.ErrInvalidForwarding}, @@ -110,7 +110,7 @@ func TestMsgTransferValidation(t *testing.T) { // TestMsgTransferGetSigners tests GetSigners for MsgTransfer func TestMsgTransferGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - msg := types.NewMsgTransfer(validPort, validChannel, coins, addr.String(), receiver, timeoutHeight, 0, "", types.NoForwarding()) + msg := types.NewMsgTransfer(validPort, validChannel, coins, addr.String(), receiver, timeoutHeight, 0, "", nil) encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 552e729d4a6..8e4c8c46ea9 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -182,7 +182,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -198,7 +198,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -214,7 +214,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -262,7 +262,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidDenomForTransfer, }, @@ -278,7 +278,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidAmount, }, @@ -289,7 +289,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidAmount, }, @@ -305,7 +305,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidAmount, }, @@ -321,7 +321,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidAmount, }, @@ -337,7 +337,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, "memo", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidAmount, }, @@ -353,7 +353,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { "", receiver, "memo", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), ibcerrors.ErrInvalidAddress, }, @@ -369,7 +369,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, "", "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), ibcerrors.ErrInvalidAddress, }, @@ -385,7 +385,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { sender, receiver, ibctesting.GenerateString(types.MaximumMemoLength+1), - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), types.ErrInvalidMemo, }, @@ -509,7 +509,7 @@ func TestGetPacketSender(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), sender, }, @@ -525,7 +525,7 @@ func TestGetPacketSender(t *testing.T) { "", receiver, "abc", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), "", }, @@ -556,7 +556,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, receiver), - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), map[string]interface{}{ @@ -575,7 +575,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"src_callback": {"address": "%s", "gas_limit": "200000"}}`, receiver), - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), map[string]interface{}{ "address": receiver, @@ -594,7 +594,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, `{"src_callback": "string"}`, - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), "string", }, @@ -610,7 +610,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, fmt.Sprintf(`{"dest_callback": {"address": "%s", "min_gas": "200000"}}`, receiver), - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -626,7 +626,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -642,7 +642,7 @@ func TestPacketDataProvider(t *testing.T) { sender, receiver, "invalid", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), nil, }, @@ -674,7 +674,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { sender, receiver, "", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), false, }, @@ -690,7 +690,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { sender, receiver, "abc", - types.EmptyForwardingPacketData(), + ibctesting.EmptyForwardingPacketData, ), true, }, diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index f2432c0c220..23be80ea98b 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -265,7 +265,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) }, func(res authz.AcceptResponse, err error) { @@ -343,7 +343,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) }, func(res authz.AcceptResponse, err error) { @@ -380,7 +380,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) }, func(res authz.AcceptResponse, err error) { @@ -508,7 +508,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { suite.chainB.GetTimeoutHeight(), 0, "", - types.NoForwarding(), + nil, ) tc.malleate() diff --git a/testing/values.go b/testing/values.go index 25c43462f8c..7938519156f 100644 --- a/testing/values.go +++ b/testing/values.go @@ -72,6 +72,8 @@ var ( MockFailPacketData = mock.MockFailPacketData MockRecvCanaryCapabilityName = mock.MockRecvCanaryCapabilityName + EmptyForwardingPacketData = ibctransfertypes.ForwardingPacketData{} + prefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) // unusedHash is a placeholder hash used for testing. unusedHash = tmhash.Sum([]byte{0x00}) From 354f63b04bfa302145c2df5374536e643911caee Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Mon, 8 Jul 2024 14:55:04 +0300 Subject: [PATCH 4/4] chore: rm NoForwarding. --- modules/apps/transfer/types/forwarding.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index 0362488882a..b244b7b840b 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -18,11 +18,6 @@ func NewForwarding(unwind bool, hops ...Hop) *Forwarding { } } -// NoForwarding is a helper function which returns a Forwarding instance with all values empty. -func NoForwarding() *Forwarding { - return &Forwarding{} -} - // Validate performs a basic validation of the Forwarding fields. func (f Forwarding) Validate() error { if err := validateHops(f.GetHops()); err != nil {