Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ledger): Overdraft with Max #1116

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}