Skip to content

Commit 53ae0b7

Browse files
committed
added tests
1 parent a3051d6 commit 53ae0b7

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
@@ -5601,3 +5601,68 @@ send [USD/2 10] (
56015601
})
56025602

56035603
}
5604+
5605+
func TestSendHalfUsingVirtual(t *testing.T) {
5606+
script := `
5607+
vars { account $v = virtual() }
5608+
5609+
send [USD/2 10] (
5610+
source = {
5611+
1/2 from @alice
5612+
remaining from $v allowing unbounded overdraft
5613+
}
5614+
destination = @interests
5615+
)
5616+
`
5617+
5618+
tc := NewTestCase()
5619+
tc.compile(t, script)
5620+
tc.setBalance("alice", "USD/2", 5)
5621+
5622+
tc.expected = CaseResult{
5623+
Postings: []machine.Posting{
5624+
{
5625+
Source: "alice",
5626+
Destination: "interests",
5627+
Asset: "USD/2",
5628+
Amount: big.NewInt(5),
5629+
},
5630+
},
5631+
}
5632+
test(t, tc)
5633+
}
5634+
5635+
func TestVirtualSendCreditAround(t *testing.T) {
5636+
script := `
5637+
vars {
5638+
account $v1 = virtual()
5639+
account $v2 = virtual()
5640+
}
5641+
5642+
send [USD 1] (
5643+
source = $v1 allowing unbounded overdraft
5644+
destination = $v2
5645+
)
5646+
5647+
send [USD 1] (
5648+
// here's we're sending the credit we have from $v1
5649+
// so $v2 doesn't "owe" anything to @dest
5650+
source = $v2
5651+
destination = @dest
5652+
)
5653+
5654+
send [USD 1] (
5655+
// that's why this doesn't output any postings
5656+
source = @world
5657+
destination = $v2
5658+
)
5659+
`
5660+
5661+
tc := NewTestCase()
5662+
tc.compile(t, script)
5663+
5664+
tc.expected = CaseResult{
5665+
Postings: []machine.Posting{},
5666+
}
5667+
test(t, tc)
5668+
}

0 commit comments

Comments
 (0)