Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more events to on IBC transfer, add tests for ibc transfer event #2643

Merged
merged 29 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f396b05
Add more events to on IBC transfer, add tests for ibc transfer event
Anmol1696 Oct 31, 2022
02348bb
Fix imports
Anmol1696 Oct 31, 2022
edf464b
Fix spelling of comment
Anmol1696 Oct 31, 2022
982e371
Create checking of expected and all values into a function
Anmol1696 Nov 1, 2022
2f65684
Remove type of expected events and use map of map directly
Anmol1696 Nov 1, 2022
b739b16
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 2, 2022
b5bd99b
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 3, 2022
a67f56f
Remove all event for ibc-transfer apart from amount and denom
Anmol1696 Nov 3, 2022
8d6df4c
Fix imports
Anmol1696 Nov 3, 2022
1579acf
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 3, 2022
a17f141
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 4, 2022
0083a15
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 5, 2022
7414ba6
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 9, 2022
c38b139
Add memo, change event checker function
Anmol1696 Nov 9, 2022
0b6bbb7
Update modules/apps/transfer/keeper/msg_server_test.go
Anmol1696 Nov 9, 2022
1894c3f
Update modules/apps/transfer/keeper/msg_server_test.go
Anmol1696 Nov 9, 2022
370b38c
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 9, 2022
0468e9a
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 10, 2022
a1384d2
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 14, 2022
01db569
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 15, 2022
6e35f5b
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 17, 2022
897909f
Use constants instead of string attributes for event verification
Anmol1696 Nov 17, 2022
2eabc77
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 18, 2022
02047c3
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 19, 2022
de4844d
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 21, 2022
91b179f
chore: add changelog entry
colin-axner Nov 21, 2022
708de00
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 21, 2022
346a50d
Merge branch 'main' into anmol/emit-msg-transfer
Anmol1696 Nov 22, 2022
d9561dc
Merge branch 'main' into anmol/emit-msg-transfer
Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
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 {
Anmol1696 marked this conversation as resolved.
Show resolved Hide resolved
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