Merge pull request #3191 from nspcc-dev/fix-roundtrip

native: prohibit non-zero GAS/NEO roundtrip with zero balance
This commit is contained in:
Roman Khimov 2023-11-08 09:32:56 +03:00 committed by GitHub
commit f8d8b03f64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -180,6 +180,9 @@ func (c *nep17TokenNative) updateAccBalance(ic *interop.Context, acc util.Uint16
if amount.Sign() < 0 {
return nil, errors.New("insufficient funds")
}
if requiredBalance != nil && requiredBalance.Sign() > 0 {
return nil, errors.New("insufficient funds")
}
if amount.Sign() == 0 {
// it's OK to transfer 0 if the balance is 0, no need to put si to the storage
return nil, nil

View file

@ -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) {
neoCommitteeInvoker := newNeoCommitteeClient(t, 10_0000_0000)
e := neoCommitteeInvoker.Executor