Skip to content
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
4,863 changes: 503 additions & 4,360 deletions internal/interpreter/interpreter_test.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions testdata/script-tests/add-monetaries-same-currency.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

send [COIN 1] + [COIN 2] (
source = @world
destination = @dest
)

15 changes: 15 additions & 0 deletions testdata/script-tests/add-monetaries-same-currency.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"testCases": [
{
"it": "-",
"expect.postings": [
{
"source": "world",
"destination": "dest",
"amount": 3,
"asset": "COIN"
}
]
}
]
}
3 changes: 3 additions & 0 deletions testdata/script-tests/add-numbers.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set_tx_meta("k", 1 + 2)

10 changes: 10 additions & 0 deletions testdata/script-tests/add-numbers.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"testCases": [
{
"it": "-",
"expect.txMetadata": {
"k": "3"
}
}
]
}
10 changes: 10 additions & 0 deletions testdata/script-tests/allocate-dont-take-too-much.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
send [CREDIT 200] (
source = {
@users:001
@users:002
}
destination = {
1/2 to @foo
1/2 to @bar
}
)
29 changes: 29 additions & 0 deletions testdata/script-tests/allocate-dont-take-too-much.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"testCases": [
{
"it": "-",
"balances": {
"users:001": {
"CREDIT": 100
},
"users:002": {
"CREDIT": 110
}
},
"expect.postings": [
{
"source": "users:001",
"destination": "foo",
"amount": 100,
"asset": "CREDIT"
},
{
"source": "users:002",
"destination": "bar",
"amount": 100,
"asset": "CREDIT"
}
]
}
]
}
12 changes: 12 additions & 0 deletions testdata/script-tests/allocation.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
vars {
account $rider
account $driver
}
send [GEM 15] (
source = $rider
destination = {
80% to $driver
8% to @a
12% to @b
}
)
36 changes: 36 additions & 0 deletions testdata/script-tests/allocation.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"testCases": [
{
"it": "-",
"balances": {
"users:001": {
"GEM": 15
}
},
"variables": {
"driver": "users:002",
"rider": "users:001"
},
"expect.postings": [
{
"source": "users:001",
"destination": "users:002",
"amount": 13,
"asset": "GEM"
},
{
"source": "users:001",
"destination": "a",
"amount": 1,
"asset": "GEM"
},
{
"source": "users:001",
"destination": "b",
"amount": 1,
"asset": "GEM"
}
]
}
]
}
10 changes: 10 additions & 0 deletions testdata/script-tests/ask-balance-twice.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

vars {
monetary $bal = balance(@alice, USD/2)
}

send $bal (
source = @alice
destination = @dest
)

20 changes: 20 additions & 0 deletions testdata/script-tests/ask-balance-twice.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"testCases": [
{
"it": "-",
"balances": {
"alice": {
"USD/2": 10
}
},
"expect.postings": [
{
"source": "alice",
"destination": "dest",
"amount": 10,
"asset": "USD/2"
}
]
}
]
}
9 changes: 9 additions & 0 deletions testdata/script-tests/balance-not-found.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

vars {
monetary $balance = balance(@a, EUR/2)
}

send $balance (
source = @world
destination = @dest
)
10 changes: 10 additions & 0 deletions testdata/script-tests/balance-not-found.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"testCases": [
{
"it": "-",
"balances": {
"a": {}
}
}
]
}
11 changes: 11 additions & 0 deletions testdata/script-tests/balance-simple.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

vars {
monetary $bal = balance(@alice, USD/2)
}

send $bal (
source = @world
destination = @dest
)


20 changes: 20 additions & 0 deletions testdata/script-tests/balance-simple.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"testCases": [
{
"it": "-",
"balances": {
"alice": {
"USD/2": 10
}
},
"expect.postings": [
{
"source": "world",
"destination": "dest",
"amount": 10,
"asset": "USD/2"
}
]
}
]
}
9 changes: 9 additions & 0 deletions testdata/script-tests/balance.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

vars {
monetary $balance = balance(@a, EUR/2)
}

send $balance (
source = @world
destination = @dest
)
20 changes: 20 additions & 0 deletions testdata/script-tests/balance.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"testCases": [
{
"it": "-",
"balances": {
"a": {
"EUR/2": 123
}
},
"expect.postings": [
{
"source": "world",
"destination": "dest",
"amount": 123,
"asset": "EUR/2"
}
]
}
]
}
12 changes: 12 additions & 0 deletions testdata/script-tests/big-int-monetary.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

vars { monetary $amt }

send $amt (
source = @world
destination = {
100% to @dest
remaining kept
}
)


18 changes: 18 additions & 0 deletions testdata/script-tests/big-int-monetary.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"testCases": [
{
"it": "-",
"variables": {
"amt": "USD/123 99999223372036854775807"
},
"expect.postings": [
{
"source": "world",
"destination": "dest",
"amount": 99999223372036854775807,
"asset": "USD/123"
}
]
}
]
}
12 changes: 12 additions & 0 deletions testdata/script-tests/big-int.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

vars { number $amt }

send [USD/2 $amt] (
source = @world
destination = {
100% to @dest
remaining kept
}
)


18 changes: 18 additions & 0 deletions testdata/script-tests/big-int.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"testCases": [
{
"it": "-",
"variables": {
"amt": "99999223372036854775807"
},
"expect.postings": [
{
"source": "world",
"destination": "dest",
"amount": 99999223372036854775807,
"asset": "USD/2"
}
]
}
]
}
9 changes: 9 additions & 0 deletions testdata/script-tests/capped-when-less-than-needed.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

send [COIN 100] (
source = {
max [COIN 40] from @src1
@src2
}
destination = @platform
)

29 changes: 29 additions & 0 deletions testdata/script-tests/capped-when-less-than-needed.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"testCases": [
{
"it": "-",
"balances": {
"src1": {
"COIN": 1000
},
"src2": {
"COIN": 1000
}
},
"expect.postings": [
{
"source": "src1",
"destination": "platform",
"amount": 40,
"asset": "COIN"
},
{
"source": "src2",
"destination": "platform",
"amount": 60,
"asset": "COIN"
}
]
}
]
}
9 changes: 9 additions & 0 deletions testdata/script-tests/capped-when-more-than-balance.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

send [COIN 100] (
source = {
max [COIN 200] from @world
@src
}
destination = @platform
)

20 changes: 20 additions & 0 deletions testdata/script-tests/capped-when-more-than-balance.num.specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"testCases": [
{
"it": "-",
"balances": {
"src": {
"COIN": 1000
}
},
"expect.postings": [
{
"source": "world",
"destination": "platform",
"amount": 100,
"asset": "COIN"
}
]
}
]
}
14 changes: 14 additions & 0 deletions testdata/script-tests/cascading-sources.num
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

send [USD/2 10000] (
source = {
// first, pull from the user balance
@users:1234:main
// then, pull from the user's vouchers,
// fairly using the ones that expire first
@users:1234:vouchers:2024-01-31
@users:1234:vouchers:2024-02-17
@users:1234:vouchers:2024-03-22
}
destination = @orders:4567:payment
)

Loading
Loading