How to set up a Zombienet for XCM testing
TL;DR
Zombienet is a testing framework for Substrate-based blockchains, providing a simple CLI tool that allows users to spawn any Substrate-based blockchains including Astar, with the Polkadot relaychain. The assertions used in the tests can include on-chain storage, metrics, logs, and custom javascript scripts that interact with the chain.
To test XCM-related features, there are mainly two options: Rococo or a local Zombienet. But some parachains may not deploy testnets to Rococo, or some XCM-related testings (XC-20 asset registration, HRMP channel opening, etc.) may require sudo
access to the testnet which is in the testnet operator’s hands. Thus, the ideal choice for XCM testings is local Zombienet.
In this guide, we will support you on how to set up Zombienet, how to spawn and configure the testnet with the latest release of the Polkadot relaychain, Astar, and how to test XCM-related features with local Zombienet.
What is Zombienet?
Zombienet is a testing framework for Substrate-based blockchains, providing a simple CLI tool that allows users to spawn any Substrate-based blockchains including Astar, and the Polkadot relaychain. The assertions used in the tests can include on-chain storage, metrics, logs, and custom javascript scripts that interact with the chain.
In this guide, we are setting up a local testnet environment with Polkadot relaychains with our parachains connected.
What is XCM?
Cross-Consensus Message Format (XCM) aims to be a language to communicate ideas between consensus systems. One of Polkadot's promises is interoperability, and XCM is the vehicle through which it will deliver this promise. Simply, it is a standard that allows protocol developers to define the data and origins that their chains can send and receive from, including cross-chain asset transfer between parachains.
Set up Zombienet CLI
In this section, we will set up Zombienet CLI using a binary. You can also set up Zombienet with docker, kubernetes, and more using the guide here.
-
Let’s create a folder in the root directory to hold the binaries
mkdir cookbook-zombienet
cd cookbook-zombienet -
Go to Zombienet and download the binary built for your local environment.
- Please don’t forget to replace the release version number in the command line to the latest release.
- In this cookbook, we are using Zombienet v1.3.22
-
Move the binary to our guide folder.
mv ~/downloads/zombienet-macos ~/cookbook-zombienet
-
Add execution permission to the Zombienet CLI binary file.
Note: if you are using a Mac, you may need an extra step to configure the security settings:- Go to Apple menu > System Settings > Privacy & Security.
- Under security, add the
astar
binary file that you just downloaded to the whitelist. - Continue with the following command.
chmod +x zombienet-macos
-
Confirm if the binary is executable in your local environment.
./zombienet-macos --help
-
When the Zombienet CLI is installed correctly, you should see the following info:
Usage: zombienet [options] [command]
Options:
-c, --spawn-concurrency <concurrency> Number of concurrent spawning process to launch, default is 1
-p, --provider <provider> Override provider to use (choices: "podman", "kubernetes", "native")
-m, --monitor Start as monitor, do not auto cleanup network
-d, --dir <path> Directory path for placing the network files instead of random temp one (e.g. -d /home/user/my-zombienet)
-f, --force Force override all prompt commands
-h, --help display help for comma
Build the polkadot
binary file
In order to spawn a testnet with a relaychain and two parachains, we need the corresponding binary files for Polkadot relaychain and Astar Network. In this section, we will build the polkadot
binary file.
-
First, let’s clone the
polkadot
source codegit clone https://github.com/paritytech/polkadot
-
Make sure you have the latest Rust and the support tools installed so that you can compile the
polkadot
source code smoothly.rustup update
brew install protobuf -
Checkout the latest release (v0.9.34 for now), compile the
polkadot
source code, and build thepolkadot
binary file.cd polkadot
git checkout release-v0.9.34
cargo build --release -
After the compilation, you will have a
polkadot
binary file. Rename the old Polkadot folder and move thepolkadot
binary to our guide folder.mv ~/cookbook-zombienet/polkadot ~/cookbook-zombienet/polkadot-built
mv ~/cookbook-zombienet/polkadot-built/target/release/polkadot ~/cookbook-zombienet
Download astar-collator
binary file
- Download the latest release of the astar-collator for macOS or Ubuntu from https://github.com/AstarNetwork/Astar/releases
Please make sure you are running a macOS or Ubuntu with the appropriate version. For macOS, please use the versions above MacOS 12.0.
-
Move the binary file to our cookbook folder.
mv ~/downloads/astar-collator ~/cookbook-zombienet
-
Add execution permission to the binary file
Note: if you are using a Mac, you may need an extra step to configure the security settings:- Go to Apple menu > System Settings > Privacy & Security.
- Under security, add the
astar
binary file that you just downloaded to the whitelist. - Continue with the following command.
chmod +x ./astar-collator
Download the configuration file for Zombienet
In order to spawn the Zombienet, we need to add a configuration file to specify the configurations. We have a configuration file ready that is configured to two parachains named shiden-dev
and shibuya-dev
, and a relaychain named rococo-local
: here.
- Download the configuration file from here.
curl -o multi_parachains.toml https://raw.githubusercontent.com/AstarNetwork/Astar/master/third-party/zombienet/multi_parachains.toml