diff --git a/components/ledger/internal/machine/script/compiler/source.go b/components/ledger/internal/machine/script/compiler/source.go index c1a0fcf984..9db97a8d47 100644 --- a/components/ledger/internal/machine/script/compiler/source.go +++ b/components/ledger/internal/machine/script/compiler/source.go @@ -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) diff --git a/components/ledger/internal/machine/vm/machine_test.go b/components/ledger/internal/machine/vm/machine_test.go index 33ac9ec1f3..f9f34fcc6f 100644 --- a/components/ledger/internal/machine/vm/machine_test.go +++ b/components/ledger/internal/machine/vm/machine_test.go @@ -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) +}