Skip to content

Commit

Permalink
Add NoForwarding and EmptyForwardingPacketData helper function to use…
Browse files Browse the repository at this point in the history
… in tests
  • Loading branch information
hakuno2000 committed Jul 7, 2024
1 parent 7527d70 commit c00b367
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 5 additions & 7 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions modules/apps/transfer/types/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit c00b367

Please sign in to comment.