Overview
When writingcheck:construction tests to test with the mesh-cli tool, it’s best to write them in the Mesh Constructor Domain-Specific Language (DSL).
The Mesh DSL allows you to write Workflows for the constructor package.
This DSL is most commonly used for writing check:construction tests for the mesh-cli tool. The Mesh DSL filename’s extension is .ros.
Prerequisites
- The Mesh DSL file is a prerequisite to write a configuration file for the
mesh-clitool’scheck:constructiontest. For more information, see How to Write a Configuration File for mesh-cli Testing. - We recommend that you write your Mesh DSL file as you write your Mesh API configuration file.
- Use Mesh-supported curve types. The
create_accountandtransferworkflows include this value. Using any other curve types will cause test failures with themesh-clitool. - The
request_fundsworkflow requires the use of an account with test funds. You can provide that with a pre-funded account or with a URL to an account with test funds. See the Account Funding section for more information.
Terminology
Themesh-cli tool’s check:construction test uses the following hierarchy of concerns:
mesh-sdk-go repository.
Syntax
When broken down into simple elements, the Mesh DSL syntax looks like the following example:Elements
line comment- Follows the JavaScript single-line comment notation of two slashes (//) at the start of a line or at the end of a line of code.workflow name- Your name for the workflow. For example,create_account.- Each workflow must have a unique name; no two workflows can have the same name.
concurrency- The order in which you want the workflow to run. You must provide aconcurrencyvalue when you define a workflow.scenario name- Your name for the scenarios you’d like to add to the workflow.- You can add one or more scenarios to a workflow. They must be separated by a comma.
- You must define the scenarios within a workflow.
- As with the workflow name, each scenario name must be unique. No two scenarios inside the same workflow can have the same name.
output path- This variable stores the results of a scenario for later use.action type- The reason why you want to run this scenario.input- The input for all functions is a JSON blob that will be evaluated by theWorker.- It is possible to reference other variables in an input using the syntax
{{var}}wherevarmust follow the GJSON syntax. The Mesh DSL compiler will automatically check that referenced variables are previously defined.
- It is possible to reference other variables in an input using the syntax
Account Funding
If you plan to run thecheck:construction test in continuous integration (CI), we recommend that you provide a value for prefunded accounts when running the test. Otherwise, you would need to manually fund generated accounts.
Optionally, you can also provide a return_funds workflow that will be invoked when exiting check:construction. This can be useful in CI when you want to return all funds to a single account or faucet (instead of black-holing them in all the addresses created during testing).
To use the check:construction test without prefunded accounts, you must implement two required Workflows:
- If you don’t implement these Workflows, processing could stall.
- Please note that
create_accountcan contain a transaction broadcast if on-chain origination is required for new accounts on your blockchain.
Broadcast Invocation
If you’d like to broadcast a transaction at the end of a Scenario, you must populate the following fields:<scenario>.network<scenario>.operations<scenario>.confirmation_depth(allows for stake-related transactions to complete before marking as a success)
<scenario>.preprocess_metadata field.
Once a transaction is confirmed on-chain (after the provided <scenario>.confirmation_depth), check:construction stores it at <scenario>.transaction for access by other Scenarios in the same Job.
Dry Runs
In UTXO-based blockchains, it may be necessary to amend theoperations stored in <scenario>.operations based on the suggested_fee returned in /construction/metadata. The check:construction test supports running a dry run of a transaction broadcast if you set the <scenario>.dry_run field to true. The suggested fee will then be stored as <scenario>.suggested_fee for use by other Scenarios in the same Job. You can find an example of this in the Bitcoin config).
If you do not populate this field or set it to false, the transaction will be constructed, signed, and broadcast.
Functions
In the Mesh DSL, it is possible to invoke functions, where the function name is written as an action type (Action.Type).
- The Mesh DSL provides optional “native invocation” support for the
mathandset_variableaction types. Read the Native Invocation section below for details. - Function invocations can span multiple lines (if you “pretty print” the JSON blob). However, each function call line must end with a semicolon (
;). - Currently, it is not possible to define your own functions. The
types.gofile lists all the available functions.
Recursive Calls
It is not possible to invoke a function from the input of another function. There MUST be exactly one function call per line. For example, this syntax is not allowed:Native Invocation
The Mesh DSL provides optional “native invocation” support for themath and set_variable action types. “Native invocation” in this case means that the caller does not need to invoke the action type in the normal format:
math
You can invokemath with the following syntax:
set_variable
You can invokeset_variable with the following syntax:
Testing
Workflows are part of a Mesh API implementation, which you can test with therosetta.cli tool.
Example Workflows
Create an Account
This Workflow is required if you are testing without prefunded accounts.The following example is for a Workflow to create an account. It includes the
create_account scenario and the save_account scenario. For more information, read the source file.
Request Funds
This Workflow is required if you are testing without prefunded accounts.The following example is for a Workflow to request funds. It includes the
find_account scenario and the request scenario. For more information, read the source file.
Transfer
The following example is for a Workflow to transfer funds. It includes thetransfer scenario. For more information, read the source file.
Example DSL File
Destination Tag Support
The following example is for a DSL file to test whether the Mesh implementation supports destination tags. It includes therequest_funds, create_account, and transfer workflows. For more information, read the Testing Destination Tag Blockchains section in the How to Test your Mesh Implementation document.