forked from TrueCloudLab/neoneo-go
native: prohibit NEP-17 roundtrip with zero balance
Close #3190. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
c5e284c117
commit
b4866bd69e
2 changed files with 19 additions and 0 deletions
|
@ -180,6 +180,9 @@ func (c *nep17TokenNative) updateAccBalance(ic *interop.Context, acc util.Uint16
|
||||||
if amount.Sign() < 0 {
|
if amount.Sign() < 0 {
|
||||||
return nil, errors.New("insufficient funds")
|
return nil, errors.New("insufficient funds")
|
||||||
}
|
}
|
||||||
|
if requiredBalance != nil && requiredBalance.Sign() > 0 {
|
||||||
|
return nil, errors.New("insufficient funds")
|
||||||
|
}
|
||||||
if amount.Sign() == 0 {
|
if amount.Sign() == 0 {
|
||||||
// it's OK to transfer 0 if the balance is 0, no need to put si to the storage
|
// it's OK to transfer 0 if the balance is 0, no need to put si to the storage
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -595,6 +595,22 @@ func TestNEO_TransferZeroWithNonZeroBalance(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/nspcc-dev/neo-go/issues/3190
|
||||||
|
func TestNEO_TransferNonZeroWithZeroBalance(t *testing.T) {
|
||||||
|
neoValidatorsInvoker := newNeoValidatorsClient(t)
|
||||||
|
e := neoValidatorsInvoker.Executor
|
||||||
|
|
||||||
|
acc := neoValidatorsInvoker.WithSigners(e.NewAccount(t))
|
||||||
|
accH := acc.Signers[0].ScriptHash()
|
||||||
|
h := acc.Invoke(t, false, "transfer", accH, accH, int64(5), nil)
|
||||||
|
aer := e.CheckHalt(t, h, stackitem.Make(false))
|
||||||
|
require.Equal(t, 0, len(aer.Events))
|
||||||
|
// check balance wasn't changed and height was not updated
|
||||||
|
updatedBalance, updatedHeight := e.Chain.GetGoverningTokenBalance(accH)
|
||||||
|
require.Equal(t, int64(0), updatedBalance.Int64())
|
||||||
|
require.Equal(t, uint32(0), updatedHeight)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNEO_CalculateBonus(t *testing.T) {
|
func TestNEO_CalculateBonus(t *testing.T) {
|
||||||
neoCommitteeInvoker := newNeoCommitteeClient(t, 10_0000_0000)
|
neoCommitteeInvoker := newNeoCommitteeClient(t, 10_0000_0000)
|
||||||
e := neoCommitteeInvoker.Executor
|
e := neoCommitteeInvoker.Executor
|
||||||
|
|
Loading…
Reference in a new issue