Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
co-authored by
Facundo Medica
parent
c21b60638c
commit
adcf958f34
@@ -118,7 +118,7 @@ func checkBalance(t *testing.T, baseApp *baseapp.BaseApp, addr sdk.AccAddress, b
|
||||
t.Helper()
|
||||
ctxCheck := baseApp.NewContext(true)
|
||||
keeperBalances := keeper.GetAllBalances(ctxCheck, addr)
|
||||
require.True(t, balances.Equal(keeperBalances))
|
||||
require.True(t, balances.Equal(keeperBalances), balances.String(), keeperBalances.String())
|
||||
}
|
||||
|
||||
func TestSendNotEnoughBalance(t *testing.T) {
|
||||
@@ -477,3 +477,47 @@ func TestMsgSetSendEnabled(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestSendToNonExistingAccount tests sending coins to an account that does not exist, and this account
|
||||
// must not be created.
|
||||
func TestSendToNonExistingAccount(t *testing.T) {
|
||||
acc1 := authtypes.NewBaseAccountWithAddress(addr1)
|
||||
genAccs := []authtypes.GenesisAccount{acc1}
|
||||
s := createTestSuite(t, genAccs)
|
||||
baseApp := s.App.BaseApp
|
||||
ctx := baseApp.NewContext(false)
|
||||
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
|
||||
_, err := baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
addr2Str, err := s.AccountKeeper.AddressCodec().BytesToString(addr2)
|
||||
require.NoError(t, err)
|
||||
sendMsg := types.NewMsgSend(addr1.String(), addr2Str, coins)
|
||||
h := header.Info{Height: baseApp.LastBlockHeight() + 1}
|
||||
txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{})
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, h, []sdk.Msg{sendMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check that the account was not created
|
||||
acc2 := s.AccountKeeper.GetAccount(baseApp.NewContext(true), addr2)
|
||||
require.Nil(t, acc2)
|
||||
|
||||
// But it does have a balance
|
||||
checkBalance(t, baseApp, addr2, coins, s.BankKeeper)
|
||||
|
||||
// Now we send coins back and the account should be created
|
||||
sendMsg = types.NewMsgSend(addr2Str, addr1.String(), coins)
|
||||
h = header.Info{Height: baseApp.LastBlockHeight() + 1}
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, h, []sdk.Msg{sendMsg}, "", []uint64{0}, []uint64{0}, true, true, priv2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Balance has been reduced
|
||||
checkBalance(t, baseApp, addr2, sdk.NewCoins(), s.BankKeeper)
|
||||
|
||||
// Check that the account was created
|
||||
acc2 = s.AccountKeeper.GetAccount(baseApp.NewContext(true), addr2)
|
||||
require.NotNil(t, acc2, "account should have been created %s", addr2.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user