Move language for Libra blockchain — how to run tests and compile scripts / modules ?

Paulina Błaszkiewicz
Jul 11 · 3 min read

Move is a new programming language for the Libra Blockchain. It enables implementation of smart contracts and custom transaction logic. Four key features of Move language are: first-class assets, flexibility, safety, and verifiability.

Now there is available Move intermediate representation (IR). It is very early and unstable version of the language and in the future it will be replaced with a higher-level Move language. But we can use Move IR to play with scripts and modules for Libra Blockchain. At the moment, as we can read in Libra documentation (https://developers.libra.org/docs/move-overview ), there is no possibility to deploy Move scripts or modules to the testnet:

Custom Move programs are not supported in the initial testnet release, but these features are available for you to try out locally

But what can we do now is testing or compiling Move modules / scripts.

1. Preparing environment

At the beginning we have to clone and setup Libra Core

git clone https://github.com/libra/libra.git

cd libra
./scripts/dev_setup.sh

2. Testing Move modules

2.1 Preparing .mvir file for testing

Due to a Medium issue — the github code is not displayed in Safari. Use a different browser to view all content

We will use example module from Libra docs.

First we have to go to the test directory

libra/language/functional_tests/tests/testsuite/modules

and create a file move_test_module.mvir

At the end of the file, after the module, we have added empty script to make our file to compile properly:

script:
main() {
return;
}

In the end you can delete this part of the file and check what will happened.

Explanation of how to create modules and scripts is beyond the scope of this article. You can find many examples in libra/language/functional_tests/tests/testsuite/modules directory or in Libra docs:

2.2 Running tests

To start testing our file we need to run a command

cargo test -p functional_tests <file_name>

So in our case it will be

cargo test -p functional_tests move_test_module.mvir

As a result we get:

3. Compiling Move scripts and modules using Move IR Compiler

3.1 Move IR Compiler

Instead of test you can use Move IR compiler directly:

The Move IR compiler compiles modules and scripts written in Move down to their respective bytecode representations

3.2 Preparing .mvir files

We will use our move_test_module.mvir file and we will also create another one with simple script from Libra docs - move_test_script.mvir

Now we can create for exampletest directory in main dir and copy both files there.

3.3 Compiling scripts and modules

To compile our files we need to run a command:

cargo run -p compiler <file_path>

So now we have to run it for our both files:

cargo run -p compiler ./test/move_test_module.mvir
cargo run -p compiler ./test/move_test_script.mvir

If the compilation was successful, as a result we will see our script/ module compiled to the Move bytecode:

This article shows in a few simple steps how to test and compile Move modules /scripts. Now we are waiting for possibility to deploy them to the testnet!

Featly

Loyalty programs on the blockchain

Paulina Błaszkiewicz

Written by

I work as a blockchain developer in Featly start-up. I find a real flow in programming, learning new things and practicing yoga. Love good coffee

Featly

Featly

Loyalty programs on the blockchain

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade