Skip to content

Commit 8dab745

Browse files
nhussein11[Your Name]
andcommitted
Add Zombienet documentation for testing framework (#1300)
* Introduce Zombienet as a testing framework for Polkadot SDK-based blockchain networks. * Detail installation methods including executable, Nix, and Docker. * Outline key features, configuration options, and CLI commands for network spawning and testing. * Provide examples for basic configuration and test file structure. Co-authored-by: [Your Name] <[email protected]>
1 parent b91301c commit 8dab745

File tree

1 file changed

+327
-1
lines changed

1 file changed

+327
-1
lines changed

.reference/tools/zombienet.md

Lines changed: 327 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,327 @@
1-
TODO
1+
---
2+
title: Zombienet
3+
description: Zombienet is a testing framework for Polkadot SDK-based blockchain networks, enabling developers to deploy and test ephemeral environments across various platforms.
4+
categories: Parachains, Tooling
5+
---
6+
7+
# Zombienet
8+
9+
## Introduction
10+
11+
Zombienet is a testing framework designed for Polkadot SDK-based blockchain networks. It enables developers to efficiently deploy and test ephemeral blockchain environments on platforms like Kubernetes, Podman, and native setups. With its simple CLI and Domain Specific Language (DSL) for writing tests, Zombienet streamlines network spawning, testing, and performance validation.
12+
13+
Key features include:
14+
15+
- **Multi-provider support**: Run networks on Kubernetes, Podman, or locally as native processes.
16+
- **Network orchestration**: Spawn relay chains with multiple validators and parachains with collators.
17+
- **Test DSL**: Write natural-language test scripts to evaluate metrics, logs, events, and on-chain storage.
18+
- **Monitoring integration**: Built-in support for Prometheus, Grafana, and Tempo on supported providers.
19+
20+
## Install Zombienet
21+
22+
Zombienet releases are available on the [Zombienet repository](https://github.com/paritytech/zombienet){target=\_blank}. Choose one of the following installation methods:
23+
24+
=== "Use the executable"
25+
26+
Download the appropriate executable for your operating system from the [latest release](https://github.com/paritytech/zombienet/releases){target=\_blank} page. Each release includes executables for Linux and macOS, generated using [pkg](https://github.com/vercel/pkg){target=\_blank}, which allows Zombienet to run without Node.js.
27+
28+
Make the downloaded file executable:
29+
30+
```bash
31+
chmod +x zombienet-{{ dependencies.repositories.zombienet.architecture }}
32+
```
33+
34+
Verify the installation:
35+
36+
```bash
37+
./zombienet-{{ dependencies.repositories.zombienet.architecture }} version
38+
```
39+
40+
Optionally, move the executable to your PATH:
41+
42+
```bash
43+
mv zombienet-{{ dependencies.repositories.zombienet.architecture }} /usr/local/bin/zombienet
44+
```
45+
46+
Now you can use the `zombienet` command directly:
47+
48+
```bash
49+
zombienet version
50+
```
51+
52+
=== "Use Nix"
53+
54+
For Nix users, the Zombienet repository provides a [`flake.nix`](https://github.com/paritytech/zombienet/blob/main/flake.nix){target=\_blank} file. You need [Flakes](https://nixos.wiki/wiki/Flakes#Enable_flakes){target=\_blank} enabled.
55+
56+
Run Zombienet directly:
57+
58+
```bash
59+
nix run github:paritytech/zombienet/INSERT_ZOMBIENET_VERSION -- \
60+
spawn INSERT_ZOMBIENET_CONFIG_FILE_NAME.toml
61+
```
62+
63+
Or include Zombienet in your current shell:
64+
65+
```bash
66+
nix shell github:paritytech/zombienet/INSERT_ZOMBIENET_VERSION
67+
```
68+
69+
=== "Use Docker"
70+
71+
Run Zombienet using Docker:
72+
73+
```bash
74+
docker run -it --rm \
75+
-v $(pwd):/home/nonroot/zombie-net/host-current-files \
76+
paritytech/zombienet
77+
```
78+
79+
Inside the container, set up the necessary binaries:
80+
81+
```bash
82+
npm run zombie -- setup polkadot polkadot-parachain
83+
```
84+
85+
Add the binaries to your PATH:
86+
87+
```bash
88+
export PATH=/home/nonroot/zombie-net:$PATH
89+
```
90+
91+
Spawn a network:
92+
93+
```bash
94+
npm run zombie -- -p native spawn host-current-files/minimal.toml
95+
```
96+
97+
## Providers
98+
99+
Zombienet supports different backend providers for running nodes: [Kubernetes](https://kubernetes.io/){target=\_blank}, [Podman](https://podman.io/){target=\_blank}, and native (local processes). Specify the provider using the `--provider` flag or in your network configuration file:
100+
101+
```bash
102+
zombienet spawn network.toml --provider INSERT_PROVIDER
103+
```
104+
105+
Or set it in the configuration:
106+
107+
```toml title="network.toml"
108+
[settings]
109+
provider = "INSERT_PROVIDER"
110+
...
111+
```
112+
113+
### Kubernetes
114+
115+
Kubernetes is compatible with [GKE](https://cloud.google.com/kubernetes-engine){target=\_blank}, [Docker Desktop](https://docs.docker.com/desktop/features/kubernetes/){target=\_blank}, and [kind](https://kind.sigs.k8s.io/){target=\_blank}.
116+
117+
- **Requirements**: Install [`kubectl`](https://kubernetes.io/docs/tasks/tools/#kubectl){target=\_blank} and ensure proper cluster permissions.
118+
- **Features**: Uses Prometheus operator for monitoring when available.
119+
120+
### Podman
121+
122+
Podman is a daemonless container engine that works on Linux-based systems. Zombienet supports Podman rootless as a provider.
123+
124+
- **Requirements**: Install [Podman](https://podman.io/getting-started/installation){target=\_blank} on Linux.
125+
126+
- **Features**: Deploys Prometheus, Tempo, and Grafana for monitoring. Services are accessible at `http://127.0.0.1:34123` (Prometheus), `http://127.0.0.1:34125` (Tempo), and `http://127.0.0.1:41461` (Grafana).
127+
128+
### Native
129+
130+
The native provider runs nodes as local processes on your machine.
131+
132+
- **Requirements**: Have the necessary binaries (`polkadot`, `polkadot-parachain`) in your PATH. Install them using:
133+
134+
```bash
135+
zombienet setup polkadot polkadot-parachain
136+
```
137+
138+
For custom binaries, specify the path in your configuration or add them to your PATH:
139+
140+
```bash
141+
export PATH=$PATH:INSERT_PATH_TO_BINARY
142+
```
143+
144+
- **Features**: No additional monitoring features.
145+
146+
## Configure Zombienet
147+
148+
Zombienet uses configuration files in JSON or TOML format to define network topology, nodes, and parameters. The [Zombienet repository](https://github.com/paritytech/zombienet/tree/main/examples){target=\_blank} provides example configurations.
149+
150+
### Basic Configuration
151+
152+
A minimal configuration includes settings, relay chain configuration, and parachain configuration:
153+
154+
=== "TOML"
155+
156+
```toml title="basic-network.toml"
157+
[settings]
158+
timeout = 1000
159+
160+
[relaychain]
161+
chain = "rococo-local"
162+
default_command = "polkadot"
163+
164+
[[relaychain.nodes]]
165+
name = "alice"
166+
validator = true
167+
168+
[[relaychain.nodes]]
169+
name = "bob"
170+
validator = true
171+
172+
[[parachains]]
173+
id = 1000
174+
chain = "asset-hub-rococo-local"
175+
176+
[parachains.collator]
177+
name = "collator-01"
178+
command = "polkadot-parachain"
179+
```
180+
181+
=== "JSON"
182+
183+
```json title="basic-network.json"
184+
{
185+
"settings": {
186+
"timeout": 1000
187+
},
188+
"relaychain": {
189+
"chain": "rococo-local",
190+
"default_command": "polkadot",
191+
"nodes": [
192+
{
193+
"name": "alice",
194+
"validator": true
195+
},
196+
{
197+
"name": "bob",
198+
"validator": true
199+
}
200+
]
201+
},
202+
"parachains": [
203+
{
204+
"id": 1000,
205+
"chain": "asset-hub-rococo-local",
206+
"collator": {
207+
"name": "collator-01",
208+
"command": "polkadot-parachain"
209+
}
210+
}
211+
]
212+
}
213+
```
214+
215+
### CLI Commands
216+
217+
Zombienet provides the following commands:
218+
219+
- **`spawn <networkConfig>`**: Spawn the network defined in the configuration file.
220+
- **`test <testFile>`**: Run tests on the spawned network.
221+
- **`setup <binaries>`**: Download and set up `polkadot` or `polkadot-parachain` binaries.
222+
- **`convert <filePath>`**: Convert a [polkadot-launch](https://github.com/paritytech/polkadot-launch){target=\_blank} configuration to Zombienet format.
223+
- **`version`**: Print Zombienet version.
224+
- **`help`**: Print help information.
225+
226+
Common flags:
227+
228+
- **`-p`, `--provider`**: Override the provider.
229+
- **`-d`, `--dir`**: Specify directory for network files.
230+
- **`-m`, `--monitor`**: Start as monitor without auto cleanup.
231+
- **`-c`, `--spawn-concurrency`**: Number of concurrent spawning processes.
232+
233+
## Spawn a Network
234+
235+
To spawn a network, create a configuration file and run:
236+
237+
```bash
238+
zombienet spawn network.toml --provider native
239+
```
240+
241+
Zombienet will:
242+
243+
1. Download or locate the required binaries.
244+
2. Generate chain specifications.
245+
3. Start relay chain validators.
246+
4. Register and start parachain collators.
247+
5. Display connection endpoints and logs.
248+
249+
Access the running nodes via the provided RPC endpoints (typically `ws://127.0.0.1:9944` for the first node).
250+
251+
## Write Tests
252+
253+
Zombienet provides a Domain Specific Language (DSL) for writing tests in `.zndsl` files. Tests can evaluate:
254+
255+
- Metrics from Prometheus.
256+
- Log patterns.
257+
- System events.
258+
- On-chain storage.
259+
- Custom JavaScript/TypeScript scripts.
260+
261+
### Test File Structure
262+
263+
Test files contain a header and body:
264+
265+
```toml title="example-test.zndsl"
266+
Description: Example test suite
267+
Network: ./network.toml
268+
Creds: config
269+
270+
# Test assertions
271+
alice: is up
272+
bob: is up
273+
alice: parachain 1000 is registered within 200 seconds
274+
alice: parachain 1000 block height is at least 10 within 300 seconds
275+
```
276+
277+
### Run Tests
278+
279+
Execute tests using:
280+
281+
```bash
282+
zombienet test example-test.zndsl --provider native
283+
```
284+
285+
The test runner will execute each assertion and report pass/fail status.
286+
287+
### Common Assertions
288+
289+
Some frequently used assertions include:
290+
291+
- **Well-known functions**: `alice: is up`, `alice: parachain 100 is registered within 225 seconds`.
292+
- **Metrics**: `alice: reports node_roles is 4`.
293+
- **Logs**: `alice: log line matches glob "rted #1" within 10 seconds`.
294+
- **System events**: `alice: system event matches ""paraId":[0-9]+" within 10 seconds`.
295+
- **Custom scripts**: `alice: js-script ./script.js return is greater than 1 within 200 seconds`.
296+
297+
## Configuration Reference
298+
299+
For detailed configuration options, see:
300+
301+
- [Configuration examples](https://github.com/paritytech/zombienet/tree/main/examples){target=\_blank} - Sample configurations for various scenarios.
302+
- [Testing DSL specification](https://paritytech.github.io/zombienet/cli/test-dsl-definition-spec.html){target=\_blank} - Complete DSL syntax reference.
303+
- [Zombienet book](https://paritytech.github.io/zombienet/){target=\_blank} - Comprehensive documentation.
304+
305+
## Where to Go Next
306+
307+
<div class="grid cards" markdown>
308+
309+
- <span class="badge tutorial">Tutorial</span> __Spawn a Basic Chain with Zombienet__
310+
311+
---
312+
313+
Learn to spawn, connect to, and monitor a basic blockchain network with Zombienet using customizable configurations.
314+
315+
[:octicons-arrow-right-24: Get Started](/tutorials/polkadot-sdk/testing/spawn-basic-chain/)
316+
317+
- <span class="badge external">External</span> __Zombienet Support__
318+
319+
---
320+
321+
For further support and information, refer to the official resources.
322+
323+
[:octicons-arrow-right-24: GitHub Repository](https://github.com/paritytech/zombienet){target=\_blank}
324+
325+
[:octicons-arrow-right-24: Element Channel](https://matrix.to/#/!FWyuEyNvIFygLnWNMh:parity.io?via=parity.io&via=matrix.org&via=web3.foundation){target=\_blank}
326+
327+
</div>

0 commit comments

Comments
 (0)