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] 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 {