Skip to content

Commit

Permalink
Add more events to on IBC transfer, add tests for ibc transfer event (#…
Browse files Browse the repository at this point in the history
…2643)

improvements: add amount, denom, and memo to transfer event emission.
  • Loading branch information
Anmol1696 authored Nov 23, 2022
1 parent 6dd5881 commit 50e1211
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 38 additions & 1 deletion modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit 50e1211

Please sign in to comment.