numscript test command
A JSON schema is available online, so that you can have autocomplete and diagnostics in your editor. In many editors such as vscode, you can enable it adding it to the json this way:
Example
Say we have the following numscript:$cap
.
We can express the relevant test cases in the following way:
Preconditions
The inputs of each test cases. You can set the preconditions top-level (in the outer object), and/or in eachtestCase
. The preconditions in a testCase will be merged to the top-level preconditions (with the precedence being given to the inner preconditions).
For example, in the following specs:
@alice
‘s EUR/2
balance, resulting in:
variables
The (stringified) value of each variable
balances
The initial accounts’ balances.
metadata
The initial accounts’ metadata.
Assertions
Assertions are only run if explicitly defined. The recommended assertion to use by default areexpect.postings
or expect.missingFunds
, but there are also a few weaker assertion that might be useful when the exact postings are an implementation detail of your business logic.
expect.missingFunds
Assert that the script failed because of missing funds. Even if this is set to true, the test will still fail if the script outputs a different error.
Defaults to false
.
expect.postings
Assert against the exact postings emitted by the script. To assert that there are no postings, you can use the empty array. To assert that no postings are produced because of a failure due to missing funds, you can use the expect.missingFunds
assertion instead.
expect.txMetadata
Assert against the trasaction meta emitted by the script (using set_tx_meta
). It’s a map from the metadata key to its (stringified) value.
expect.metadata
Assert against the accounts metadata at the end of script execution (using set_account_meta
). It’s a nested map from an account, to the metadata key to its (stringified) value.
accountsMeta
as well.
expect.volumes
Assert against the balances at the end of the script
For example:
@alice
has [EUR/2 100]
balance after the script is applied.
You might consider using this assertion when you only care about the end balance of an account, for example if you need to bring an account to a certain value (not less, not more), so you don’t care about how the postings are composed exactly.
expect.movements
Assert against the resulting movements. A movement is a nested map from a source account, to destination account, to the sent amounts.
For example, this assertion:
@alice
sent [EUR/2 100]
to @bob
You might consider using this assertion when you care about the movements graph from-to accounts, and you don’t care about the order of the postings or the way they are split.