From 9a6178380e2d86f7019461233adafd0379efdd49 Mon Sep 17 00:00:00 2001 From: ascandone Date: Thu, 1 Oct 2026 11:37:20 +0200 Subject: [PATCH] test: port the compiler e2e scenarios to spec fixtures --- .../account-interpolation-account-alias.num | 7 ++ ...interpolation-account-alias.num.specs.json | 19 +++ .../e2e/account-interpolation-number.num | 7 ++ ...ccount-interpolation-number.num.specs.json | 19 +++ .../e2e/account-interpolation-string.num | 7 ++ ...ccount-interpolation-string.num.specs.json | 19 +++ .../script-tests/e2e/account-var-origin.num | 7 ++ .../e2e/account-var-origin.num.specs.json | 23 ++++ .../e2e/allotment-beyond-int64.num | 7 ++ .../e2e/allotment-beyond-int64.num.specs.json | 22 ++++ .../e2e/allotment-exact-no-remaining.num | 7 ++ ...llotment-exact-no-remaining.num.specs.json | 22 ++++ .../e2e/allotment-halves-of-odd-amount.num | 7 ++ ...otment-halves-of-odd-amount.num.specs.json | 22 ++++ .../e2e/allotment-leftover-two-units.num | 8 ++ ...llotment-leftover-two-units.num.specs.json | 28 +++++ .../allotment-percentages-divide-exactly.num | 7 ++ ...-percentages-divide-exactly.num.specs.json | 22 ++++ .../e2e/allotment-remaining-only.num | 6 + .../allotment-remaining-only.num.specs.json | 16 +++ .../script-tests/e2e/allotment-sevenths.num | 8 ++ .../e2e/allotment-sevenths.num.specs.json | 28 +++++ .../testdata/script-tests/e2e/balance-var.num | 7 ++ .../e2e/balance-var.num.specs.json | 23 ++++ .../script-tests/e2e/bounded-overdraft.num | 4 + .../e2e/bounded-overdraft.num.specs.json | 23 ++++ .../script-tests/e2e/colored-source.num | 4 + .../e2e/colored-source.num.specs.json | 33 +++++ .../e2e/destination-allotment-thirds.num | 8 ++ ...estination-allotment-thirds.num.specs.json | 28 +++++ .../e2e/destination-allotment.num | 7 ++ .../e2e/destination-allotment.num.specs.json | 22 ++++ .../script-tests/e2e/destination-inorder.num | 7 ++ .../e2e/destination-inorder.num.specs.json | 22 ++++ .../script-tests/e2e/destination-kept.num | 7 ++ .../e2e/destination-kept.num.specs.json | 16 +++ .../script-tests/e2e/dynamic-world-source.num | 7 ++ .../e2e/dynamic-world-source.num.specs.json | 19 +++ .../testdata/script-tests/e2e/get-amount.num | 8 ++ .../e2e/get-amount.num.specs.json | 26 ++++ .../testdata/script-tests/e2e/get-asset.num | 8 ++ .../script-tests/e2e/get-asset.num.specs.json | 26 ++++ .../script-tests/e2e/inorder-with-cap.num | 8 ++ .../e2e/inorder-with-cap.num.specs.json | 45 +++++++ .../testdata/script-tests/e2e/inorder.num | 8 ++ .../script-tests/e2e/inorder.num.specs.json | 39 ++++++ .../script-tests/e2e/int-addition.num | 4 + .../e2e/int-addition.num.specs.json | 23 ++++ .../script-tests/e2e/int-subtraction.num | 4 + .../e2e/int-subtraction.num.specs.json | 23 ++++ .../script-tests/e2e/monetary-addition.num | 8 ++ .../e2e/monetary-addition.num.specs.json | 23 ++++ .../script-tests/e2e/monetary-subtraction.num | 8 ++ .../e2e/monetary-subtraction.num.specs.json | 23 ++++ .../script-tests/e2e/nested-destination.num | 10 ++ .../e2e/nested-destination.num.specs.json | 28 +++++ .../script-tests/e2e/oneof-nested.num | 10 ++ .../e2e/oneof-nested.num.specs.json | 80 +++++++++++++ .../testdata/script-tests/e2e/oneof.num | 8 ++ .../script-tests/e2e/oneof.num.specs.json | 113 ++++++++++++++++++ .../script-tests/e2e/overdraft-function.num | 7 ++ .../e2e/overdraft-function.num.specs.json | 37 ++++++ .../e2e/prefix-minus-monetary.num | 8 ++ .../e2e/prefix-minus-monetary.num.specs.json | 23 ++++ .../script-tests/e2e/prefix-minus-number.num | 8 ++ .../e2e/prefix-minus-number.num.specs.json | 23 ++++ .../script-tests/e2e/save-then-send-all.num | 5 + .../e2e/save-then-send-all.num.specs.json | 23 ++++ .../e2e/send-all-bounded-overdraft.num | 4 + .../send-all-bounded-overdraft.num.specs.json | 23 ++++ .../e2e/send-all-multi-source.num | 8 ++ .../e2e/send-all-multi-source.num.specs.json | 45 +++++++ .../e2e/send-all-negative-overdraft-bound.num | 4 + ...ll-negative-overdraft-bound.num.specs.json | 23 ++++ .../testdata/script-tests/e2e/send-all.num | 4 + .../script-tests/e2e/send-all.num.specs.json | 23 ++++ .../testdata/script-tests/e2e/send.num | 4 + .../script-tests/e2e/send.num.specs.json | 34 ++++++ .../e2e/source-allotment-insufficient.num | 7 ++ ...urce-allotment-insufficient.num.specs.json | 21 ++++ .../e2e/source-allotment-thirds.num | 8 ++ .../source-allotment-thirds.num.specs.json | 45 +++++++ .../script-tests/e2e/source-allotment.num | 7 ++ .../e2e/source-allotment.num.specs.json | 34 ++++++ .../script-tests/e2e/world-source.num | 4 + .../e2e/world-source.num.specs.json | 16 +++ 86 files changed, 1536 insertions(+) create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-var-origin.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/account-var-origin.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/balance-var.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/balance-var.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/colored-source.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/colored-source.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-allotment.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-allotment.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-inorder.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-inorder.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-kept.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/destination-kept.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/get-amount.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/get-amount.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/get-asset.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/get-asset.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/inorder.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/inorder.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/int-addition.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/int-addition.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/int-subtraction.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/int-subtraction.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/monetary-addition.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/monetary-addition.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/nested-destination.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/nested-destination.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/oneof-nested.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/oneof-nested.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/oneof.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/oneof.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/overdraft-function.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/overdraft-function.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/send-all.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/send.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/send.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/source-allotment.num.specs.json create mode 100644 internal/interpreter/testdata/script-tests/e2e/world-source.num create mode 100644 internal/interpreter/testdata/script-tests/e2e/world-source.num.specs.json diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num new file mode 100644 index 00000000..b8f1c410 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num @@ -0,0 +1,7 @@ +vars { + account $a = @src +} +send [USD/2 10] ( + source = @world + destination = @dest:$a +) diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num.specs.json new file mode 100644 index 00000000..1f029aeb --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-account-alias.num.specs.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-account-interpolation" + ], + "testCases": [ + { + "it": "interpolates the name of an account var whose origin is another account", + "expect.postings": [ + { + "source": "world", + "destination": "dest:src", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num new file mode 100644 index 00000000..a16cf87b --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num @@ -0,0 +1,7 @@ +vars { + number $n = 42 +} +send [USD/2 10] ( + source = @world + destination = @account:$n +) diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num.specs.json new file mode 100644 index 00000000..ca429d73 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-number.num.specs.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-account-interpolation" + ], + "testCases": [ + { + "it": "interpolates a number var", + "expect.postings": [ + { + "source": "world", + "destination": "account:42", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num new file mode 100644 index 00000000..487c417a --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num @@ -0,0 +1,7 @@ +vars { + string $id = "alice" +} +send [USD/2 10] ( + source = @world + destination = @users:$id:wallet +) diff --git a/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num.specs.json new file mode 100644 index 00000000..d8c57593 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-interpolation-string.num.specs.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-account-interpolation" + ], + "testCases": [ + { + "it": "interpolates a string var", + "expect.postings": [ + { + "source": "world", + "destination": "users:alice:wallet", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num b/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num new file mode 100644 index 00000000..09f10046 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num @@ -0,0 +1,7 @@ +vars { + account $acc = @src +} +send [USD/2 10] ( + source = $acc + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num.specs.json new file mode 100644 index 00000000..62502328 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/account-var-origin.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "uses an account var initialized from a literal", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num b/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num new file mode 100644 index 00000000..7cb86d22 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num @@ -0,0 +1,7 @@ +send [USD/2 1000000000000000000000000001] ( + source = @world + destination = { + 1/2 to @a + remaining to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num.specs.json new file mode 100644 index 00000000..e165299e --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-beyond-int64.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "splits an amount beyond int64", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 500000000000000000000000001, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 500000000000000000000000000, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num b/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num new file mode 100644 index 00000000..aa514a03 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = @world + destination = { + 1/4 to @a + 3/4 to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num.specs.json new file mode 100644 index 00000000..5a993d41 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-exact-no-remaining.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "portions summing to exactly 1 need no remaining", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 25, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 75, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num b/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num new file mode 100644 index 00000000..b5bd898c --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num @@ -0,0 +1,7 @@ +send [USD/2 7] ( + source = @world + destination = { + 1/2 to @a + remaining to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num.specs.json new file mode 100644 index 00000000..6a6b1b98 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-halves-of-odd-amount.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "the odd unit goes to the earliest share", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 4, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 3, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num b/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num new file mode 100644 index 00000000..eb63f97a --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num @@ -0,0 +1,8 @@ +send [USD/2 100] ( + source = @world + destination = { + 1/6 to @a + 1/6 to @b + remaining to @c + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num.specs.json new file mode 100644 index 00000000..064f7773 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-leftover-two-units.num.specs.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "each of the first shares gets one leftover unit", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 17, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 17, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "c", + "amount": 66, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num b/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num new file mode 100644 index 00000000..54110e62 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num @@ -0,0 +1,7 @@ +send [USD/2 10000] ( + source = @world + destination = { + 19/100 to @a + remaining to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num.specs.json new file mode 100644 index 00000000..d7885a5e --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-percentages-divide-exactly.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "no share is adjusted when the split is exact", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 1900, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 8100, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num b/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num new file mode 100644 index 00000000..81f8afe0 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num @@ -0,0 +1,6 @@ +send [USD/2 100] ( + source = @world + destination = { + remaining to @dest + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num.specs.json new file mode 100644 index 00000000..885430ce --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-remaining-only.num.specs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "a lone remaining clause takes everything", + "expect.postings": [ + { + "source": "world", + "destination": "dest", + "amount": 100, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num b/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num new file mode 100644 index 00000000..534aa0af --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num @@ -0,0 +1,8 @@ +send [USD/2 1001] ( + source = @world + destination = { + 1/7 to @a + 2/7 to @b + remaining to @c + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num.specs.json new file mode 100644 index 00000000..e13f1359 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/allotment-sevenths.num.specs.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "the shares sum back to the amount", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 143, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 286, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "c", + "amount": 572, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/balance-var.num b/internal/interpreter/testdata/script-tests/e2e/balance-var.num new file mode 100644 index 00000000..a9d3fb32 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/balance-var.num @@ -0,0 +1,7 @@ +vars { + monetary $bal = balance(@src, USD/2) +} +send $bal ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/balance-var.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/balance-var.num.specs.json new file mode 100644 index 00000000..7821ca7a --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/balance-var.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "sends the balance read into a var", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 100, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num b/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num new file mode 100644 index 00000000..ffdb7869 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num @@ -0,0 +1,4 @@ +send [USD/2 42] ( + source = @a allowing overdraft up to [USD/2 5] + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num.specs.json new file mode 100644 index 00000000..a8a9451b --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/bounded-overdraft.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "overdraws within the bound", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 40 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 42, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/colored-source.num b/internal/interpreter/testdata/script-tests/e2e/colored-source.num new file mode 100644 index 00000000..1eab93f3 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/colored-source.num @@ -0,0 +1,4 @@ +send [COIN 10] ( + source = @src \ "RED" + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/colored-source.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/colored-source.num.specs.json new file mode 100644 index 00000000..4c2bc223 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/colored-source.num.specs.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-asset-colors" + ], + "testCases": [ + { + "it": "pulls only the colored balance", + "balances": [ + { + "account": "src", + "asset": "COIN", + "amount": 100 + }, + { + "account": "src", + "asset": "COIN", + "amount": 30, + "color": "RED" + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "COIN", + "color": "RED" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num b/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num new file mode 100644 index 00000000..4b146636 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num @@ -0,0 +1,8 @@ +send [USD/2 100] ( + source = @world + destination = { + 1/3 to @a + 1/3 to @b + remaining to @c + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num.specs.json new file mode 100644 index 00000000..4c26e551 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-allotment-thirds.num.specs.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "the leftover unit goes to the earliest share", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 34, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 33, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "c", + "amount": 33, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num b/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num new file mode 100644 index 00000000..61e61ede --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = @world + destination = { + 1/2 to @a + remaining to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num.specs.json new file mode 100644 index 00000000..f656df02 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-allotment.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "splits by portion", + "expect.postings": [ + { + "source": "world", + "destination": "a", + "amount": 50, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 50, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num b/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num new file mode 100644 index 00000000..1ed4110a --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = @world + destination = { + max [USD/2 30] to @x + remaining to @y + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num.specs.json new file mode 100644 index 00000000..66107f1b --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-inorder.num.specs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "a capped clause takes its cap and remaining takes the rest", + "expect.postings": [ + { + "source": "world", + "destination": "x", + "amount": 30, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "y", + "amount": 70, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-kept.num b/internal/interpreter/testdata/script-tests/e2e/destination-kept.num new file mode 100644 index 00000000..f8480f11 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-kept.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = @world + destination = { + max [USD/2 30] kept + remaining to @y + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/destination-kept.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/destination-kept.num.specs.json new file mode 100644 index 00000000..e0c26fb8 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/destination-kept.num.specs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "a kept clause emits no posting", + "expect.postings": [ + { + "source": "world", + "destination": "y", + "amount": 70, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num b/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num new file mode 100644 index 00000000..aa836ade --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num @@ -0,0 +1,7 @@ +vars { + account $src +} +send [USD/2 100] ( + source = $src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num.specs.json new file mode 100644 index 00000000..62121152 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/dynamic-world-source.num.specs.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "world passed as a var is unbounded", + "variables": { + "src": "world" + }, + "expect.postings": [ + { + "source": "world", + "destination": "dest", + "amount": 100, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/get-amount.num b/internal/interpreter/testdata/script-tests/e2e/get-amount.num new file mode 100644 index 00000000..937192e6 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/get-amount.num @@ -0,0 +1,8 @@ +vars { + monetary $m = [USD/2 42] + number $n = get_amount($m) +} +send [USD/2 $n] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/get-amount.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/get-amount.num.specs.json new file mode 100644 index 00000000..60c5b0c3 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/get-amount.num.specs.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-get-amount-function" + ], + "testCases": [ + { + "it": "reads the amount of a monetary", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 42, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/get-asset.num b/internal/interpreter/testdata/script-tests/e2e/get-asset.num new file mode 100644 index 00000000..9dbf7f20 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/get-asset.num @@ -0,0 +1,8 @@ +vars { + monetary $m = [USD/2 42] + asset $a = get_asset($m) +} +send [$a 10] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/get-asset.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/get-asset.num.specs.json new file mode 100644 index 00000000..d32bfe46 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/get-asset.num.specs.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-get-asset-function" + ], + "testCases": [ + { + "it": "reads the asset of a monetary", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num b/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num new file mode 100644 index 00000000..5815b99b --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num @@ -0,0 +1,8 @@ +send [USD/2 10] ( + source = { + @a + max [USD/2 5] from @b + @c + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num.specs.json new file mode 100644 index 00000000..cc3507f5 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/inorder-with-cap.num.specs.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "the cap binds inside an inorder source", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 3 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 100 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 3, + "asset": "USD/2" + }, + { + "source": "b", + "destination": "dest", + "amount": 5, + "asset": "USD/2" + }, + { + "source": "c", + "destination": "dest", + "amount": 2, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/inorder.num b/internal/interpreter/testdata/script-tests/e2e/inorder.num new file mode 100644 index 00000000..f46c31fe --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/inorder.num @@ -0,0 +1,8 @@ +send [USD/2 10] ( + source = { + @a + @b + @c + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/inorder.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/inorder.num.specs.json new file mode 100644 index 00000000..36112514 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/inorder.num.specs.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "stops pulling once the amount is covered", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 6 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 6, + "asset": "USD/2" + }, + { + "source": "b", + "destination": "dest", + "amount": 4, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/int-addition.num b/internal/interpreter/testdata/script-tests/e2e/int-addition.num new file mode 100644 index 00000000..b9119718 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/int-addition.num @@ -0,0 +1,4 @@ +send [USD/2 4 + 6] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/int-addition.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/int-addition.num.specs.json new file mode 100644 index 00000000..d00d6335 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/int-addition.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "adds numbers", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num b/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num new file mode 100644 index 00000000..a11d6b76 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num @@ -0,0 +1,4 @@ +send [USD/2 16 - 6] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num.specs.json new file mode 100644 index 00000000..7bcf535f --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/int-subtraction.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "subtracts numbers", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num b/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num new file mode 100644 index 00000000..e30ee6ba --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num @@ -0,0 +1,8 @@ +vars { + monetary $a = [USD/2 3] + monetary $b = [USD/2 7] +} +send $a + $b ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num.specs.json new file mode 100644 index 00000000..e04751cd --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/monetary-addition.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "adds monetaries of the same asset", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num b/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num new file mode 100644 index 00000000..7666c489 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num @@ -0,0 +1,8 @@ +vars { + monetary $a = [USD/2 30] + monetary $b = [USD/2 20] +} +send $a - $b ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num.specs.json new file mode 100644 index 00000000..4a28d119 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/monetary-subtraction.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "subtracts monetaries of the same asset", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/nested-destination.num b/internal/interpreter/testdata/script-tests/e2e/nested-destination.num new file mode 100644 index 00000000..d44ccef4 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/nested-destination.num @@ -0,0 +1,10 @@ +send [USD/2 100] ( + source = @world + destination = { + 1/2 to { + max [USD/2 10] to @x + remaining to @a + } + remaining to @b + } +) diff --git a/internal/interpreter/testdata/script-tests/e2e/nested-destination.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/nested-destination.num.specs.json new file mode 100644 index 00000000..01907b40 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/nested-destination.num.specs.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "splits a share again", + "expect.postings": [ + { + "source": "world", + "destination": "x", + "amount": 10, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "a", + "amount": 40, + "asset": "USD/2" + }, + { + "source": "world", + "destination": "b", + "amount": 50, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num b/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num new file mode 100644 index 00000000..35956af5 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num @@ -0,0 +1,10 @@ +send [USD/2 10] ( + source = oneof { + { + @a + oneof { @b @c } + } + @d + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num.specs.json new file mode 100644 index 00000000..a1f6b713 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/oneof-nested.num.specs.json @@ -0,0 +1,80 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-oneof" + ], + "testCases": [ + { + "it": "an inner backtrack keeps the outer branch's funds", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 4 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 5 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 6 + }, + { + "account": "d", + "asset": "USD/2", + "amount": 10 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 4, + "asset": "USD/2" + }, + { + "source": "c", + "destination": "dest", + "amount": 6, + "asset": "USD/2" + } + ] + }, + { + "it": "an outer backtrack discards the inner region too", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 4 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 3 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 5 + }, + { + "account": "d", + "asset": "USD/2", + "amount": 10 + } + ], + "expect.postings": [ + { + "source": "d", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/oneof.num b/internal/interpreter/testdata/script-tests/e2e/oneof.num new file mode 100644 index 00000000..e7bcadca --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/oneof.num @@ -0,0 +1,8 @@ +send [USD/2 10] ( + source = oneof { + @a + @b + @c + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/oneof.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/oneof.num.specs.json new file mode 100644 index 00000000..b31f8b78 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/oneof.num.specs.json @@ -0,0 +1,113 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-oneof" + ], + "testCases": [ + { + "it": "the first branch covers it", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 10 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + }, + { + "it": "backtracks past a short branch", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 3 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 10 + } + ], + "expect.postings": [ + { + "source": "b", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + }, + { + "it": "backtracks twice, to the last branch", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 3 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 9 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 10 + } + ], + "expect.postings": [ + { + "source": "c", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + }, + { + "it": "fails when no branch covers it", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 3 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 4 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 5 + } + ], + "expect.error.missingFunds": true + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num b/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num new file mode 100644 index 00000000..7719b2fa --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num @@ -0,0 +1,7 @@ +vars { + monetary $od = overdraft(@acc, USD/2) +} +send $od ( + source = @world + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num.specs.json new file mode 100644 index 00000000..beed7f66 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/overdraft-function.num.specs.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "featureFlags": [ + "experimental-overdraft-function" + ], + "testCases": [ + { + "it": "a negative balance's overdraft is the debt", + "balances": [ + { + "account": "acc", + "asset": "USD/2", + "amount": -100 + } + ], + "expect.postings": [ + { + "source": "world", + "destination": "dest", + "amount": 100, + "asset": "USD/2" + } + ] + }, + { + "it": "a positive balance has no overdraft", + "balances": [ + { + "account": "acc", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num new file mode 100644 index 00000000..26f92d4d --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num @@ -0,0 +1,8 @@ +vars { + monetary $neg_mon = [USD/2 -10] + monetary $pos_mon = -$neg_mon +} +send $pos_mon ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num.specs.json new file mode 100644 index 00000000..9c77ddb0 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-monetary.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "negates a monetary", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num new file mode 100644 index 00000000..c19c009e --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num @@ -0,0 +1,8 @@ +vars { + number $neg = -10 + number $pos = -$neg +} +send [USD/2 $pos] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num.specs.json new file mode 100644 index 00000000..83380089 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/prefix-minus-number.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "negates a literal and a variable", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num b/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num new file mode 100644 index 00000000..e6aa8d75 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num @@ -0,0 +1,5 @@ +save [USD/2 30] from @a +send [USD/2 *] ( + source = @a + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num.specs.json new file mode 100644 index 00000000..51ad55aa --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/save-then-send-all.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "send-all takes only what was not saved", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 70, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num b/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num new file mode 100644 index 00000000..bb565370 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num @@ -0,0 +1,4 @@ +send [USD/2 *] ( + source = @a allowing overdraft up to [USD/2 5] + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num.specs.json new file mode 100644 index 00000000..fb78faec --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-bounded-overdraft.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "send-all includes the overdraft bound", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 40 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 45, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num b/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num new file mode 100644 index 00000000..ba1f4018 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num @@ -0,0 +1,8 @@ +send [USD/2 *] ( + source = { + @a + max [USD/2 5] from @b + @c + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num.specs.json new file mode 100644 index 00000000..5b083873 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-multi-source.num.specs.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "pulls everything from each source in order", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 100 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 7 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + }, + { + "source": "b", + "destination": "dest", + "amount": 5, + "asset": "USD/2" + }, + { + "source": "c", + "destination": "dest", + "amount": 7, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num b/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num new file mode 100644 index 00000000..e1bd18f9 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num @@ -0,0 +1,4 @@ +send [COIN *] ( + source = @s allowing overdraft up to [COIN -10] + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num.specs.json new file mode 100644 index 00000000..2b006430 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all-negative-overdraft-bound.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "a negative overdraft bound is clamped to zero", + "balances": [ + { + "account": "s", + "asset": "COIN", + "amount": 1 + } + ], + "expect.postings": [ + { + "source": "s", + "destination": "dest", + "amount": 1, + "asset": "COIN" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all.num b/internal/interpreter/testdata/script-tests/e2e/send-all.num new file mode 100644 index 00000000..dbe0dc87 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all.num @@ -0,0 +1,4 @@ +send [USD/2 *] ( + source = @a + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/send-all.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/send-all.num.specs.json new file mode 100644 index 00000000..12f49d04 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send-all.num.specs.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "sends the whole balance", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 30 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 30, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/send.num b/internal/interpreter/testdata/script-tests/e2e/send.num new file mode 100644 index 00000000..8a4a72d5 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send.num @@ -0,0 +1,4 @@ +send [USD/2 10] ( + source = @src + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/send.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/send.num.specs.json new file mode 100644 index 00000000..e1146cee --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/send.num.specs.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "sends from a funded source", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 100 + } + ], + "expect.postings": [ + { + "source": "src", + "destination": "dest", + "amount": 10, + "asset": "USD/2" + } + ] + }, + { + "it": "fails when the source cannot cover the amount", + "balances": [ + { + "account": "src", + "asset": "USD/2", + "amount": 4 + } + ], + "expect.error.missingFunds": true + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num b/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num new file mode 100644 index 00000000..d8ba2061 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = { + 1/2 from @s1 + remaining from @s2 + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num.specs.json new file mode 100644 index 00000000..4b577ba5 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment-insufficient.num.specs.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "a source that cannot cover its share fails", + "balances": [ + { + "account": "s1", + "asset": "USD/2", + "amount": 10 + }, + { + "account": "s2", + "asset": "USD/2", + "amount": 1000 + } + ], + "expect.error.missingFunds": true + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num b/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num new file mode 100644 index 00000000..1ca9e0c2 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num @@ -0,0 +1,8 @@ +send [USD/2 100] ( + source = { + 1/3 from @a + 1/3 from @b + remaining from @c + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num.specs.json new file mode 100644 index 00000000..b05a379d --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment-thirds.num.specs.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "the leftover unit goes to the earliest share", + "balances": [ + { + "account": "a", + "asset": "USD/2", + "amount": 1000 + }, + { + "account": "b", + "asset": "USD/2", + "amount": 1000 + }, + { + "account": "c", + "asset": "USD/2", + "amount": 1000 + } + ], + "expect.postings": [ + { + "source": "a", + "destination": "dest", + "amount": 34, + "asset": "USD/2" + }, + { + "source": "b", + "destination": "dest", + "amount": 33, + "asset": "USD/2" + }, + { + "source": "c", + "destination": "dest", + "amount": 33, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment.num b/internal/interpreter/testdata/script-tests/e2e/source-allotment.num new file mode 100644 index 00000000..c18e1357 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment.num @@ -0,0 +1,7 @@ +send [USD/2 100] ( + source = { + 1/4 from @s1 + remaining from @s2 + } + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/source-allotment.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/source-allotment.num.specs.json new file mode 100644 index 00000000..d8c142cf --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/source-allotment.num.specs.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "pulls each share from its source", + "balances": [ + { + "account": "s1", + "asset": "USD/2", + "amount": 1000 + }, + { + "account": "s2", + "asset": "USD/2", + "amount": 1000 + } + ], + "expect.postings": [ + { + "source": "s1", + "destination": "dest", + "amount": 25, + "asset": "USD/2" + }, + { + "source": "s2", + "destination": "dest", + "amount": 75, + "asset": "USD/2" + } + ] + } + ] +} diff --git a/internal/interpreter/testdata/script-tests/e2e/world-source.num b/internal/interpreter/testdata/script-tests/e2e/world-source.num new file mode 100644 index 00000000..6e302c68 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/world-source.num @@ -0,0 +1,4 @@ +send [USD/2 100] ( + source = @world + destination = @dest +) diff --git a/internal/interpreter/testdata/script-tests/e2e/world-source.num.specs.json b/internal/interpreter/testdata/script-tests/e2e/world-source.num.specs.json new file mode 100644 index 00000000..c8abdcd0 --- /dev/null +++ b/internal/interpreter/testdata/script-tests/e2e/world-source.num.specs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/formancehq/numscript/main/v1.specs.schema.json", + "testCases": [ + { + "it": "world is unbounded", + "expect.postings": [ + { + "source": "world", + "destination": "dest", + "amount": 100, + "asset": "USD/2" + } + ] + } + ] +}