Skip to content

Commit

Permalink
feat: trimmed zero postings
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Dec 6, 2024
1 parent 661c6a1 commit 90f330d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ func (s *programState) receiveFrom(destination parser.Destination, amount *big.I
remainingAmount := new(big.Int).Set(amount)

handler := func(keptOrDest parser.KeptOrDestination, amountToReceive *big.Int) InterpreterError {
if amountToReceive.Cmp(big.NewInt(0)) == 0 {
return nil
}

err := s.receiveFromKeptOrDest(keptOrDest, amountToReceive)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions internal/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,30 @@ func TestZeroPostings(t *testing.T) {
test(t, tc)
}

func TestZeroPostingsDestination(t *testing.T) {
tc := NewTestCase()
tc.compile(t, `
send [COIN 100] (
source = @world
destination = {
max [COIN 0] to @d1
remaining to @d2
}
)
`)
tc.expected = CaseResult{
Postings: []machine.Posting{
{
"world",
"d2",
big.NewInt(100),
"COIN",
},
},
}
test(t, tc)
}

func TestUnboundedOverdraftWhenNotEnoughFunds(t *testing.T) {
tc := NewTestCase()
tc.setBalance("users:2345:main", "USD/2", 8000)
Expand Down

0 comments on commit 90f330d

Please sign in to comment.