Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zombienet examples #1249

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
source ${HOME}/.cargo/env
rustup toolchain install nightly-2023-03-13
rustup default nightly-2023-03-13
cargo install taplo-cli
cargo install taplo-cli --locked
- name: cache cargo
uses: Swatinem/rust-cache@v2
- name: Check Formatting
Expand Down
72 changes: 72 additions & 0 deletions zombienet/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Manta's zombienet examples

## Docs and examples
- docs: https://paritytech.github.io/zombienet/
- examples:
- https://github.com/paritytech/zombienet/tree/main/examples
- https://github.com/paritytech/cumulus/tree/master/zombienet
- https://github.com/paritytech/polkadot/tree/master/zombienet_tests

## Install zombienet

According to your platform, download the latest pre-compiled binary from [zombinet](https://github.com/paritytech/zombienet/releases) repository.

## Start network

### Start one paracahin network locally by zombienet
1. Go to [small-network](./small-network.toml), make the `command` point to the polkadot binary and manta binary.
2. Start the network.
```shell
zombienet spawn --provider native small-network.toml
```
After a while, the network will be started.

### Start two parachains
1. Go to [two-parachains](./two-parachains.toml), make the `command` point to the polkadot binary and manta binary.
2. Start the network.
```shell
zombienet spawn --provider native two-parachains.toml
```
After a while, two paracahins(`2084` and `2104`) will be started.

## Testing

Zombienet supports testing as well, but you have to write test cases with a special dsl: `zndsl`.
Please take a look at this [doc](https://paritytech.github.io/zombienet/cli/test-dsl-definition-spec.html) to see more details about how to write test cases.

### Runtime upgrade(not ready)
1. Go to [runtime-upgrade](./runtime-upgrade.toml), make the `command` point to the polkadot binary and manta binary. And go to [runtime upgrade test case](./runtime-upgrade.zndsl), make sure `line 6` point to the correct wasm binary.
2. Run runtime upgrade.
```shell
zombienet -f --provider native test runtime-upgrade.zndsl
```
This test case would take minutes to be finished.

### Run you own customized test script
1. Go to [custom-script](./custom-script.toml), make the `command` point to the polkadot binary and manta binary.
2. Define and implement a function named `run` in your script.
```ts
async function run(nodeName, networkInfo, args) {
return 2084;
}
```
3. Go to the [custom-script test case](./custom-script.zndsl), make sure `line 8` point to your script, and compare the expected value.
```
Dave: js-script ./custom-script.js return is equal to 2084 within 300 seconds
```
4. Start the test.
```shell
zombienet -f --provider native test custom-script.zndsl
```

## Tips:
1. When run the network, please do not use the same node name for relaychain and parachain.
For example: if one relaychain node takes `Alice`, so you cannot use `Alice` for any parachain nodes, but you can use `alice`.
2. Please be careful the node name in your test case, you must understand what you want to test.
For example, if one relaychain node takes `Alice` as node, you can use `alice` for one of paracahin nodes, the `Alice` will test relaychain node, but `alice` is for parachain only.
```
alice: parachain 2084 is registered within 225 seconds
Alice: reports block height is at least 5 within 250 seconds
```
The first line will check parachain's block production, the second line will check relaychain's.
Because relaychain and parachain use the same node name, the zombienet's test framework won't know who is `Alice`.
10 changes: 10 additions & 0 deletions zombienet/examples/check-block-production.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description: Block Production Test
Network: ./small-network.toml
Creds: config

# metrics
Alice: reports node_roles is 4

# logs
alice: parachain 2084 is registered within 225 seconds
Alice: reports block height is at least 5 within 250 seconds
7 changes: 7 additions & 0 deletions zombienet/examples/custom-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const assert = require("assert");

async function run(nodeName, networkInfo, args) {
return 2084;
}

module.exports = { run }
48 changes: 48 additions & 0 deletions zombienet/examples/custom-script.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[settings]
timeout = 300

[relaychain]
chain = "rococo-local"
default_command = "polkadot-binary"

[[relaychain.nodes]]
name = "alice"
validator = true
ws_port = 9944

[[relaychain.nodes]]
name = "bob"
validator = true
ws_port = 9911

[[parachains]]
chain = "calamari-local"
cumulus_based = true
id = 2084

[[parachains.collators]]
command = "manta-binary"
name = "Alice"
rcp_port = 9967
validator = true
ws_port = 9921

[[parachains.collators]]
command = "manta-binary"
name = "Bob"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Charlie"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Dave"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Eve"
validator = true
8 changes: 8 additions & 0 deletions zombienet/examples/custom-script.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description: Runtime Upgrade Test
Network: ./custom-script.toml
Creds: config

alice: parachain 2084 is registered within 225 seconds
Bob: reports block height is at least 5 within 250 seconds
Dave: reports block height is at least 5 within 250 seconds
Dave: js-script ./custom-script.js return is equal to 2084 within 300 seconds
24 changes: 24 additions & 0 deletions zombienet/examples/runtime-upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const assert = require("assert");

async function run(nodeName, networkInfo, args) {
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
const api = await zombie.connect(wsUri, userDefinedTypes);

// get blockhash/runtimeVersion at block 1
const hashAtBlock1 = await api.rpc.chain.getBlockHash(1);
const versionAtBlock1 = await api.rpc.state.getRuntimeVersion(hashAtBlock1.toHuman());

// get blockhash/runtimeVersion at current head
const currentHeader = await api.rpc.chain.getHeader();
const hashAtCurrent = await api.rpc.chain.getBlockHash(currentHeader.number.toHuman());
const versionAtCurrent = await api.rpc.state.getRuntimeVersion(hashAtCurrent.toHuman());

const oldVersionIncremented = parseInt(versionAtBlock1.specVersion.toHuman(),10) + 1;
console.log("current", versionAtCurrent.specVersion.toHuman());
console.log("oldVersionIncremented", oldVersionIncremented);

// 2 == 2
assert.equal( oldVersionIncremented, versionAtCurrent.specVersion.toHuman(), "Running version should be the incremented version");
}

module.exports = { run }
48 changes: 48 additions & 0 deletions zombienet/examples/runtime-upgrade.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[settings]
timeout = 300

[relaychain]
chain = "rococo-local"
default_command = "polkadot-binary"

[[relaychain.nodes]]
name = "alice"
validator = true
ws_port = 9944

[[relaychain.nodes]]
name = "bob"
validator = true
ws_port = 9911

[[parachains]]
chain = "calamari-local"
cumulus_based = true
id = 2084

[[parachains.collators]]
command = "manta-binary"
name = "Alice"
rcp_port = 9967
validator = true
ws_port = 9921

[[parachains.collators]]
command = "manta-binary"
name = "Bob"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Charlie"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Dave"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Eve"
validator = true
9 changes: 9 additions & 0 deletions zombienet/examples/runtime-upgrade.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description: Runtime Upgrade Test
Network: ./runtime-upgrade.toml
Creds: config

alice: parachain 2084 is registered within 225 seconds
bob: parachain 2084 perform upgrade with ./calamari-runtime-v4400.compact.compressed.wasm within 300 seconds
Bob: reports block height is at least 5 within 250 seconds
Dave: reports block height is at least 5 within 250 seconds
Dave: js-script ./runtime.unpragde.js within 600 seconds
49 changes: 49 additions & 0 deletions zombienet/examples/small-network.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[settings]
timeout = 300

[relaychain]
chain = "rococo-local"
default_command = "polkadot-binary"

[[relaychain.nodes]]
name = "alice"
validator = true
ws_port = 9944

[[relaychain.nodes]]
name = "bob"
validator = true
ws_port = 9911

[[parachains]]
chain = "calamari-local"
# chain_spec_file = ""
cumulus_based = true
id = 2084

[[parachains.collators]]
command = "manta-binary"
name = "Alice" # cannot use alice here, alice has been occupied by one of relaychain node
rcp_port = 9967
validator = true
ws_port = 9921

[[parachains.collators]]
command = "manta-binary"
name = "Bob"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Charlie"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Dave"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Eve"
validator = true
76 changes: 76 additions & 0 deletions zombienet/examples/two-parachains.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[settings]
timeout = 300

[relaychain]
chain = "rococo-local"
default_command = "/home/jamie/my-repo/forks/jdeng/Manta/zombienet/polkadot"

[[relaychain.nodes]]
name = "eve"
validator = true
ws_port = 9944

[[relaychain.nodes]]
name = "bob"
validator = true
ws_port = 9911

[[parachains]]
chain = "calamari-local"
cumulus_based = true
default_command = "manta-binary"
id = 2084

[[parachains.collators]]
args = ["-lparachain=debug,xcm=trace"]
command = "manta-binary"
name = "Alice" # case sensitive, if you use `alice` here, zombienet will generate a key from alice-1
rcp_port = 9967
validator = true
ws_port = 9921

[[parachains.collators]]
command = "manta-binary"
name = "Bob"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Charlie"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Dave"
validator = true

[[parachains.collators]]
command = "manta-binary"
name = "Eve"
validator = true

[[parachains]]
chain = "manta-dev"
cumulus_based = true
default_command = "manta-binary"
id = 2104

[[parachains.collators]]
command = "manta-binary"
name = "Alice" # Alice-1
rcp_port = 9968
validator = true
ws_port = 9922
# args = ["-lparachain=debug"]

[[hrmp_channels]]
max_capacity = 4
max_message_size = 524288
recipient = 2084
sender = 2104

[[hrmp_channels]]
max_capacity = 4
max_message_size = 524288
recipient = 2104
sender = 2084