Skip to content

Commit 161a0f3

Browse files
committed
fix: fix complex test case
1 parent 46588c0 commit 161a0f3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

internal/interpreter/funds_stack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type fundsStack struct {
1515
}
1616

1717
func newFundsStack(senders []Sender) fundsStack {
18+
senders = slices.Clone(senders)
19+
1820
// TODO do not modify arg
1921
// TODO clone big ints so that we can manipulate them
2022
slices.Reverse(senders)

internal/interpreter/interpreter_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,6 +4296,41 @@ func TestWithinInorder(t *testing.T) {
42964296
test(t, tc)
42974297
}
42984298

4299+
func TestThroughComplex(t *testing.T) {
4300+
script := `
4301+
send [USD/2 10] (
4302+
source = {
4303+
@a1 // balance: 5
4304+
@a2 // balance: 100
4305+
} through {
4306+
2/3 from @p1 // [USD/2 7]
4307+
1/3 from @p2 // [USD/2 3]
4308+
}
4309+
destination = @dest
4310+
)
4311+
`
4312+
4313+
tc := NewTestCase()
4314+
tc.compile(t, script)
4315+
tc.setBalance("a1", "USD/2", 5)
4316+
tc.setBalance("a2", "USD/2", 100)
4317+
4318+
tc.expected = CaseResult{
4319+
Postings: []Posting{
4320+
{Source: "a1", Destination: "p1", Amount: big.NewInt(5), Asset: "USD/2"},
4321+
{Source: "a2", Destination: "p1", Amount: big.NewInt(2), Asset: "USD/2"},
4322+
4323+
{Source: "a2", Destination: "p2", Amount: big.NewInt(3), Asset: "USD/2"},
4324+
4325+
{Source: "p1", Destination: "dest", Amount: big.NewInt(7), Asset: "USD/2"},
4326+
{Source: "p2", Destination: "dest", Amount: big.NewInt(3), Asset: "USD/2"},
4327+
},
4328+
Error: nil,
4329+
}
4330+
4331+
test(t, tc)
4332+
}
4333+
42994334
func TestColorSend(t *testing.T) {
43004335
script := `
43014336
send [COIN 100] (

0 commit comments

Comments
 (0)