Skip to content

Commit 925ffa8

Browse files
committed
added tests
1 parent 03dcd79 commit 925ffa8

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

internal/interpreter/interpreter_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,3 +5528,68 @@ send [USD/2 10] (
55285528
})
55295529

55305530
}
5531+
5532+
func TestSendHalfUsingVirtual(t *testing.T) {
5533+
script := `
5534+
vars { account $v = virtual() }
5535+
5536+
send [USD/2 10] (
5537+
source = {
5538+
1/2 from @alice
5539+
remaining from $v allowing unbounded overdraft
5540+
}
5541+
destination = @interests
5542+
)
5543+
`
5544+
5545+
tc := NewTestCase()
5546+
tc.compile(t, script)
5547+
tc.setBalance("alice", "USD/2", 5)
5548+
5549+
tc.expected = CaseResult{
5550+
Postings: []machine.Posting{
5551+
{
5552+
Source: "alice",
5553+
Destination: "interests",
5554+
Asset: "USD/2",
5555+
Amount: big.NewInt(5),
5556+
},
5557+
},
5558+
}
5559+
test(t, tc)
5560+
}
5561+
5562+
func TestVirtualSendCreditAround(t *testing.T) {
5563+
script := `
5564+
vars {
5565+
account $v1 = virtual()
5566+
account $v2 = virtual()
5567+
}
5568+
5569+
send [USD 1] (
5570+
source = $v1 allowing unbounded overdraft
5571+
destination = $v2
5572+
)
5573+
5574+
send [USD 1] (
5575+
// here's we're sending the credit we have from $v1
5576+
// so $v2 doesn't "owe" anything to @dest
5577+
source = $v2
5578+
destination = @dest
5579+
)
5580+
5581+
send [USD 1] (
5582+
// that's why this doesn't output any postings
5583+
source = @world
5584+
destination = $v2
5585+
)
5586+
`
5587+
5588+
tc := NewTestCase()
5589+
tc.compile(t, script)
5590+
5591+
tc.expected = CaseResult{
5592+
Postings: []machine.Posting{},
5593+
}
5594+
test(t, tc)
5595+
}

0 commit comments

Comments
 (0)