Skip to content

Commit

Permalink
Add NoForwarding and EmptyForwardingPacketData helper function to use… (
Browse files Browse the repository at this point in the history
#6774)

* Add NoForwarding and EmptyForwardingPacketData helper function to use in tests

* use NoForwarding and EmptyForwardingPacketData is a few more places

* use nil for forwarding and move empty forwarding packet data to testing package

* chore: rm NoForwarding.

---------

Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
3 people authored Jul 8, 2024
1 parent 2d35a43 commit 45342f2
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 94 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,
ibctesting.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,
ibctesting.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,
ibctesting.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,
ibctesting.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: ibctesting.EmptyForwardingPacketData,
}

portID := s.path.EndpointA.ChannelConfig.PortID
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() {
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
"",
types.ForwardingPacketData{},
ibctesting.EmptyForwardingPacketData,
)

tokensBz, err := json.Marshal(packetData.Tokens)
Expand Down
20 changes: 9 additions & 11 deletions modules/apps/transfer/internal/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const (
receiver = "receiver"
)

var emptyForwardingPacketData = types.ForwardingPacketData{}

func TestUnmarshalPacketData(t *testing.T) {
var (
packetDataBz []byte
Expand All @@ -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.ForwardingPacketData{})

packetDataBz = packetData.GetBytes()
version = types.V2
Expand Down Expand Up @@ -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.ForwardingPacketData{},
)

packetDataBz = packet.GetBytes()
Expand Down Expand Up @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -167,7 +165,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom"),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -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.ForwardingPacketData{}),
nil,
},
{
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack
AddressFromString(packet.Data.Sender),
AddressFromString(packet.Data.Receiver),
"",
types.ForwardingPacketData{},
ibctesting.EmptyForwardingPacketData,
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/relay_forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() {
},
address,
receiver.GetAddress().String(),
"", types.ForwardingPacketData{},
"", ibctesting.EmptyForwardingPacketData,
)

packet = channeltypes.NewPacket(
Expand Down
34 changes: 14 additions & 20 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -201,10 +196,9 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
memo = ""
timeoutHeight = suite.chainB.GetTimeoutHeight()
expEscrowAmount = sdkmath.ZeroInt()
forwarding = emptyForwarding

// 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, "", nil)
result, err := suite.chainB.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand Down Expand Up @@ -293,7 +287,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
suite.chainB.GetTimeoutHeight(), 0, "",
emptyForwarding,
nil,
)
result, err := suite.chainA.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed
Expand All @@ -314,7 +308,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT
suite.chainB.SenderAccount.GetAddress().String(),
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainA.GetTimeoutHeight(), 0, "",
emptyForwarding,
nil,
)

res, err := suite.chainB.GetSimApp().TransferKeeper.Transfer(suite.chainB.GetContext(), msg)
Expand Down Expand Up @@ -420,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, 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, nil)
_, err := suite.chainA.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand All @@ -433,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, 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)
Expand Down Expand Up @@ -555,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, 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, nil)
res, err := suite.chainB.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand All @@ -572,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, 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, nil)
_, err = suite.chainA.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand All @@ -584,7 +578,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, 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)
Expand Down Expand Up @@ -662,7 +656,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(), "", ibctesting.EmptyForwardingPacketData)
packet := channeltypes.NewPacket(
data.GetBytes(),
seq,
Expand Down Expand Up @@ -793,7 +787,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(), "", 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())

Expand Down Expand Up @@ -888,7 +882,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo
suite.chainB.SenderAccount.GetAddress().String(),
suite.chainA.SenderAccount.GetAddress().String(),
"",
emptyForwardingPacketData,
ibctesting.EmptyForwardingPacketData,
)
packet := channeltypes.NewPacket(
data.GetBytes(),
Expand Down Expand Up @@ -1028,7 +1022,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
Denom: denom,
Amount: amount,
},
}, sender, suite.chainB.SenderAccount.GetAddress().String(), "", 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())

Expand Down Expand Up @@ -1114,7 +1108,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(), "", ibctesting.EmptyForwardingPacketData)
packet := channeltypes.NewPacket(
data.GetBytes(),
seq,
Expand Down Expand Up @@ -1271,7 +1265,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, "", ibctesting.EmptyForwardingPacketData)
suite.Require().Equal(bz, expPacketData.GetBytes())
suite.Require().NoError(err)
},
Expand Down
Loading

0 comments on commit 45342f2

Please sign in to comment.