How to Test your Mesh Implementation
Overview
You can use the mesh-cli
tool to test your Mesh API implementation. Once your implementation passes through the check:data
and check:construction
tests, it’s a few steps away from being used in services that use Mesh API.
Prerequisites
1. Install the mesh-cli tool in your local directory
Download the binary into a ./bin
directory (relative to your current directory) with the following command:
The binary will be installed inside the ./bin
directory (relative to the directory where you ran the installation command).
- Note: Downloading binaries from the GitHub application will cause permission errors on Mac.
To download the binary into a specific directory, run the following command:
2. Create your configuration file
Read How to Write a Configuration File to learn how to create a configuration file for mesh-cli testing. You can find example configuration files in the examples/configuration
directory. You can also find example configuration files for running tests against a Bitcoin Mesh implementation (configuration file) and an Ethereum Mesh implementation (configuration file).
You can also create a default configuration file with the mesh-cli
tool’s configuration:create
command.
3. Write the check:construction tests in Mesh DSL.
Read our How to Write a Mesh DSL File documentation to learn how to create the tests.
4. Disable complex checks (for now)
If you are just getting started with your implementation, you may want to disable balance tracking (did any address balance go below zero?) and reconciliation (does the balance I calculated match the balance returned by the /account/balance
endpoint?). Take a look at this simple configuration for an example of how to do this.
If you’d like to add more details, see our How to Disable Complex Checks documentation.
After you’re done testing, be sure to enable these complex checks again! Your Mesh API implementation is complete when these complex checks pass the mesh-cli
tool testing.
Run the Tool
Run the mesh-cli
tool from the command line with this command: mesh-cli [command]
. You must run the tool with a command. Otherwise, the default return is the same as the return for the mesh-cli
help command.
If there are no issues found while running check:data
or check:construction
, it will exit with a 0
status code. If there are any issues, it will exit with a 1
status code. It can be useful to run this command as an integration test for any changes to your implementation.
Commands
You can use the following commands with the mesh-cli
tool.
Command | Description | Example |
---|---|---|
check:construction | Tests a Mesh Construction API Implementation. | mesh-cli check:construction |
check:data | Tests a Mesh Data API Implementation. | mesh-cli check:data |
configuration:create | Creates a default configuration file at the provided path. | mesh-cli configuration:create |
configuration:validate | Ensures that the configuration file at the provided path is formatted correctly. | mesh-cli configuration:validate |
help | Provides help about any command. | mesh-cli help |
utils:asserter-configuration | Generate a static configuration file. Most users will not need to use this command. | mesh-cli utils:asserter-configuration |
utils:train-zstd | Generate a zstd dictionary for enhanced compression performance. Most users will not need to use this command. | mesh-cli utils:train-zstd |
version | Prints the mesh-cli tool’s version number. | mesh-cli version |
view:balance | Views an account balance. | mesh-cli view:balance |
view:block | Views a block. | mesh-cli view:block |
view:networks | Views all network statuses. | mesh-cli view:networks |
Flags
Use the following flags with the commands for the mesh-cli
tool.
Flag | Description | Example |
---|---|---|
--block-profile [filename] | Saves the pprof block profile in the specified file. | mesh-cli [command] --block-profile pprof.file |
--configuration-file [filename] | The configuration file that provides connection and test settings. | |
If you would like to generate a starter configuration file (populated with the defaults), run mesh-cli configuration:create . Any fields not populated in the configuration file will be populated with default values. | mesh-cli check:data --configuration-file config.json | |
--cpu-profile [filename] | Save the pprof cpu profile in the specified file. | 1 |
-h , --help | Shows the help file for the mesh-cli tool. | mesh-cli --help |
--mem-profile [filename] | Saves the pprof mem profile in the specified file. | mesh-cli [command] --mem-profile pprof.file |
mesh-cli [command] --help | Provides more information about the specified command. | mesh-cli check:data --help |
Example
The following example runs the check:data command with the —configuration-file flag.
The command’s output will resemble the following example:
Testing Destination Tag Blockchains
You can test the Mesh implementation of a blockchain that uses destination tags with a Workflow that you can add to your Mesh DSL file.
- Manually generate the recipient account address and the corresponding destination tag from the blockchain wallet or tool you’re testing.
- Write your Mesh DSL file
transfer
Workflows to test the destination tag. You can follow the example in the Destination Tag Support section of the How to Write a Mesh DSL File documentation. - Enter the recipient address and destination tag that you generated in step 1 in these fields in your
transfer
Workflow:- The
address
field inrecipient_account
:recipient_account = {"address":"a1d2d3r4e5s6s7"}
- The
memo
field intransfer.preprocess_metadata
:transfer.preprocess_metadata = {"memo":"destination-tag"}
- The
- Run the
check:construction
command and check the results. If your results are correct, your output should be similar to the output in the Example section.
Frequently Asked Questions
Which command should I run first?
This will depend on what goals you’re trying to accomplish. We suggest that you run the check:data
test first. The reason is that this test may take a long time, depending on your configuration. If the check:data
test has to check all of the accounts in older blockchains, that test can take a long time to finish.
(Fortunately, if there are any errors that end the check:data
test before it’s checked all the information you want it to check, the test will restart at the last block where it left off.)
After the check:data
test completes, we suggest that you run the check:construction
test.
Can I run the check:data
and check:construction
commands at the same time?
You must run the check:data
and check:construction
commands separately. They cannot be run at the same time. The check:data
test may take a long time to complete on older blockchains with lots of blocks. (We’re talking about weeks, maybe even a month or more!) If you are testing on the mainnet
network, be aware that this situation will likely occur for older blockchains.
What does the pprof profile do?
The pprof profile is a Golang tool that helps with performance optimization. You can use this tool to know which resources your system is using before or after you run the mesh-cli
tool for testing your Mesh API implementations. For more information, visit Google’s pprof repository in GitHub.