From 0a2297eabe287d38723ab8213d5256ce34d2bb2d Mon Sep 17 00:00:00 2001 From: sontrinh16 <48055119+sontrinh16@users.noreply.github.com> Date: Sat, 26 Nov 2022 00:55:07 +0700 Subject: [PATCH] Update RecordsKeeper.Transfer to use msgTransferResponse sequence number (#376) Co-authored-by: Son Trinh --- x/records/keeper/keeper.go | 20 ++------------------ x/records/keeper/transfer_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/x/records/keeper/keeper.go b/x/records/keeper/keeper.go index 25d747137e..b8ce54010d 100644 --- a/x/records/keeper/keeper.go +++ b/x/records/keeper/keeper.go @@ -3,7 +3,6 @@ package keeper import ( "fmt" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" "github.com/tendermint/tendermint/libs/log" @@ -11,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -78,25 +76,11 @@ func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capabilit func (k Keeper) Transfer(ctx sdk.Context, msg *ibctypes.MsgTransfer, depositRecord types.DepositRecord) error { goCtx := sdk.WrapSDKContext(ctx) - - // because TransferKeeper.Transfer doesn't return a sequence number, we need to fetch it manually - // the sequence number isn't actually incremented here, that happens in `SendPacket`, which is triggered - // by calling `Transfer` - // see: https://github.com/cosmos/ibc-go/blob/48a6ae512b4ea42c29fdf6c6f5363f50645591a2/modules/core/04-channel/keeper/packet.go#L125 - sequence, found := k.IBCKeeper.ChannelKeeper.GetNextSequenceSend(ctx, msg.SourcePort, msg.SourceChannel) - if !found { - return sdkerrors.Wrapf( - channeltypes.ErrSequenceSendNotFound, - "source port: %s, source channel: %s", msg.SourcePort, msg.SourceChannel, - ) - } - - // trigger transfer - _, err := k.TransferKeeper.Transfer(goCtx, msg) + msgTransferResponse, err := k.TransferKeeper.Transfer(goCtx, msg) if err != nil { return err } - + sequence := msgTransferResponse.Sequence // add callback data transferCallback := types.TransferCallback{ DepositRecordId: depositRecord.Id, diff --git a/x/records/keeper/transfer_test.go b/x/records/keeper/transfer_test.go index 607dcca203..2f082393a7 100644 --- a/x/records/keeper/transfer_test.go +++ b/x/records/keeper/transfer_test.go @@ -55,3 +55,19 @@ func (s *KeeperTestSuite) TestTransfer_Successful() { s.Require().True(found) s.Require().Equal(record.Status, recordtypes.DepositRecord_TRANSFER_IN_PROGRESS, "deposit record status should be TRANSFER_IN_PROGRESS") } + +func (s *KeeperTestSuite) TestSequence_Equal() { + tc := s.SetupTransfer() + goCtx := sdk.WrapSDKContext(s.Ctx()) + sequence, found := s.App.IBCKeeper.ChannelKeeper.GetNextSequenceSend(s.Ctx(), + tc.transferMsg.SourcePort, tc.transferMsg.SourceChannel) + s.Require().True(found) + + msgTransferResponse, err := s.App.TransferKeeper.Transfer(goCtx, &tc.transferMsg) + s.Require().NoError(err) + + checkSequence := msgTransferResponse.Sequence + + // Confirm msg sequence are equal to next sequence + s.Require().Equal(checkSequence, sequence, "sequence should be equal") +}