From f7bdc7510f7c95bddd12c1c7df5b9a4c3423c102 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 28 Jun 2024 14:40:48 +0200 Subject: [PATCH] refactor: add and use `NewHop` constructor (#6727) * refactor: use NewHop constructor * more NewHop --- e2e/tests/transfer/forwarding_test.go | 5 +- modules/apps/transfer/client/cli/tx.go | 2 +- modules/apps/transfer/ibc_module_test.go | 2 +- modules/apps/transfer/keeper/msg_server.go | 2 +- .../apps/transfer/keeper/msg_server_test.go | 14 +-- .../transfer/keeper/relay_forwarding_test.go | 67 ++++++------ modules/apps/transfer/keeper/relay_test.go | 16 +-- modules/apps/transfer/types/forwarding.go | 5 + .../apps/transfer/types/forwarding_test.go | 100 ++++-------------- modules/apps/transfer/types/msgs_test.go | 4 +- modules/apps/transfer/types/packet_test.go | 10 +- .../types/transfer_authorization_test.go | 44 ++++---- 12 files changed, 101 insertions(+), 170 deletions(-) diff --git a/e2e/tests/transfer/forwarding_test.go b/e2e/tests/transfer/forwarding_test.go index 386e6a61c96..d038a134d73 100644 --- a/e2e/tests/transfer/forwarding_test.go +++ b/e2e/tests/transfer/forwarding_test.go @@ -57,10 +57,7 @@ func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_S t.Run("IBC transfer from A to C with forwarding through B", func(t *testing.T) { inFiveMinutes := time.Now().Add(5 * time.Minute).UnixNano() - forwarding := transfertypes.NewForwarding(false, transfertypes.Hop{ - PortId: channelBtoC.PortID, - ChannelId: channelBtoC.ChannelID, - }) + forwarding := transfertypes.NewForwarding(false, transfertypes.NewHop(channelBtoC.PortID, channelBtoC.ChannelID)) msgTransfer := testsuite.GetMsgTransfer( channelAtoB.PortID, diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index 14d0ccb61d8..2a42012a082 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -161,7 +161,7 @@ func parseForwarding(cmd *cobra.Command) (types.Forwarding, error) { return types.Forwarding{}, fmt.Errorf("expected a portID/channelID pair, found %s", pair) } - hop := types.Hop{PortId: pairSplit[0], ChannelId: pairSplit[1]} + hop := types.NewHop(pairSplit[0], pairSplit[1]) hops = append(hops, hop) } diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index c524bb42cc5..4cc72c970b7 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -303,7 +303,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", - types.NewForwardingPacketData("", types.Hop{PortId: "transfer", ChannelId: "channel-0"}), + types.NewForwardingPacketData("", types.NewHop("transfer", "channel-0")), ) packet.Data = packetData.GetBytes() diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 9c40125cc50..b8712975df4 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -83,7 +83,7 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT var unwindHops []types.Hop // remove the first hop in denom as it is the current port/channel on this chain for _, trace := range token.Denom.Trace[1:] { - unwindHops = append(unwindHops, types.Hop{PortId: trace.PortId, ChannelId: trace.ChannelId}) //nolint: gosimple + unwindHops = append(unwindHops, types.NewHop(trace.PortId, trace.ChannelId)) //nolint: gosimple } // Update message fields. diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 13b2dc72d2c..83449069878 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -268,7 +268,7 @@ func (suite *KeeperTestSuite) TestUnwindHops() { suite.Require().NoError(err, "got unexpected error from unwindHops") msg.SourceChannel = denom.Trace[0].PortId msg.SourcePort = denom.Trace[0].ChannelId - msg.Forwarding = types.NewForwarding(false, types.Hop{PortId: denom.Trace[1].PortId, ChannelId: denom.Trace[1].ChannelId}) + msg.Forwarding = types.NewForwarding(false, types.NewHop(denom.Trace[1].PortId, denom.Trace[1].ChannelId)) suite.Require().Equal(*msg, *modified, "expected msg and modified msg are different") }, }, @@ -285,9 +285,9 @@ func (suite *KeeperTestSuite) TestUnwindHops() { msg.SourceChannel = denom.Trace[0].PortId msg.SourcePort = denom.Trace[0].ChannelId msg.Forwarding = types.NewForwarding(false, - types.Hop{PortId: denom.Trace[3].PortId, ChannelId: denom.Trace[3].ChannelId}, - types.Hop{PortId: denom.Trace[2].PortId, ChannelId: denom.Trace[2].ChannelId}, - types.Hop{PortId: denom.Trace[1].PortId, ChannelId: denom.Trace[1].ChannelId}, + types.NewHop(denom.Trace[3].PortId, denom.Trace[3].ChannelId), + types.NewHop(denom.Trace[2].PortId, denom.Trace[2].ChannelId), + types.NewHop(denom.Trace[1].PortId, denom.Trace[1].ChannelId), ) suite.Require().Equal(*msg, *modified, "expected msg and modified msg are different") }, @@ -296,15 +296,15 @@ func (suite *KeeperTestSuite) TestUnwindHops() { "success - unwind hops are added to existing hops", func() { suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), denom) - msg.Forwarding = types.NewForwarding(true, types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-2"}) + msg.Forwarding = types.NewForwarding(true, types.NewHop(ibctesting.MockPort, "channel-2")) }, func(modified *types.MsgTransfer, err error) { suite.Require().NoError(err, "got unexpected error from unwindHops") msg.SourceChannel = denom.Trace[0].PortId msg.SourcePort = denom.Trace[0].ChannelId msg.Forwarding = types.NewForwarding(false, - types.Hop{PortId: denom.Trace[1].PortId, ChannelId: denom.Trace[1].ChannelId}, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(denom.Trace[1].PortId, denom.Trace[1].ChannelId), + types.NewHop(ibctesting.MockPort, "channel-2"), ) suite.Require().Equal(*msg, *modified, "expected msg and modified msg are different") }, diff --git a/modules/apps/transfer/keeper/relay_forwarding_test.go b/modules/apps/transfer/keeper/relay_forwarding_test.go index 67fe4c3ff54..05f18aadee5 100644 --- a/modules/apps/transfer/keeper/relay_forwarding_test.go +++ b/modules/apps/transfer/keeper/relay_forwarding_test.go @@ -65,10 +65,10 @@ func (suite *KeeperTestSuite) TestStoredForwardedPacketAndEscrowAfterFirstHop() coin := ibctesting.TestCoin sender := suite.chainA.SenderAccounts[0].SenderAccount receiver := suite.chainC.SenderAccounts[0].SenderAccount - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathBtoC.EndpointA.ChannelConfig.PortID, - ChannelId: pathBtoC.EndpointA.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathBtoC.EndpointA.ChannelConfig.PortID, + pathBtoC.EndpointA.ChannelID, + )) transferMsg := types.NewMsgTransfer( pathAtoB.EndpointA.ChannelConfig.PortID, @@ -130,10 +130,10 @@ func (suite *KeeperTestSuite) TestSuccessfulForward() { coinOnA := ibctesting.TestCoin sender := suite.chainA.SenderAccounts[0].SenderAccount receiver := suite.chainC.SenderAccounts[0].SenderAccount - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathBtoC.EndpointA.ChannelConfig.PortID, - ChannelId: pathBtoC.EndpointA.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathBtoC.EndpointA.ChannelConfig.PortID, + pathBtoC.EndpointA.ChannelID, + )) transferMsg := types.NewMsgTransfer( pathAtoB.EndpointA.ChannelConfig.PortID, @@ -244,10 +244,10 @@ func (suite *KeeperTestSuite) TestSuccessfulForwardWithMemo() { coinOnA := ibctesting.TestCoin sender := suite.chainA.SenderAccounts[0].SenderAccount receiver := suite.chainC.SenderAccounts[0].SenderAccount - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathBtoC.EndpointA.ChannelConfig.PortID, - ChannelId: pathBtoC.EndpointA.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathBtoC.EndpointA.ChannelConfig.PortID, + pathBtoC.EndpointA.ChannelID, + )) transferMsg := types.NewMsgTransfer( pathAtoB.EndpointA.ChannelConfig.PortID, @@ -383,10 +383,10 @@ func (suite *KeeperTestSuite) TestSuccessfulForwardWithNonCosmosAccAddress() { sender := suite.chainA.SenderAccounts[0].SenderAccount nonCosmosReceiver := "0x42069163Ac5919fD49e6A67e6c211E0C86397fa2" - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathBtoC.EndpointA.ChannelConfig.PortID, - ChannelId: pathBtoC.EndpointA.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathBtoC.EndpointA.ChannelConfig.PortID, + pathBtoC.EndpointA.ChannelID, + )) transferMsg := types.NewMsgTransfer( pathAtoB.EndpointA.ChannelConfig.PortID, @@ -498,10 +498,10 @@ func (suite *KeeperTestSuite) TestSuccessfulUnwind() { originalABalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), receiver.GetAddress(), coinOnA.Denom) - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathAtoB.EndpointB.ChannelConfig.PortID, - ChannelId: pathAtoB.EndpointB.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathAtoB.EndpointB.ChannelConfig.PortID, + pathAtoB.EndpointB.ChannelID, + )) transferMsg := types.NewMsgTransfer( pathBtoC.EndpointB.ChannelConfig.PortID, @@ -647,10 +647,10 @@ func (suite *KeeperTestSuite) TestAcknowledgementFailureWithMiddleChainAsNativeT sender := suite.chainC.SenderAccounts[0].SenderAccount receiver := suite.chainA.SenderAccounts[0].SenderAccount - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathAtoB.EndpointB.ChannelConfig.PortID, - ChannelId: pathAtoB.EndpointB.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathAtoB.EndpointB.ChannelConfig.PortID, + pathAtoB.EndpointB.ChannelID, + )) forwardTransfer := types.NewMsgTransfer( pathBtoC.EndpointB.ChannelConfig.PortID, @@ -780,10 +780,10 @@ func (suite *KeeperTestSuite) TestAcknowledgementFailureWithMiddleChainAsNotBein sender := suite.chainC.SenderAccounts[0].SenderAccount receiver := suite.chainA.SenderAccounts[0].SenderAccount - forwarding := types.NewForwarding(false, types.Hop{ - PortId: pathAtoB.EndpointB.ChannelConfig.PortID, - ChannelId: pathAtoB.EndpointB.ChannelID, - }) + forwarding := types.NewForwarding(false, types.NewHop( + pathAtoB.EndpointB.ChannelConfig.PortID, + pathAtoB.EndpointB.ChannelID, + )) forwardTransfer := types.NewMsgTransfer( pathBtoC.EndpointB.ChannelConfig.PortID, @@ -900,12 +900,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() { originalABalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), sender.GetAddress(), coin.Denom) forwarding := types.Forwarding{ - Hops: []types.Hop{ - { - PortId: pathBtoC.EndpointA.ChannelConfig.PortID, - ChannelId: pathBtoC.EndpointA.ChannelID, - }, - }, + Hops: []types.Hop{types.NewHop(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID)}, } transferMsg := types.NewMsgTransfer( @@ -1049,8 +1044,8 @@ func (suite *KeeperTestSuite) TestForwardingWithMoreThanOneHop() { receiver := suite.chainD.SenderAccounts[0].SenderAccount forwarding := types.NewForwarding(false, - types.Hop{PortId: pathBtoC.EndpointA.ChannelConfig.PortID, ChannelId: pathBtoC.EndpointA.ChannelID}, - types.Hop{PortId: pathCtoD.EndpointA.ChannelConfig.PortID, ChannelId: pathCtoD.EndpointA.ChannelID}, + types.NewHop(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID), + types.NewHop(pathCtoD.EndpointA.ChannelConfig.PortID, pathCtoD.EndpointA.ChannelID), ) transferMsg := types.NewMsgTransfer( diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index e9824c05ace..7617f7824c1 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -97,10 +97,10 @@ func (suite *KeeperTestSuite) TestSendTransfer() { "successful transfer with non-empty forwarding hops and ics20-2", func() { expEscrowAmount = sdkmath.NewInt(100) - forwarding = types.NewForwarding(false, types.Hop{ - PortId: path.EndpointA.ChannelConfig.PortID, - ChannelId: path.EndpointA.ChannelID, - }) + forwarding = types.NewForwarding(false, types.NewHop( + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + )) }, nil, }, @@ -178,10 +178,10 @@ func (suite *KeeperTestSuite) TestSendTransfer() { channel.Version = types.V1 }) - forwarding = types.NewForwarding(false, types.Hop{ - PortId: path.EndpointA.ChannelConfig.PortID, - ChannelId: path.EndpointA.ChannelID, - }) + forwarding = types.NewForwarding(false, types.NewHop( + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + )) }, ibcerrors.ErrInvalidRequest, }, diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index 7af7d339522..9db76e10ad3 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -50,6 +50,11 @@ func (fpd ForwardingPacketData) Validate() error { return nil } +// NewHop creates a Hop with the given port ID and channel ID. +func NewHop(portID, channelID string) Hop { + return Hop{portID, channelID} +} + // Validate performs a basic validation of the Hop fields. func (h Hop) Validate() error { if err := host.PortIdentifierValidator(h.PortId); err != nil { diff --git a/modules/apps/transfer/types/forwarding_test.go b/modules/apps/transfer/types/forwarding_test.go index 357291ee735..07deaa62527 100644 --- a/modules/apps/transfer/types/forwarding_test.go +++ b/modules/apps/transfer/types/forwarding_test.go @@ -10,10 +10,7 @@ import ( ibctesting "github.com/cosmos/ibc-go/v8/testing" ) -var validHop = types.Hop{ - PortId: types.PortID, - ChannelId: ibctesting.FirstChannelID, -} +var validHop = types.NewHop(types.PortID, ibctesting.FirstChannelID) func TestForwarding_Validate(t *testing.T) { tests := []struct { @@ -45,10 +42,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with too short hop port ID", types.NewForwarding( false, - types.Hop{ - PortId: invalidShortPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidShortPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -56,10 +50,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with too long hop port ID", types.NewForwarding( false, - types.Hop{ - PortId: invalidLongPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidLongPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -67,10 +58,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with non-alpha hop port ID", types.NewForwarding( false, - types.Hop{ - PortId: invalidPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -78,10 +66,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with too long hop channel ID", types.NewForwarding( false, - types.Hop{ - PortId: types.PortID, - ChannelId: invalidLongChannel, - }, + types.NewHop(types.PortID, invalidLongChannel), ), types.ErrInvalidForwarding, }, @@ -89,10 +74,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with too short hop channel ID", types.NewForwarding( false, - types.Hop{ - PortId: types.PortID, - ChannelId: invalidShortChannel, - }, + types.NewHop(types.PortID, invalidShortChannel), ), types.ErrInvalidForwarding, }, @@ -100,10 +82,7 @@ func TestForwarding_Validate(t *testing.T) { "invalid forwarding with non-alpha hop channel ID", types.NewForwarding( false, - types.Hop{ - PortId: types.PortID, - ChannelId: invalidChannel, - }, + types.NewHop(types.PortID, invalidChannel), ), types.ErrInvalidForwarding, }, @@ -174,10 +153,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with too short hop port ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: invalidShortPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidShortPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -185,10 +161,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with too long hop port ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: invalidLongPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidLongPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -196,10 +169,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with non-alpha hop port ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: invalidPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidPort, ibctesting.FirstChannelID), ), types.ErrInvalidForwarding, }, @@ -207,10 +177,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with too long hop channel ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidLongChannel, - }, + types.NewHop(types.PortID, invalidLongChannel), ), types.ErrInvalidForwarding, }, @@ -218,10 +185,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with too short hop channel ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidShortChannel, - }, + types.NewHop(types.PortID, invalidShortChannel), ), types.ErrInvalidForwarding, }, @@ -229,10 +193,7 @@ func TestForwardingPacketData_Validate(t *testing.T) { "invalid forwarding with non-alpha hop channel ID", types.NewForwardingPacketData( "", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidChannel, - }, + types.NewHop(types.PortID, invalidChannel), ), types.ErrInvalidForwarding, }, @@ -266,50 +227,32 @@ func TestValidateHop(t *testing.T) { }, { "invalid hop with too short port ID", - types.Hop{ - PortId: invalidShortPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidShortPort, ibctesting.FirstChannelID), host.ErrInvalidID, }, { "invalid hop with too long port ID", - types.Hop{ - PortId: invalidLongPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidLongPort, ibctesting.FirstChannelID), host.ErrInvalidID, }, { "invalid hop with non-alpha port ID", - types.Hop{ - PortId: invalidPort, - ChannelId: ibctesting.FirstChannelID, - }, + types.NewHop(invalidPort, ibctesting.FirstChannelID), host.ErrInvalidID, }, { "invalid hop with too long channel ID", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidLongChannel, - }, + types.NewHop(types.PortID, invalidLongChannel), host.ErrInvalidID, }, { "invalid hop with too short channel ID", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidShortChannel, - }, + types.NewHop(types.PortID, invalidShortChannel), host.ErrInvalidID, }, { "invalid hop with non-alpha channel ID", - types.Hop{ - PortId: types.PortID, - ChannelId: invalidChannel, - }, + types.NewHop(types.PortID, invalidChannel), host.ErrInvalidID, }, } @@ -333,10 +276,7 @@ func TestValidateHop(t *testing.T) { func generateHops(n int) []types.Hop { hops := make([]types.Hop, n) for i := 0; i < n; i++ { - hops[i] = types.Hop{ - PortId: types.PortID, - ChannelId: ibctesting.FirstChannelID, - } + hops[i] = types.NewHop(types.PortID, ibctesting.FirstChannelID) } return hops } diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 2fea4f4a5b2..4d300f3f5ac 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -84,8 +84,8 @@ func TestMsgTransferValidation(t *testing.T) { {"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}, {"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.Hop{PortId: invalidPort, ChannelId: validChannel})), types.ErrInvalidForwarding}, - {"invalid forwarding info channel", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, types.Hop{PortId: validPort, ChannelId: invalidChannel})), types.ErrInvalidForwarding}, + {"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}, {"invalid forwarding info too many hops", types.NewMsgTransfer(validPort, validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, generateHops(types.MaximumNumberOfForwardingHops+1)...)), types.ErrInvalidForwarding}, {"invalid portID when forwarding is set but unwind is not", types.NewMsgTransfer("", validChannel, coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, validHop)), host.ErrInvalidID}, {"invalid channelID when forwarding is set but unwind is not", types.NewMsgTransfer(validPort, "", coins, sender, receiver, clienttypes.ZeroHeight(), 100, "", types.NewForwarding(false, validHop)), host.ErrInvalidID}, diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 6a70b8d72a3..ad348cfe450 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -421,10 +421,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { "", types.NewForwardingPacketData( "", - types.Hop{ - PortId: invalidPort, - ChannelId: "channel-1", - }, + types.NewHop(invalidPort, "channel-1"), ), ), types.ErrInvalidForwarding, @@ -443,10 +440,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { "", types.NewForwardingPacketData( "", - types.Hop{ - PortId: "transfer", - ChannelId: invalidChannel, - }, + types.NewHop("transfer", invalidChannel), ), ), types.ErrInvalidForwarding, diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index 20554327cf1..773988b0236 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -284,12 +284,12 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { { "success: allowed forwarding hops", func() { - msgTransfer.Forwarding = types.NewForwarding(false, types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-1"}, types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-2"}) + msgTransfer.Forwarding = types.NewForwarding(false, types.NewHop(ibctesting.MockPort, "channel-1"), types.NewHop(ibctesting.MockPort, "channel-2")) transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ { Hops: []types.Hop{ - {PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - {PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), }, }, } @@ -305,8 +305,8 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ { Hops: []types.Hop{ - {PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - {PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), }, }, } @@ -394,15 +394,15 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { "failure: allowed forwarding hops contains more hops", func() { msgTransfer.Forwarding = types.NewForwarding(false, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-2"}, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-3"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), + types.NewHop(ibctesting.MockPort, "channel-3"), ) transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ { Hops: []types.Hop{ - {PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - {PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), }, }, } @@ -416,14 +416,14 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { "failure: allowed forwarding hops contains one different hop", func() { msgTransfer.Forwarding = types.NewForwarding(false, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - types.Hop{PortId: "3", ChannelId: "channel-3"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop("3", "channel-3"), ) transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ { Hops: []types.Hop{ - {PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - {PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), }, }, } @@ -437,7 +437,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { "failure: allowed forwarding hops is empty but hops are present", func() { msgTransfer.Forwarding = types.NewForwarding(false, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-1"}, + types.NewHop(ibctesting.MockPort, "channel-1"), ) }, func(res authz.AcceptResponse, err error) { @@ -449,14 +449,14 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { "failure: order of hops is different", func() { msgTransfer.Forwarding = types.NewForwarding(false, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-1"}, - types.Hop{PortId: ibctesting.MockPort, ChannelId: "channel-2"}, + types.NewHop(ibctesting.MockPort, "channel-1"), + types.NewHop(ibctesting.MockPort, "channel-2"), ) transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ { Hops: []types.Hop{ - {PortId: ibctesting.MockPort, ChannelId: "channel-2"}, - {PortId: ibctesting.MockPort, ChannelId: "channel-1"}, + types.NewHop(ibctesting.MockPort, "channel-2"), + types.NewHop(ibctesting.MockPort, "channel-1"), }, }, } @@ -577,7 +577,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { func() { transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ {Hops: []types.Hop{validHop}}, - {Hops: []types.Hop{{types.PortID, "channel-1"}}}, + {Hops: []types.Hop{types.NewHop(types.PortID, "channel-1")}}, } }, true, @@ -650,7 +650,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { func() { transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ {Hops: []types.Hop{validHop}}, - {Hops: []types.Hop{{"invalid/port", ibctesting.FirstChannelID}}}, + {Hops: []types.Hop{types.NewHop("invalid/port", ibctesting.FirstChannelID)}}, } }, false, @@ -660,7 +660,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { func() { transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{ {Hops: []types.Hop{validHop}}, - {Hops: []types.Hop{{types.PortID, "invalid/channel"}}}, + {Hops: []types.Hop{types.NewHop(types.PortID, "invalid/channel")}}, } }, false,