From bdaa081c35733c5775c196f62cbf9252614bce7f Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 23 Sep 2024 11:02:55 +0300 Subject: [PATCH 1/2] fix --- x/bank/app_test.go | 5 +++++ x/bank/keeper/send.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 338f2838b9fa..03aa9ebfa83e 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -572,4 +572,9 @@ func TestHooks(t *testing.T) { require.NoError(t, err) require.Equal(t, countTrackBeforeSend, expNextCount) expNextCount++ + + err = s.BankKeeper.InputOutputCoins(ctx, types.Input{Address: addr1.String(), Coins: triggerTrackSendAmount}, []types.Output{{Address: addr2.String(), Coins: triggerTrackSendAmount}}) + require.NoError(t, err) + require.Equal(t, countTrackBeforeSend, expNextCount) + expNextCount++ } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index b0de6cc69e1a..173b13b89c2e 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -164,6 +164,19 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, return err } + for _, out := range outputs { + outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address) + if err != nil { + return err + } + + if err := k.BlockBeforeSend(ctx, inAddress, outAddress, out.Coins); err != nil { + return err + } + + k.TrackBeforeSend(ctx, inAddress, outAddress, out.Coins) + } + err = k.subUnlockedCoins(ctx, inAddress, input.Coins) if err != nil { return err From d4597e1e1133177628572fbf81a007d6edf516b3 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Tue, 24 Sep 2024 18:28:47 +0300 Subject: [PATCH 2/2] additional tests --- x/bank/app_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 03aa9ebfa83e..ddeb5aaf35a2 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -63,6 +63,8 @@ var ( priv2 = secp256k1.GenPrivKey() addr2 = sdk.AccAddress(priv2.PubKey().Address()) addr3 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr4 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr5 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} halfCoins = sdk.Coins{sdk.NewInt64Coin("foocoin", 5)} @@ -576,5 +578,26 @@ func TestHooks(t *testing.T) { err = s.BankKeeper.InputOutputCoins(ctx, types.Input{Address: addr1.String(), Coins: triggerTrackSendAmount}, []types.Output{{Address: addr2.String(), Coins: triggerTrackSendAmount}}) require.NoError(t, err) require.Equal(t, countTrackBeforeSend, expNextCount) - expNextCount++ + + multiSendTrackInput := types.Input{ + Address: addr1.String(), + Coins: triggerTrackSendAmount.MulInt(sdkmath.NewInt(4)), + } + multiSendTrackOutput := []types.Output{{ + Address: addr2.String(), + Coins: triggerTrackSendAmount, + }, { + Address: addr3.String(), + Coins: triggerTrackSendAmount, + }, { + Address: addr4.String(), + Coins: triggerTrackSendAmount, + }, { + Address: addr5.String(), + Coins: triggerTrackSendAmount, + }} + err = s.BankKeeper.InputOutputCoins(ctx, multiSendTrackInput, multiSendTrackOutput) + require.NoError(t, err) + expNextCount += 4 + require.Equal(t, countTrackBeforeSend, expNextCount) }