From 79bb3df3ca166e95b6d0a9d5d4a859f1ac79405f Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sat, 24 Sep 2022 13:56:27 -0600 Subject: [PATCH 1/8] Return sequence from new private sendTransfer method --- modules/apps/transfer/keeper/relay.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 0f3670bdb69..c2e22c76572 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -60,7 +60,7 @@ func (k Keeper) SendTransfer( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, ) error { - return k.sendTransfer( + _, err := k.sendTransfer( ctx, sourcePort, sourceChannel, @@ -70,6 +70,7 @@ func (k Keeper) SendTransfer( timeoutHeight, timeoutTimestamp, ) + return err } // sendTransfer handles transfer sending logic. @@ -82,18 +83,18 @@ func (k Keeper) sendTransfer( receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, -) error { +) (uint64, error) { if !k.GetSendEnabled(ctx) { - return types.ErrSendDisabled + return 0, types.ErrSendDisabled } if k.bankKeeper.BlockedAddr(sender) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) + return 0, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() @@ -102,7 +103,7 @@ func (k Keeper) sendTransfer( // get the next sequence sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( channeltypes.ErrSequenceSendNotFound, "source port: %s, source channel: %s", sourcePort, sourceChannel, ) @@ -112,7 +113,7 @@ func (k Keeper) sendTransfer( // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { - return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic @@ -125,7 +126,7 @@ func (k Keeper) sendTransfer( if strings.HasPrefix(token.Denom, "ibc/") { fullDenomPath, err = k.DenomPathFromHash(ctx, token.Denom) if err != nil { - return err + return 0, err } } @@ -148,7 +149,7 @@ func (k Keeper) sendTransfer( if err := k.bankKeeper.SendCoins( ctx, sender, escrowAddress, sdk.NewCoins(token), ); err != nil { - return err + return 0, err } } else { @@ -158,7 +159,7 @@ func (k Keeper) sendTransfer( if err := k.bankKeeper.SendCoinsFromAccountToModule( ctx, sender, types.ModuleName, sdk.NewCoins(token), ); err != nil { - return err + return 0, err } if err := k.bankKeeper.BurnCoins( @@ -187,7 +188,7 @@ func (k Keeper) sendTransfer( ) if err := k.ics4Wrapper.SendPacket(ctx, channelCap, packet); err != nil { - return err + return 0, err } defer func() { @@ -206,7 +207,7 @@ func (k Keeper) sendTransfer( ) }() - return nil + return sequence, nil } // OnRecvPacket processes a cross chain fungible token transfer. If the From 235e059e36fcf9e49142afd4e96bc91c7bb96287 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 25 Sep 2022 21:45:15 -0600 Subject: [PATCH 2/8] Update with strategy of #1969 --- .../adr-015-ibc-packet-receiver.md | 2 +- docs/ibc/proto-docs.md | 5 + .../apps/transfer/keeper/mbt_relay_test.go | 2 +- modules/apps/transfer/keeper/msg_server.go | 7 +- modules/apps/transfer/keeper/relay_test.go | 2 +- modules/apps/transfer/types/tx.pb.go | 99 +++++++++++++------ proto/ibc/applications/transfer/v1/tx.proto | 5 +- 7 files changed, 84 insertions(+), 38 deletions(-) diff --git a/docs/architecture/adr-015-ibc-packet-receiver.md b/docs/architecture/adr-015-ibc-packet-receiver.md index 26f9bdecc88..dd131ac6453 100644 --- a/docs/architecture/adr-015-ibc-packet-receiver.md +++ b/docs/architecture/adr-015-ibc-packet-receiver.md @@ -239,7 +239,7 @@ func NewHandler(k Keeper) Handler { } func handleMsgTransfer(ctx Context, k Keeper, msg MsgTransfer) Result { - err := k.SendTransfer(ctx,msg.PortID, msg.ChannelID, msg.Amount, msg.Sender, msg.Receiver) + _, err := k.SendTransfer(ctx,msg.PortID, msg.ChannelID, msg.Amount, msg.Sender, msg.Receiver) if err != nil { return sdk.ResultFromError(err) } diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 16bb144132e..527643f9d7f 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2267,6 +2267,11 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf MsgTransferResponse defines the Msg/Transfer response type. +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sequence` | [uint64](#uint64) | | sequence number of the packet on the channel. | + + diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 83a7be7c0a7..74633dc8b45 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -338,7 +338,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { if !ok { panic("MBT failed to parse amount from string") } - err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( + _, err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( suite.chainB.GetContext(), tc.packet.SourcePort, tc.packet.SourceChannel, diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 9764138b295..622ce2a404b 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -19,9 +19,10 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. return nil, err } - if err := k.sendTransfer( + sequence, err := k.sendTransfer( ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, - ); err != nil { + ) + if err != nil { return nil, err } @@ -39,5 +40,5 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. ), }) - return &types.MsgTransferResponse{}, nil + return &types.MsgTransferResponse{Sequence: sequence}, nil } diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index c467459c5c3..32a0d03fd0e 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -140,7 +140,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().NoError(err) // message committed } - err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( + _, err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, sender, suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, ) diff --git a/modules/apps/transfer/types/tx.pb.go b/modules/apps/transfer/types/tx.pb.go index 26df01dcc91..4a9cf75545e 100644 --- a/modules/apps/transfer/types/tx.pb.go +++ b/modules/apps/transfer/types/tx.pb.go @@ -87,6 +87,8 @@ var xxx_messageInfo_MsgTransfer proto.InternalMessageInfo // MsgTransferResponse defines the Msg/Transfer response type. type MsgTransferResponse struct { + // sequence number of the packet on the channel. + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` } func (m *MsgTransferResponse) Reset() { *m = MsgTransferResponse{} } @@ -122,6 +124,13 @@ func (m *MsgTransferResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgTransferResponse proto.InternalMessageInfo +func (m *MsgTransferResponse) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + func init() { proto.RegisterType((*MsgTransfer)(nil), "ibc.applications.transfer.v1.MsgTransfer") proto.RegisterType((*MsgTransferResponse)(nil), "ibc.applications.transfer.v1.MsgTransferResponse") @@ -132,38 +141,39 @@ func init() { } var fileDescriptor_7401ed9bed2f8e09 = []byte{ - // 494 bytes of a gzipped FileDescriptorProto + // 506 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x6d, 0x92, 0x86, 0x70, 0x51, 0x2b, 0x30, 0xb4, 0x72, 0xa3, 0x62, 0x47, 0x96, 0x90, - 0xc2, 0xc0, 0x9d, 0x5c, 0x04, 0x95, 0x3a, 0xa1, 0x74, 0x81, 0xa1, 0x12, 0x58, 0x9d, 0x58, 0x8a, - 0x7d, 0x3d, 0x9c, 0x13, 0xf1, 0x3d, 0xeb, 0xee, 0x62, 0xd1, 0x6f, 0xc0, 0xc8, 0x47, 0xe8, 0xcc, - 0x27, 0xe9, 0xd8, 0x91, 0x29, 0x42, 0xc9, 0xc2, 0x9c, 0x4f, 0x80, 0xce, 0xbe, 0x84, 0x64, 0x41, - 0x4c, 0xf6, 0x7b, 0xff, 0xdf, 0xbb, 0xbf, 0xde, 0xbd, 0x77, 0xe8, 0x19, 0xcf, 0x28, 0x49, 0xcb, - 0x72, 0xc2, 0x69, 0xaa, 0x39, 0x08, 0x45, 0xb4, 0x4c, 0x85, 0xfa, 0xcc, 0x24, 0xa9, 0x62, 0xa2, - 0xbf, 0xe2, 0x52, 0x82, 0x06, 0xef, 0x88, 0x67, 0x14, 0x6f, 0x62, 0x78, 0x85, 0xe1, 0x2a, 0xee, - 0x3f, 0xc9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 0xe9, 0x7e, 0xbb, 0xf6, 0xad, 0xdf, 0xd7, 0xbe, + 0x15, 0x84, 0xe4, 0xe1, 0xc6, 0xac, 0x22, 0x50, 0x39, 0x4a, 0x05, 0xc6, 0xa9, 0x82, 0x2f, 0x53, + 0x90, 0x1c, 0xaa, 0x81, 0xb5, 0xa3, 0x75, 0x7c, 0x84, 0xa4, 0x75, 0xa6, 0x52, 0x67, 0x4c, 0xba, + 0xeb, 0x11, 0x3f, 0xa3, 0xff, 0x5a, 0x34, 0xba, 0xa1, 0xd0, 0x0f, 0xff, 0x1b, 0x5d, 0x7d, 0xcc, + 0xe8, 0xfd, 0xcd, 0xdc, 0xb3, 0x6f, 0xe7, 0x9e, 0xfd, 0x6b, 0xee, 0xd9, 0xdf, 0x17, 0x9e, 0x75, + 0xbb, 0xf0, 0xac, 0x9f, 0x0b, 0xcf, 0xfa, 0x70, 0x9c, 0x0a, 0x3d, 0x9e, 0x26, 0x94, 0x63, 0xc6, + 0x9a, 0xb5, 0x15, 0x09, 0x7f, 0x9e, 0x22, 0x2b, 0x5f, 0xb1, 0x0c, 0x2f, 0xa7, 0x13, 0x50, 0xe6, + 0x99, 0x6c, 0x3c, 0x0f, 0x7d, 0x95, 0x83, 0x4a, 0x3a, 0xd5, 0xaa, 0xbe, 0xf8, 0x13, 0x00, 0x00, + 0xff, 0xff, 0xca, 0x82, 0x70, 0x0f, 0x48, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -344,6 +354,11 @@ func (m *MsgTransferResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -396,6 +411,9 @@ func (m *MsgTransferResponse) Size() (n int) { } var l int _ = l + if m.Sequence != 0 { + n += 1 + sovTx(uint64(m.Sequence)) + } return n } @@ -697,6 +715,25 @@ func (m *MsgTransferResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgTransferResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index 33b19655b47..0334eb88230 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -41,4 +41,7 @@ message MsgTransfer { } // MsgTransferResponse defines the Msg/Transfer response type. -message MsgTransferResponse {} +message MsgTransferResponse { + // sequence number of the packet on the channel. + uint64 sequence = 1; +} From 23d4671ad6a6806ef65f4c1ccd470113bc896562 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Mon, 26 Sep 2022 09:21:41 -0600 Subject: [PATCH 3/8] Update proto/ibc/applications/transfer/v1/tx.proto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- proto/ibc/applications/transfer/v1/tx.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index 0334eb88230..d0bd3e98246 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -42,6 +42,6 @@ message MsgTransfer { // MsgTransferResponse defines the Msg/Transfer response type. message MsgTransferResponse { - // sequence number of the packet on the channel. + // sequence number of the transfer packet sent uint64 sequence = 1; } From 752488b6db98d5325c3b28df591fbe984cda7094 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Mon, 26 Sep 2022 09:43:19 -0600 Subject: [PATCH 4/8] Add breaking change to CHANGELOG. Add non-zero assertion for sequence in relay_test. --- CHANGELOG.md | 1 + modules/apps/transfer/keeper/relay_test.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a1e72ecb14..3893eb7e2d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (apps/27-interchain-accounts)[\#2302](https://github.com/cosmos/ibc-go/pull/2302) Handle unwrapping of channel version in interchain accounts channel reopening handshake flow. The `host` submodule `Keeper` now requires an `ICS4Wrapper` similarly to the `controller` submodule. +* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Modified `SendTransfer` signature to return sequence in the case of success. ### State Machine Breaking diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 32a0d03fd0e..e637a326715 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -140,12 +140,13 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().NoError(err) // message committed } - _, err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( + sequence, err := suite.chainA.GetSimApp().TransferKeeper.SendTransfer( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, sender, suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, ) if tc.expPass { + suite.Require().Greater(sequence, uint64(0)) suite.Require().NoError(err) } else { suite.Require().Error(err) From 3700eb88fa7d114a3f2d7730d464b07ccbea3a17 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 27 Sep 2022 09:00:26 -0600 Subject: [PATCH 5/8] Update modules/apps/transfer/keeper/relay_test.go Co-authored-by: Carlos Rodriguez --- modules/apps/transfer/keeper/relay_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index e637a326715..c062ac48123 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -149,6 +149,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().Greater(sequence, uint64(0)) suite.Require().NoError(err) } else { + suite.Require().Equal(uint64(0), sequence) suite.Require().Error(err) } }) From a08c8419e617459dd65c46b935bd32478c5075e2 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 27 Sep 2022 09:01:44 -0600 Subject: [PATCH 6/8] Update godoc to mention sequence return value --- CHANGELOG.md | 2 +- docs/architecture/adr-015-ibc-packet-receiver.md | 2 +- modules/apps/transfer/keeper/mbt_relay_test.go | 2 +- modules/apps/transfer/keeper/relay_test.go | 4 +--- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3893eb7e2d1..9e8b008f291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (apps/27-interchain-accounts)[\#2302](https://github.com/cosmos/ibc-go/pull/2302) Handle unwrapping of channel version in interchain accounts channel reopening handshake flow. The `host` submodule `Keeper` now requires an `ICS4Wrapper` similarly to the `controller` submodule. -* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Modified `SendTransfer` signature to return sequence in the case of success. ### State Machine Breaking @@ -104,6 +103,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (apps/27-interchain-accounts) [\#2251](https://github.com/cosmos/ibc-go/pull/2251) Adding `msgServer` struct to controller submodule that embeds the `Keeper` struct. * (apps/27-interchain-accounts) [\#2297](https://github.com/cosmos/ibc-go/pull/2297) Adding cli command to generate ICS27 packet data. * (modules/core/keeper) [\#1728](https://github.com/cosmos/ibc-go/pull/2399) Updated channel callback errors to include portID & channelID for better identification of errors. +* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Adding `sequence` to `MsgTransferResponse`. ### Features diff --git a/docs/architecture/adr-015-ibc-packet-receiver.md b/docs/architecture/adr-015-ibc-packet-receiver.md index dd131ac6453..26f9bdecc88 100644 --- a/docs/architecture/adr-015-ibc-packet-receiver.md +++ b/docs/architecture/adr-015-ibc-packet-receiver.md @@ -239,7 +239,7 @@ func NewHandler(k Keeper) Handler { } func handleMsgTransfer(ctx Context, k Keeper, msg MsgTransfer) Result { - _, err := k.SendTransfer(ctx,msg.PortID, msg.ChannelID, msg.Amount, msg.Sender, msg.Receiver) + err := k.SendTransfer(ctx,msg.PortID, msg.ChannelID, msg.Amount, msg.Sender, msg.Receiver) if err != nil { return sdk.ResultFromError(err) } diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 74633dc8b45..83a7be7c0a7 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -338,7 +338,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { if !ok { panic("MBT failed to parse amount from string") } - _, err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( + err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( suite.chainB.GetContext(), tc.packet.SourcePort, tc.packet.SourceChannel, diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index c062ac48123..c467459c5c3 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -140,16 +140,14 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().NoError(err) // message committed } - sequence, err := suite.chainA.GetSimApp().TransferKeeper.SendTransfer( + err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, sender, suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, ) if tc.expPass { - suite.Require().Greater(sequence, uint64(0)) suite.Require().NoError(err) } else { - suite.Require().Equal(uint64(0), sequence) suite.Require().Error(err) } }) From 2c48b42ae2ad0e5e46f839f47abc101845a138e7 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 4 Oct 2022 09:04:43 -0600 Subject: [PATCH 7/8] Assertions for sequence. Move changelog to state machine breaking --- CHANGELOG.md | 3 ++- modules/apps/transfer/keeper/msg_server_test.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e51bac40e41..557ab8ffd7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Adding `sequence` to `MsgTransferResponse`. + ### Improvements * (modules/light-clients/07-tendermint) [\#1713](https://github.com/cosmos/ibc-go/pull/1713) Allow client upgrade proposals to update `TrustingPeriod`. See ADR-026 for context. @@ -94,7 +96,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (light-clients/06-solomachine) Moving `verifyMisbehaviour` function from update.go to misbehaviour_handle.go. * (apps/27-interchain-accounts) [\#2297](https://github.com/cosmos/ibc-go/pull/2297) Adding cli command to generate ICS27 packet data. * (modules/core/keeper) [\#1728](https://github.com/cosmos/ibc-go/pull/2399) Updated channel callback errors to include portID & channelID for better identification of errors. -* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Adding `sequence` to `MsgTransferResponse`. ### Features diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 724c9222946..68f54756c22 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -61,9 +61,11 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tc.expPass { + suite.Require().NotEqual(res.Sequence, uint64(0)) suite.Require().NoError(err) suite.Require().NotNil(res) } else { + suite.Require().Equal(res.Sequence, uint64(0)) suite.Require().Error(err) suite.Require().Nil(res) } From f9ac4b3361a861c09f01a5043029265f70790904 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 4 Oct 2022 17:24:34 -0600 Subject: [PATCH 8/8] Fix NPE --- modules/apps/transfer/keeper/msg_server_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 68f54756c22..fee7ba71b5d 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -65,7 +65,6 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { suite.Require().NoError(err) suite.Require().NotNil(res) } else { - suite.Require().Equal(res.Sequence, uint64(0)) suite.Require().Error(err) suite.Require().Nil(res) }