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

fix account creation on MsgMultiSend #6674

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ to detail this new feature and how state transitions occur.
now exists a single `Params` type with a getter and setter along with a getter for each individual parameter.

### Bug Fixes

* (x/bank) [\#6283](https://github.com/cosmos/cosmos-sdk/pull/6283) Create account if recipient does not exist on handing `MsgMultiSend`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to go on 0.39 👍

alessio marked this conversation as resolved.
Show resolved Hide resolved
* (rest) [\#5508](https://github.com/cosmos/cosmos-sdk/pull/5508) Fix `x/distribution` endpoints to properly return height in the response.
* (x/genutil) [\#5499](https://github.com/cosmos/cosmos-sdk/pull/) Ensure `DefaultGenesis` returns valid and non-nil default genesis state.
* (client) [\#5303](https://github.com/cosmos/cosmos-sdk/issues/5303) Fix ignored error in tx generate only mode.
Expand Down
9 changes: 9 additions & 0 deletions x/bank/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ func (keeper BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.In
sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()),
),
)

// Create account if recipient does not exist.
//
// NOTE: This should ultimately be removed in favor a more flexible approach
// such as delegated fee messages.
acc := keeper.ak.GetAccount(ctx, out.Address)
if acc == nil {
keeper.ak.SetAccount(ctx, keeper.ak.NewAccountWithAddress(ctx, out.Address))
}
}

return nil
Expand Down
32 changes: 32 additions & 0 deletions x/bank/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ func TestSendKeeper(t *testing.T) {
require.Error(t, err)
}

func TestInputOutputNewAccount(t *testing.T) {
app, ctx := createTestApp(false)
balances := sdk.NewCoins(sdk.NewInt64Coin("foo", 100), sdk.NewInt64Coin("bar", 50))
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)

app.AccountKeeper.SetAccount(ctx, acc1)
require.NoError(t, app.BankKeeper.SetCoins(ctx, addr1, balances))

acc1Balances := app.BankKeeper.GetCoins(ctx, addr1)
require.Equal(t, balances, acc1Balances)

addr2 := sdk.AccAddress([]byte("addr2"))

require.Nil(t, app.AccountKeeper.GetAccount(ctx, addr2))
require.Empty(t, app.BankKeeper.GetCoins(ctx, addr2))

inputs := []types.Input{
{Address: addr1, Coins: sdk.NewCoins(sdk.NewInt64Coin("foo", 30), sdk.NewInt64Coin("bar", 10))},
}
outputs := []types.Output{
{Address: addr2, Coins: sdk.NewCoins(sdk.NewInt64Coin("foo", 30), sdk.NewInt64Coin("bar", 10))},
}

require.NoError(t, app.BankKeeper.InputOutputCoins(ctx, inputs, outputs))

expected := sdk.NewCoins(sdk.NewInt64Coin("foo", 30), sdk.NewInt64Coin("bar", 10))
acc2Balances := app.BankKeeper.GetCoins(ctx, addr2)
require.Equal(t, expected, acc2Balances)
require.NotNil(t, app.AccountKeeper.GetAccount(ctx, addr2))
}

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

Expand Down