diff --git a/modules/apps/transfer/v2/keeper/msg_server_test.go b/modules/apps/transfer/v2/keeper/msg_server_test.go index 64d47543ce5..9dcaba67e89 100644 --- a/modules/apps/transfer/v2/keeper/msg_server_test.go +++ b/modules/apps/transfer/v2/keeper/msg_server_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "bytes" "time" sdkmath "cosmossdk.io/math" @@ -13,6 +14,7 @@ import ( channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" ) // TestMsgSendPacketTransfer tests the MsgSendPacket rpc handler for the transfer v2 application. @@ -130,11 +132,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() { { "failure: receive is disabled", func() { - expectedAck.AcknowledgementResults[0].RecvPacketResult = channeltypesv2.RecvPacketResult{ - Status: channeltypesv2.PacketStatus_Failure, - Acknowledgement: channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement(), - } - + expectedAck.AppAcknowledgements[0] = channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement() suite.chainB.GetSimApp().TransferKeeperV2.SetParams(suite.chainB.GetContext(), transfertypes.Params{ ReceiveEnabled: false, @@ -174,16 +172,8 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() { suite.Require().NoError(err) // by default, we assume a successful acknowledgement will be written. - expectedAck = channeltypesv2.Acknowledgement{AcknowledgementResults: []channeltypesv2.AcknowledgementResult{ - { - AppName: transfertypes.ModuleName, - RecvPacketResult: channeltypesv2.RecvPacketResult{ - Status: channeltypesv2.PacketStatus_Success, - Acknowledgement: channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), - }, - }, - }} - + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + expectedAck = channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} tc.malleate() err = path.EndpointB.MsgRecvPacket(packet) @@ -208,7 +198,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() { var expectedBalance sdk.Coin // on a successful ack we expect the full amount to be transferred - if expectedAck.AcknowledgementResults[0].RecvPacketResult.Status == channeltypesv2.PacketStatus_Success { + if bytes.Equal(expectedAck.AppAcknowledgements[0], ackBytes) { expectedBalance = sdk.NewCoin(denom.IBCDenom(), ibctesting.DefaultCoinAmount) } else { // otherwise the tokens do not make it to the address. @@ -247,7 +237,7 @@ func (suite *KeeperTestSuite) TestMsgAckPacketTransfer() { { "failure: proof verification failure", func() { - expectedAck.AcknowledgementResults[0].RecvPacketResult.Acknowledgement = channeltypes.NewResultAcknowledgement([]byte{byte(2)}).Acknowledgement() + expectedAck.AppAcknowledgements[0] = mockv2.MockFailRecvPacketResult.Acknowledgement }, commitmenttypes.ErrInvalidProof, false, @@ -255,10 +245,7 @@ func (suite *KeeperTestSuite) TestMsgAckPacketTransfer() { { "failure: escrowed tokens are refunded", func() { - expectedAck.AcknowledgementResults[0].RecvPacketResult = channeltypesv2.RecvPacketResult{ - Status: channeltypesv2.PacketStatus_Failure, - Acknowledgement: channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement(), - } + expectedAck.AppAcknowledgements[0] = channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement() }, nil, true, @@ -306,16 +293,8 @@ func (suite *KeeperTestSuite) TestMsgAckPacketTransfer() { err = path.EndpointB.MsgRecvPacket(packet) suite.Require().NoError(err) - expectedAck = channeltypesv2.Acknowledgement{AcknowledgementResults: []channeltypesv2.AcknowledgementResult{ - { - AppName: transfertypes.ModuleName, - RecvPacketResult: channeltypesv2.RecvPacketResult{ - Status: channeltypesv2.PacketStatus_Success, - Acknowledgement: channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), - }, - }, - }} - + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + expectedAck = channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} tc.malleate() err = path.EndpointA.MsgAcknowledgePacket(packet, expectedAck) @@ -324,7 +303,7 @@ func (suite *KeeperTestSuite) TestMsgAckPacketTransfer() { if expPass { suite.Require().NoError(err) - if expectedAck.AcknowledgementResults[0].RecvPacketResult.Status == channeltypesv2.PacketStatus_Success { + if bytes.Equal(expectedAck.AppAcknowledgements[0], ackBytes) { // tokens remain escrowed for _, t := range tokens { escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) @@ -466,15 +445,8 @@ func (suite *KeeperTestSuite) TestV2RetainsFungibility() { }, } - successfulAck := channeltypesv2.Acknowledgement{AcknowledgementResults: []channeltypesv2.AcknowledgementResult{ - { - AppName: transfertypes.ModuleName, - RecvPacketResult: channeltypesv2.RecvPacketResult{ - Status: channeltypesv2.PacketStatus_Success, - Acknowledgement: channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), - }, - }, - }} + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + successfulAck := channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} originalAmount, ok := sdkmath.NewIntFromString(ibctesting.DefaultGenesisAccBalance) suite.Require().True(ok) diff --git a/modules/core/04-channel/v2/keeper/msg_server.go b/modules/core/04-channel/v2/keeper/msg_server.go index a268094c505..f4c2dc446a1 100644 --- a/modules/core/04-channel/v2/keeper/msg_server.go +++ b/modules/core/04-channel/v2/keeper/msg_server.go @@ -180,7 +180,7 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*typ // TODO: store the packet for async applications to access if required. defer telemetry.ReportRecvPacket(msg.Packet) - + sdkCtx.Logger().Info("receive packet callback succeeded", "source-channel", msg.Packet.SourceChannel, "dest-channel", msg.Packet.DestinationChannel, "result", types.SUCCESS.String()) return &types.MsgRecvPacketResponse{Result: types.SUCCESS}, nil } @@ -212,7 +212,7 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *types.MsgAcknowledgem for i, pd := range msg.Packet.Payloads { cbs := k.Router.Route(pd.SourcePort) ack := msg.Acknowledgement.AppAcknowledgements[i] - err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, ack, relayer) + err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, ack, pd, relayer) if err != nil { return nil, errorsmod.Wrapf(err, "failed OnAcknowledgementPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, msg.Packet.SourceChannel, msg.Packet.DestinationChannel) } diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go index 3870e361e91..072de3e77fb 100644 --- a/modules/core/04-channel/v2/keeper/msg_server_test.go +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -316,7 +316,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() { expectedAck := types.Acknowledgement{AppAcknowledgements: [][]byte{expRecvRes.Acknowledgement}} // modify the callback to return the expected recv result. - path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data types.Payload, relayer sdk.AccAddress) types.RecvPacketResult { + path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data types.Payload, relayer sdk.AccAddress) types.RecvPacketResult { return expRecvRes } @@ -377,7 +377,7 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() { // Modify the callback to return an error. // This way, we can verify that the callback is not executed in a No-op case. - path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, channeltypesv2.Payload, []byte, sdk.AccAddress) error { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, types.Payload, []byte, sdk.AccAddress) error { return mock.MockApplicationCallbackError } }, @@ -385,7 +385,7 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() { { name: "failure: callback fails", malleate: func() { - path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, channeltypesv2.Payload, []byte, sdk.AccAddress) error { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, types.Payload, []byte, sdk.AccAddress) error { return mock.MockApplicationCallbackError } }, @@ -471,7 +471,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() { // Modify the callback to return a different error. // This way, we can verify that the callback is not executed in a No-op case. - path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, channeltypesv2.Payload, sdk.AccAddress) error { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, types.Payload, sdk.AccAddress) error { return mock.MockApplicationCallbackError } }, @@ -480,7 +480,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() { { name: "failure: callback fails", malleate: func() { - path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, channeltypesv2.Payload, sdk.AccAddress) error { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, types.Payload, sdk.AccAddress) error { return mock.MockApplicationCallbackError } }, diff --git a/modules/core/module.go b/modules/core/module.go index 0e6610bd868..32e2589d075 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - channelkeeperv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra"