diff --git a/internal/interpreter/interpreter.go b/internal/interpreter/interpreter.go index 383b36ef..14ba6cfd 100644 --- a/internal/interpreter/interpreter.go +++ b/internal/interpreter/interpreter.go @@ -395,7 +395,9 @@ func (st *programState) runSaveStatement(saveStatement parser.SaveStatement) Int balance := st.CachedBalances.fetchBalance(*account, *asset, "") if amt == nil { - balance.Set(big.NewInt(0)) + if balance.Sign() > 0 { + balance.Set(big.NewInt(0)) + } } else { // Do not allow negative saves if amt.Cmp(big.NewInt(0)) == -1 { diff --git a/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num b/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num new file mode 100644 index 00000000..0a85a69f --- /dev/null +++ b/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num @@ -0,0 +1,6 @@ +save [USD *] from @alice + +send [USD 10] ( + source = @alice allowing overdraft up to [USD 30] + destination = @world +) diff --git a/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num.specs.json b/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num.specs.json new file mode 100644 index 00000000..6d9c6bd9 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num.specs.json @@ -0,0 +1,13 @@ +{ + "testCases": [ + { + "it": "-", + "balances": { + "alice": { + "USD": -100 + } + }, + "expect.error.missingFunds": true + } + ] +}