diff --git a/CHANGELOG.md b/CHANGELOG.md index ebfe1bf5d08..42057e1a1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (apps/transfer) [\#2643](https://github.com/cosmos/ibc-go/pull/2643) Add amount, denom, and memo to transfer event emission. * (core) [\#2746](https://github.com/cosmos/ibc-go/pull/2746) Allow proof height to be zero for all core IBC `sdk.Msg` types that contain proofs. * (light-clients/06-solomachine) [\#2746](https://github.com/cosmos/ibc-go/pull/2746) Discard proofHeight for solo machines and use the solo machine sequence instead. * (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. diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 74812ecd1a9..564647b2148 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -46,6 +46,9 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. types.EventTypeTransfer, sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), sdk.NewAttribute(types.AttributeKeyReceiver, msg.Receiver), + sdk.NewAttribute(types.AttributeKeyAmount, msg.Token.Amount.String()), + sdk.NewAttribute(types.AttributeKeyDenom, msg.Token.Denom), + sdk.NewAttribute(types.AttributeKeyMemo, msg.Memo), ), sdk.NewEvent( sdk.EventTypeMessage, diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 3943024f648..0fe65b4ebdc 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -7,6 +7,36 @@ import ( "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" ) +func (suite *KeeperTestSuite) assertTransferEvents( + actualEvents sdk.Events, + coin sdk.Coin, + memo string, +) { + hasEvent := false + + expEvent := map[string]string{ + sdk.AttributeKeySender: suite.chainA.SenderAccount.GetAddress().String(), + types.AttributeKeyReceiver: suite.chainB.SenderAccount.GetAddress().String(), + types.AttributeKeyAmount: coin.Amount.String(), + types.AttributeKeyDenom: coin.Denom, + types.AttributeKeyMemo: memo, + } + + for _, event := range actualEvents { + if event.Type == types.EventTypeTransfer { + hasEvent = true + suite.Require().Len(event.Attributes, len(expEvent)) + for _, attr := range event.Attributes { + expValue, found := expEvent[string(attr.Key)] + suite.Require().True(found) + suite.Require().Equal(expValue, string(attr.Value)) + } + } + } + + suite.Require().True(hasEvent, "event: %s was not found in events", types.EventTypeTransfer) +} + func (suite *KeeperTestSuite) TestMsgTransfer() { var msg *types.MsgTransfer @@ -94,15 +124,22 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { tc.malleate() - res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) + ctx := suite.chainA.GetContext() + res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(ctx), msg) if tc.expPass { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().NotEqual(res.Sequence, uint64(0)) + + events := ctx.EventManager().Events() + suite.assertTransferEvents(events, coin, "memo") } else { suite.Require().Error(err) suite.Require().Nil(res) + + events := ctx.EventManager().Events() + suite.Require().Len(events, 0) } }) }