Skip to content

Commit

Permalink
Merge PR #5557: Added amount event to InputOutputCoins for MsgMultSend
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldingli1997 authored and alexanderbez committed Feb 7, 2020
1 parent 4c51736 commit 96de834
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [v0.37.7] - TBD

### Bug Fixes

* (x/bank) [\#5531](https://github.com/cosmos/cosmos-sdk/issues/5531) Added missing amount event to MsgMultiSend, emitted for each output.

## [v0.37.6] - 2020-01-21

### Improvements
Expand Down
1 change: 1 addition & 0 deletions docs/spec/bank/04_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The bank module emits the following events:
| Type | Attribute Key | Attribute Value |
|----------|---------------|--------------------|
| transfer | recipient | {recipientAddress} |
| transfer | amount | {amount} |
| message | module | bank |
| message | action | multisend |
| message | sender | {senderAddress} |
1 change: 1 addition & 0 deletions x/bank/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (keeper BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.In
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, out.Address.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()),
),
)
}
Expand Down
88 changes: 88 additions & 0 deletions x/bank/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,94 @@ func TestSendKeeper(t *testing.T) {
require.Error(t, err)
}

func TestMsgMultiSendEvents(t *testing.T) {
app, ctx := createTestApp(false)

app.BankKeeper.SetSendEnabled(ctx, true)

addr := sdk.AccAddress([]byte("addr1"))
addr2 := sdk.AccAddress([]byte("addr2"))
addr3 := sdk.AccAddress([]byte("addr3"))
addr4 := sdk.AccAddress([]byte("addr4"))
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)

app.AccountKeeper.SetAccount(ctx, acc)
app.AccountKeeper.SetAccount(ctx, acc2)
newCoins := sdk.NewCoins(sdk.NewInt64Coin("foocoin", 50))
newCoins2 := sdk.NewCoins(sdk.NewInt64Coin("barcoin", 100))
inputs := []types.Input{
{Address: addr, Coins: newCoins},
{Address: addr2, Coins: newCoins2},
}
outputs := []types.Output{
{Address: addr3, Coins: newCoins},
{Address: addr4, Coins: newCoins2},
}
err := app.BankKeeper.InputOutputCoins(ctx, inputs, outputs)
require.Error(t, err)
events := ctx.EventManager().Events()
require.Equal(t, 0, len(events))

// Set addr's coins but not addr2's coins
app.BankKeeper.SetCoins(ctx, addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 50)))

err = app.BankKeeper.InputOutputCoins(ctx, inputs, outputs)
require.Error(t, err)
events = ctx.EventManager().Events()
require.Equal(t, 1, len(events))
event1 := sdk.Event{
Type: sdk.EventTypeMessage,
Attributes: []tmkv.Pair{},
}
event1.Attributes = append(
event1.Attributes,
tmkv.Pair{Key: []byte(types.AttributeKeySender), Value: []byte(addr.String())})
require.Equal(t, event1, events[0])

// Set addr's coins and addr2's coins
app.BankKeeper.SetCoins(ctx, addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 50)))
newCoins = sdk.NewCoins(sdk.NewInt64Coin("foocoin", 50))
app.BankKeeper.SetCoins(ctx, addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 100)))
newCoins2 = sdk.NewCoins(sdk.NewInt64Coin("barcoin", 100))

err = app.BankKeeper.InputOutputCoins(ctx, inputs, outputs)
require.NoError(t, err)
events = ctx.EventManager().Events()
require.Equal(t, 5, len(events))
event2 := sdk.Event{
Type: sdk.EventTypeMessage,
Attributes: []tmkv.Pair{},
}
event2.Attributes = append(
event2.Attributes,
tmkv.Pair{Key: []byte(types.AttributeKeySender), Value: []byte(addr2.String())})
event3 := sdk.Event{
Type: types.EventTypeTransfer,
Attributes: []tmkv.Pair{},
}
event3.Attributes = append(
event3.Attributes,
tmkv.Pair{Key: []byte(types.AttributeKeyRecipient), Value: []byte(addr3.String())})
event3.Attributes = append(
event3.Attributes,
tmkv.Pair{Key: []byte(sdk.AttributeKeyAmount), Value: []byte(newCoins.String())})
event4 := sdk.Event{
Type: types.EventTypeTransfer,
Attributes: []tmkv.Pair{},
}
event4.Attributes = append(
event4.Attributes,
tmkv.Pair{Key: []byte(types.AttributeKeyRecipient), Value: []byte(addr4.String())})
event4.Attributes = append(
event4.Attributes,
tmkv.Pair{Key: []byte(sdk.AttributeKeyAmount), Value: []byte(newCoins2.String())})
require.Equal(t, event1, events[1])
require.Equal(t, event2, events[2])
require.Equal(t, event3, events[3])
require.Equal(t, event4, events[4])
}

func TestViewKeeper(t *testing.T) {
input := setupTestInput()
ctx := input.ctx
Expand Down

0 comments on commit 96de834

Please sign in to comment.