Skip to content

Commit

Permalink
fix(ledger): Overdraft with Max (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed Jan 12, 2024
1 parent 2f3a8dc commit cba9ca0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (p *parseVisitor) VisitSource(c parser.ISourceContext, pushAsset func(), is
if err != nil {
return nil, nil, nil, LogicError(c, err)
}
p.AppendInstruction(program.OP_TAKE_ALL)
p.AppendInstruction(program.OP_TAKE_ALWAYS)
err = p.PushInteger(machine.NewNumber(2))
if err != nil {
return nil, nil, nil, LogicError(c, err)
Expand Down
29 changes: 29 additions & 0 deletions components/ledger/internal/machine/vm/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2147,3 +2147,32 @@ send [B 100] (
}
test(t, tc)
}

func TestMaxWithUnboundedOverdraft(t *testing.T) {
tc := NewTestCase()
tc.compile(t, `
send [COIN 100] (
source = {
max [COIN 10] from @account1 allowing unbounded overdraft
@account2
}
destination = @world
)`)
tc.setBalance("account1", "COIN", 10000)
tc.setBalance("account2", "COIN", 10000)
tc.expected = CaseResult{
Printed: []machine.Value{},
Postings: []Posting{{
Source: "account1",
Destination: "world",
Amount: machine.NewMonetaryInt(10),
Asset: "COIN",
}, {
Source: "account2",
Destination: "world",
Amount: machine.NewMonetaryInt(90),
Asset: "COIN",
}},
}
test(t, tc)
}

1 comment on commit cba9ca0

@vercel
Copy link

@vercel vercel bot commented on cba9ca0 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.