How to execute and deploy Move script?

Hi

I am able to run commands from Libra CLI but I am unsure how to execute examples given; what would the file extension and how would they run on Blockchain. Can anyone guide?

4 Likes

Good places to start are:

The file extension is .mvir

You can find many small Move IR examples in the tests. The easiest way to experiment with Move IR is to create a new test in this directory and follow the instructions for runnning the tests.

Just going to note down the steps I took to compile and run a Move script as I go along (note, this is a work in progress).

1. Clone and build the Libra Core

Instructions here: https://developers.libra.org/docs/my-first-transaction#clone-and-build-libra-core

2. Build the compiler

In the folder you installed Libra Core you, use cargo to build the compiler:

cargo build --bin compiler

You can read more about this: https://github.com/libra/libra/blob/master/language/compiler/README.md

3. Run the compiler

Navigate to the folder where the compiler was created:

cd target/debug

See what commands are available using:
./compiler --help

4. Compile a script

We’ll compile one of the available test scripts:

./compiler ../../language/functional_tests/tests/testsuite/examples/script.mvir

which will output:

CompiledProgram: {
Modules: [
],
Script: CompiledScript: {
Main:
	public 0x0.<SELF>.main(): ()
		locals(0): ,
		Ret
Struct Handles: []
Module Handles: [
	0x0.<SELF>,]
Function Handles: [
	0x0.<SELF>.main(): (),]
Type Signatures: []
Function Signatures: [
	(): (),]
Locals Signatures: [
	,]
Strings: [
	<SELF>,
	main,]
ByteArrays: []
Addresses: [
	0x0,]
}

}

Alternatively, you can compile the test script to a specific folder / location, using:

./compiler -o ../../language/functional_tests/tests/testsuite/examples/MYOUTPUTTEDFILE ../../language/functional_tests/tests/testsuite/examples/script.mvir

… Not sure what to do next, can anyone carry this on? :slight_smile:

7 Likes

Hi,

We have faced the same challenges and found work arounds using local environment, and help and discussion with the libra team. We documented our experience and shared our code. Check

4 Likes

Hi,

Move dev here. Right now the easiest way to run a custom move transaction is to write it as a test (.mvir file under libra/language/functional_tests/tests/testsuite/). You can then run the tests using the following commands:

// runs all the tests
cargo test -p functional_tests

// runs only the tests with "xyz" in the name
cargo test -p functional_tests xyz

@Omri has made an excellent tutorial on this and I recommend you check it out.

Note: tests are connected to an in-memory (fake) storage instead of a blockchain. We are also working on tools that will make this process easier so stay tuned.

7 Likes

Hello @vgao, could you please update this thread to make it up to date?
Is this information still actual?

How to get same output as in the question example these days? Is it still possible to get so verbose output? What should I do/use for it?

1 Like

@damirka With the latest update, you’ll need to set the environment variable PRETTY=1 to see the pretty printed AST/CompiledModule etc. On linux/mac os here’s what you do:

PRETTY=1 cargo test
# or
env PRETTY=1 cargo test

I’m also planning to write a manual/tutorial for this testing framework so stay tuned.

4 Likes

This directory (‘functional_tests’) doesn’t appear in my local copy when I follow these instructions. Instead, I do see scripts in sub-directories of …/…/language/ir-testsuite/tests. Did I miss something, or have the file locations changed? Thanks!

The instructions above may be completely out of date:

[johnk@localhost debug]$ ./compiler …/…/language/ir-testsuite/tests/move/modules/access_public_function.mvir
error: Parser Error

┌── …/…/language/ir-testsuite/tests/move/modules/access_public_function.mvir:1:1 ───

1 │ module M {
│ ^^^^^^ Invalid Token

thread ‘main’ panicked at ‘Failed to compile script: ParserError: Invalid Token’, language/compiler/src/main.rs:147:14
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[johnk@localhost debug]$ ./compiler …/…/language/ir-testsuite/tests/move/modules/access_private_function.mvir
error: Parser Error

┌── …/…/language/ir-testsuite/tests/move/modules/access_private_function.mvir:1:1 ───

1 │ module M {
│ ^^^^^^ Invalid Token

thread ‘main’ panicked at ‘Failed to compile script: ParserError: Invalid Token’, language/compiler/src/main.rs:147:14
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[johnk@localhost debug] ./compiler ../../language/ir-testsuite/tests/move/scripts/script_ script_too_few_type_args_inner.mvir script_too_many_type_args.mvir script_type_args_type_eq.mvir script_with_type_parameters.mvir script_too_few_type_args.mvir script_type_arg_kind_mismatch_1.mvir script_type_parameters_in_args.mvir script_too_many_type_args_inner.mvir script_type_arg_kind_mismatch_2.mvir script_with_generic_type_arg.mvir [johnk@localhost debug] ./compiler …/…/language/ir-testsuite/tests/move/scripts/script_type_args_type_eq.mvir
error: Parser Error

┌── …/…/language/ir-testsuite/tests/move/scripts/script_type_args_type_eq.mvir:1:1 ───

1 │ module M {
│ ^^^^^^ Invalid Token

thread ‘main’ panicked at ‘Failed to compile script: ParserError: Invalid Token’, language/compiler/src/main.rs:147:14
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace