Merge PR #5557: Added amount event to InputOutputCoins for MsgMultSend

This commit is contained in:
Miguel Dingli 2020-01-27 15:46:55 +01:00 committed by Alexander Bezobchuk
parent 1b6897ad1b
commit d5d29ef67a
4 changed files with 94 additions and 0 deletions

View File

@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/. * (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/.
### Bug Fixes
* (x/bank) [\#5531](https://github.com/cosmos/cosmos-sdk/issues/5531) Added missing amount event to MsgMultiSend, emitted for each output.
## [v0.38.0] - 2020-01-23 ## [v0.38.0] - 2020-01-23
### State Machine Breaking ### State Machine Breaking

View File

@ -208,6 +208,7 @@ func (keeper BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.In
sdk.NewEvent( sdk.NewEvent(
types.EventTypeTransfer, types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, out.Address.String()), sdk.NewAttribute(types.AttributeKeyRecipient, out.Address.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()),
), ),
) )
} }

View File

@ -194,6 +194,94 @@ func TestMsgSendEvents(t *testing.T) {
require.Equal(t, event2, events[3]) require.Equal(t, event2, events[3])
} }
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) { func TestViewKeeper(t *testing.T) {
app, ctx := createTestApp(false) app, ctx := createTestApp(false)

View File

@ -23,6 +23,7 @@ The bank module emits the following events:
| Type | Attribute Key | Attribute Value | | Type | Attribute Key | Attribute Value |
|----------|---------------|--------------------| |----------|---------------|--------------------|
| transfer | recipient | {recipientAddress} | | transfer | recipient | {recipientAddress} |
| transfer | amount | {amount} |
| message | module | bank | | message | module | bank |
| message | action | multisend | | message | action | multisend |
| message | sender | {senderAddress} | | message | sender | {senderAddress} |