Working With Move Contracts
Last updated
Last updated
The Endless CLI is mostly used to compile, test, and formally verify Move contracts. If you have not installed the Endless CLI yet, you can do so by following the steps here Install the Endless CLI.
You can jump to sections here:
Compiling Move
Unit Testing Move Contracts
Generating Test Coverage Reports
Publishing Move Contracts
Running Published Contracts
(Optional) Formally Verifying Move Scripts
To see how to chain together Move contracts on-chain using the CLI, you can follow this "CLI Arguments" tutorial.
You can compile a Move package by running:
Based on the settings in your Move.toml
file, you may need to pass in additional information to that compile command.
For example, if you look at the , in the Move.toml
file it specifies a variable named address called hello_blockchain
.
So, to compile this, you will need to pass in the value for hello_blockchain
with the --named-addresses
parameter.
You can learn more about optional parameters when compiling Move contracts by running endless move compile --help
.
The Endless CLI can also be used to compile and run unit tests locally by running:
This command both compiles and runs tests, so it needs all the same optional parameters you use when compiling.
You can learn more about the optional parameters for testing move contracts by running endless move test --help.
Printing Debugging Information
Run endless move test
.
You should see:
The Endless CLI can be used to analyze and improve the testing of your Move modules. To use this feature:
To see the code coverage of your tests run the following command from your Move package’s directory:
If you would like to focus your coverage down to specific packages, you can do so with the --filter
option. To narrow even further to specific Move modules, use the --module
parameter.
For more detailed / advanced coverage information (such as your test coverage in the compiled bytecode) you can run endless move coverage
. With that command, the CLI will prompt you for more details on what specifically you would like more coverage information about.
You can learn more about optional parameters for test coverage by running endless move test --help
and endless move coverage --help
.
To publish a Move contract, you will need to run:
Note that when you are publishing on the main network, the credentials you pass into optional parameters like --named-addresses
will need to reflect accounts on that network instead of test credentials.
The package will be published to your default profile in the CLI. You can override that to specify which account to publish to using --profile
in the command. To generate a new profile for a specific account, use endless init --profile <name_of_profile>
and follow the prompts.
Please also note that when publishing Move modules, if multiple modules are in one package, then all modules in that package must use the same account. If they use different accounts, then the publishing will fail at the transaction level.
You can estimate the gas fees associated with publishing your Move contract by using the Gas Profiler.
:::caution By default Move contracts publish their source code. To avoid publishing with source code, publish with the --included-artifacts none
argument.
Since the Endless blockchain is inherently open by design, note that even without source access it is possible to regenerate Move source from published Move bytecode. :::
Now that you have published your Move package, you can run it directly from the CLI.
You will first need to construct your function-id
by combining:
You can then pass in args by using the --args
parameter.
Which should result in:
For cases where you want to guarantee that your code works as expected beyond unit testing, you can use the Move Prover to formally verify your Move contract code.
Once you have installed the Move Prover, you can use it from the Endless CLI by running:
When writing tests, it can be helpful to print out debug information or stack traces. You can do that by using debug::print
and debug::print_stack_trace
to print information when you use endless move test
. See an example of how they are used in .
To see the output of testing ’s package:
Clone .
Navigate to the by running cd crates/endless/debug-move-example
.
For more on how to write unit tests with Move, follow this .
As an example, if you were to have published the to an account with an address b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb
you could run its set_message
function via the following command:
To learn how to formally verify your code, please follow the in-depth Move tutorial (step 7 and 8 cover how to use the Move Prover and write formal specifications in the example code).