From 807db6ff0ddad09c5bde27df9fe79f1f3cc3478d Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Thu, 18 Aug 2022 12:59:36 -0300 Subject: [PATCH] Zombienet add tests (#1321) * changes to read json spec in test binary * add zombienet tests * fmt * use {{COL_IMAGE}} and clean config * add comment and use relay image from env * use test-parachain image from pr * fix warns * fix warns * fmt * typo * fix ci to use zombienet image * fix spawn nodes for test * reorg test * add within to test * remove check for full node collators is up * add tests for pov, mirate solo to para, sync blocks * bump zombienet image * add job dep with artifacts * add sleep for test * fix after merge * fmt * bump zombienet version * changes from clap * use base/shared params * fmt * debug ci * add upgrade test * update js test for debug * less debug in test * print assertion * fix upgrade test * Collator key only needed if we run as collator * [Fix] Benchmark build artifact folder creation (#1518) * Trivial networking changes for Substrate PR #11940 (#1486) * Trivial networking changes for Substrate PR https://github.com/paritytech/substrate/pull/11940 * Apply formatting rules * update lockfile for {"polkadot", "substrate"} Co-authored-by: parity-processbot <> * bump zombienet version * update network def for test * typo Co-authored-by: Sebastian Kunert Co-authored-by: Roman Useinov Co-authored-by: Nazar Mokrynskyi --- cumulus/.gitlab-ci.yml | 168 ++++++++++++++++++ cumulus/test/service/src/cli.rs | 13 +- cumulus/test/service/src/lib.rs | 2 +- cumulus/test/service/src/main.rs | 37 ++-- ...rom_tip_without_connected_collator.feature | 6 +- ...s_from_tip_without_connected_collator.toml | 24 ++- .../zombienet_tests/0002-pov_recovery.feature | 2 +- .../zombienet_tests/0002-pov_recovery.toml | 20 +-- ...ure => 0003-full_node_catching_up.feature} | 5 +- ...p.toml => 0003-full_node_catching_up.toml} | 20 +-- .../0004-runtime_upgrade.feature | 13 ++ .../zombienet_tests/0004-runtime_upgrade.toml | 33 ++++ .../0005-migrate_solo_to_para.feature | 13 ++ .../0005-migrate_solo_to_para.toml | 45 +++++ .../zombienet_tests/migrate_solo_to_para.js | 57 ++++++ cumulus/zombienet_tests/runtime_upgrade.js | 24 +++ 16 files changed, 425 insertions(+), 57 deletions(-) rename cumulus/zombienet_tests/{0003-test_full_node_catching_up.feature => 0003-full_node_catching_up.feature} (75%) rename cumulus/zombienet_tests/{0003-test_full_node_catching_up.toml => 0003-full_node_catching_up.toml} (65%) create mode 100644 cumulus/zombienet_tests/0004-runtime_upgrade.feature create mode 100644 cumulus/zombienet_tests/0004-runtime_upgrade.toml create mode 100644 cumulus/zombienet_tests/0005-migrate_solo_to_para.feature create mode 100644 cumulus/zombienet_tests/0005-migrate_solo_to_para.toml create mode 100644 cumulus/zombienet_tests/migrate_solo_to_para.js create mode 100644 cumulus/zombienet_tests/runtime_upgrade.js diff --git a/cumulus/.gitlab-ci.yml b/cumulus/.gitlab-ci.yml index e11e2814a8..fb8e950bcc 100644 --- a/cumulus/.gitlab-ci.yml +++ b/cumulus/.gitlab-ci.yml @@ -11,6 +11,7 @@ stages: - benchmarks-build - benchmarks-run - publish + - integration-test default: interruptible: true @@ -28,6 +29,7 @@ variables: CI_IMAGE: "paritytech/ci-linux:production" DOCKER_OS: "debian:stretch" ARCH: "x86_64" + ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.2.53" .collect-artifacts: &collect-artifacts artifacts: @@ -84,6 +86,15 @@ variables: rules: - if: $CI_COMMIT_REF_NAME =~ /^release-parachains-v[0-9].*$/ # i.e. release-parachains-v1.0, release-parachains-v2.1rc1, release-parachains-v3000 +.zombienet-refs: &zombienet-refs + rules: + - if: $CI_PIPELINE_SOURCE == "pipeline" + when: never + - if: $CI_PIPELINE_SOURCE == "schedule" + when: never + - if: $CI_COMMIT_REF_NAME == "master" + - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs + .docker-env: &docker-env image: "${CI_IMAGE}" before_script: @@ -212,6 +223,8 @@ build-test-parachain: - echo "___Packing the artifacts___" - mkdir -p ./artifacts - mv ./target/release/test-parachain ./artifacts/. + - mkdir -p ./artifacts/zombienet + - mv ./target/release/wbuild/cumulus-test-runtime/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm ./artifacts/zombienet/. #### stage: publish @@ -395,6 +408,161 @@ update-parachain-template: --github-api-token "$GITHUB_TOKEN" --polkadot-branch "$CI_COMMIT_REF_NAME" +#### stage: integration-test + +zombienet-0001-sync_blocks_from_tip_without_connected_collator: + stage: integration-test + image: "${ZOMBIENET_IMAGE}" + <<: *zombienet-refs + needs: + - job: build-push-image-test-parachain + variables: + POLKADOT_IMAGE: "docker.io/paritypr/polkadot-debug:master" + GH_DIR: "https://github.com/paritytech/cumulus/tree/${CI_COMMIT_SHORT_SHA}/zombienet_tests" + COL_IMAGE: "docker.io/paritypr/test-parachain:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + before_script: + - echo "Zombie-net Tests Config" + - echo "${ZOMBIENET_IMAGE}" + - echo "${RELAY_IMAGE}" + - echo "${COL_IMAGE}" + - echo "${GH_DIR}" + - export DEBUG=zombie + - export RELAY_IMAGE=${POLKADOT_IMAGE} + - export COL_IMAGE=${COL_IMAGE} + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh + --github-remote-dir="${GH_DIR}" + --concurrency=1 + --test="0001-sync_blocks_from_tip_without_connected_collator.feature" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test + +zombienet-0002-pov_recovery: + stage: integration-test + image: "${ZOMBIENET_IMAGE}" + <<: *zombienet-refs + needs: + - job: build-push-image-test-parachain + variables: + POLKADOT_IMAGE: "docker.io/paritypr/polkadot-debug:master" + GH_DIR: "https://github.com/paritytech/cumulus/tree/${CI_COMMIT_SHORT_SHA}/zombienet_tests" + COL_IMAGE: "docker.io/paritypr/test-parachain:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + before_script: + - echo "Zombie-net Tests Config" + - echo "${ZOMBIENET_IMAGE}" + - echo "${RELAY_IMAGE}" + - echo "${COL_IMAGE}" + - echo "${GH_DIR}" + - export DEBUG=zombie + - export RELAY_IMAGE=${POLKADOT_IMAGE} + - export COL_IMAGE=${COL_IMAGE} + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh + --github-remote-dir="${GH_DIR}" + --concurrency=1 + --test="0002-pov_recovery.feature" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test + +zombienet-0003-full_node_catching_up: + stage: integration-test + image: "${ZOMBIENET_IMAGE}" + <<: *zombienet-refs + needs: + - job: build-push-image-test-parachain + variables: + POLKADOT_IMAGE: "docker.io/paritypr/polkadot-debug:master" + GH_DIR: "https://github.com/paritytech/cumulus/tree/${CI_COMMIT_SHORT_SHA}/zombienet_tests" + COL_IMAGE: "docker.io/paritypr/test-parachain:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + before_script: + - echo "Zombie-net Tests Config" + - echo "${ZOMBIENET_IMAGE}" + - echo "${RELAY_IMAGE}" + - echo "${COL_IMAGE}" + - echo "${GH_DIR}" + - export DEBUG=zombie + - export RELAY_IMAGE=${POLKADOT_IMAGE} + - export COL_IMAGE=${COL_IMAGE} + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh + --github-remote-dir="${GH_DIR}" + --concurrency=1 + --test="0003-full_node_catching_up.feature" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test + +zombienet-0004-runtime_upgrade: + stage: integration-test + image: "${ZOMBIENET_IMAGE}" + <<: *zombienet-refs + needs: + - job: build-push-image-test-parachain + - job: build-test-parachain + artifacts: true + variables: + POLKADOT_IMAGE: "docker.io/paritypr/polkadot-debug:master" + GH_DIR: "https://github.com/paritytech/cumulus/tree/${CI_COMMIT_SHORT_SHA}/zombienet_tests" + COL_IMAGE: "docker.io/paritypr/test-parachain:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + before_script: + - ls -ltr * + - cp ./artifacts/zombienet/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm /tmp/ + - ls /tmp + - echo "Zombie-net Tests Config" + - echo "${ZOMBIENET_IMAGE}" + - echo "${RELAY_IMAGE}" + - echo "${COL_IMAGE}" + - echo "${GH_DIR}" + - export DEBUG=zombie + - export RELAY_IMAGE=${POLKADOT_IMAGE} + - export COL_IMAGE=${COL_IMAGE} + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh + --github-remote-dir="${GH_DIR}" + --concurrency=1 + --test="0004-runtime_upgrade.feature" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test + +zombienet-0005-migrate_solo_to_para: + stage: integration-test + image: "${ZOMBIENET_IMAGE}" + <<: *zombienet-refs + needs: + - job: build-push-image-test-parachain + - job: build-test-parachain + artifacts: true + variables: + POLKADOT_IMAGE: "docker.io/paritypr/polkadot-debug:master" + GH_DIR: "https://github.com/paritytech/cumulus/tree/${CI_COMMIT_SHORT_SHA}/zombienet_tests" + COL_IMAGE: "docker.io/paritypr/test-parachain:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + before_script: + - ls -ltr * + - echo "Zombie-net Tests Config" + - echo "${ZOMBIENET_IMAGE}" + - echo "${RELAY_IMAGE}" + - echo "${COL_IMAGE}" + - echo "${GH_DIR}" + - export DEBUG=zombie + - export RELAY_IMAGE=${POLKADOT_IMAGE} + - export COL_IMAGE=${COL_IMAGE} + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh + --github-remote-dir="${GH_DIR}" + --concurrency=1 + --test="0005-migrate_solo_to_para.feature" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test + #### stage: .post # This job cancels the whole pipeline if any of provided jobs fail. diff --git a/cumulus/test/service/src/cli.rs b/cumulus/test/service/src/cli.rs index f8c4fecb03..595c8d42aa 100644 --- a/cumulus/test/service/src/cli.rs +++ b/cumulus/test/service/src/cli.rs @@ -288,9 +288,16 @@ impl SubstrateCli for TestCollatorCli { 2017 } - fn load_spec(&self, _: &str) -> std::result::Result, String> { - Ok(Box::new(cumulus_test_service::get_chain_spec(ParaId::from(self.parachain_id))) - as Box<_>) + fn load_spec(&self, id: &str) -> std::result::Result, String> { + Ok(match id { + "" => Box::new(cumulus_test_service::get_chain_spec(ParaId::from(self.parachain_id))) + as Box<_>, + path => { + let chain_spec = + cumulus_test_service::chain_spec::ChainSpec::from_json_file(path.into())?; + Box::new(chain_spec) + }, + }) } fn native_runtime_version(_: &Box) -> &'static RuntimeVersion { diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 28c52ac8f7..844b0f9138 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -18,7 +18,7 @@ #![warn(missing_docs)] -mod chain_spec; +pub mod chain_spec; mod genesis; use std::{ diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index fadbd3539c..b87a8ed191 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -16,7 +16,7 @@ mod cli; -use std::sync::Arc; +use std::{io::Write, sync::Arc}; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_client_cli::generate_genesis_block; @@ -43,14 +43,31 @@ fn main() -> Result<(), sc_cli::Error> { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) }, - Some(Subcommand::ExportGenesisState(cmd)) => { - let runner = cli.create_runner(cmd)?; - runner.sync_run(|_config| { - let parachain_id = ParaId::from(cmd.parachain_id); - let spec = cumulus_test_service::get_chain_spec(parachain_id); - let state_version = cumulus_test_service::runtime::VERSION.state_version(); - cmd.base.run::(&spec, state_version) - }) + + Some(Subcommand::ExportGenesisState(params)) => { + let mut builder = sc_cli::LoggerBuilder::new(""); + builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); + let _ = builder.init(); + + let spec = + cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; + let state_version = cumulus_test_service::runtime::VERSION.state_version(); + + let block: parachains_common::Block = generate_genesis_block(&*spec, state_version)?; + let raw_header = block.header().encode(); + let output_buf = if params.base.raw { + raw_header + } else { + format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() + }; + + if let Some(output) = ¶ms.base.output { + std::fs::write(output, output_buf)?; + } else { + std::io::stdout().write_all(&output_buf)?; + } + + Ok(()) }, Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -106,7 +123,7 @@ fn main() -> Result<(), sc_cli::Error> { if config.role.is_authority() { "yes" } else { "no" } ); - let collator_key = Some(CollatorPair::generate().0); + let collator_key = config.role.is_authority().then(|| CollatorPair::generate().0); let consensus = cli .use_null_consensus diff --git a/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.feature b/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.feature index 6f84041c07..68620d03ab 100644 --- a/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.feature +++ b/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.feature @@ -1,4 +1,4 @@ -Description: Small Network test +Description: Sync blocks from tip without connected collator test Network: ./0001-sync_blocks_from_tip_without_connected_collator.toml Creds: config @@ -7,11 +7,9 @@ alice: is up bob: is up charlie: is up dave: is up -ferdie: is up -eve: is up alice: parachain 2000 is registered within 225 seconds alice: parachain 2000 block height is at least 10 within 250 seconds ferdie: reports block height is at least 12 within 250 seconds -eve: reports block height is at least 12 within 250 seconds +eve: reports block height is at least 12 within 250 seconds \ No newline at end of file diff --git a/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.toml b/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.toml index 8f2d8a3a8c..c0d49b3129 100644 --- a/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.toml +++ b/cumulus/zombienet_tests/0001-sync_blocks_from_tip_without_connected_collator.toml @@ -1,5 +1,5 @@ [relaychain] -default_image = "docker.io/paritypr/polkadot-debug:master" +default_image = "{{RELAY_IMAGE}}" default_command = "polkadot" default_args = [ "-lparachain=debug" ] @@ -11,9 +11,7 @@ chain = "rococo-local" [[relaychain.nodes]] name = "bob" - image = "docker.io/paritypr/polkadot-debug:5236-0.9.18-c55660e9-be16bd72" validator = true - args = ["--database=paritydb-experimental"] [[parachains]] id = 2000 @@ -23,30 +21,30 @@ cumulus_based = true [[parachains.collators]] name = "charlie" validator = true - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" + image = "{{COL_IMAGE}}" + command = "test-parachain" args = ["-lparachain=debug"] # run dave as parachain full node [[parachains.collators]] name = "dave" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" + image = "{{COL_IMAGE}}" + command = "test-parachain" args = ["-lparachain=debug"] # run eve as parachain full node that is only connected to dave [[parachains.collators]] name = "eve" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'dave'|zombie}}"] + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'dave'|zombie('multiAddress')}}"] # run ferdie as parachain full node that is only connected to dave [[parachains.collators]] name = "ferdie" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'dave'|zombie}}"] \ No newline at end of file + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'dave'|zombie('multiAddress')}}", "--relay-chain-rpc-url {{'alice'|zombie('wsUri')}}"] diff --git a/cumulus/zombienet_tests/0002-pov_recovery.feature b/cumulus/zombienet_tests/0002-pov_recovery.feature index 5f33c5ff4a..fa9836e264 100644 --- a/cumulus/zombienet_tests/0002-pov_recovery.feature +++ b/cumulus/zombienet_tests/0002-pov_recovery.feature @@ -1,4 +1,4 @@ -Description: Small Network test +Description: PoV recovery test Network: ./0002-pov_recovery.toml Creds: config diff --git a/cumulus/zombienet_tests/0002-pov_recovery.toml b/cumulus/zombienet_tests/0002-pov_recovery.toml index 5913cf8275..fc62d94595 100644 --- a/cumulus/zombienet_tests/0002-pov_recovery.toml +++ b/cumulus/zombienet_tests/0002-pov_recovery.toml @@ -1,5 +1,5 @@ [relaychain] -default_image = "docker.io/paritypr/polkadot-debug:master" +default_image = "{{RELAY_IMAGE}}" default_command = "polkadot" default_args = [ "-lparachain=debug" ] @@ -11,9 +11,7 @@ chain = "rococo-local" [[relaychain.nodes]] name = "bob" - image = "docker.io/paritypr/polkadot-debug:5236-0.9.18-c55660e9-be16bd72" validator = true - args = ["--database=paritydb-experimental"] [[parachains]] id = 2000 @@ -23,8 +21,8 @@ cumulus_based = true [[parachains.collators]] name = "charlie" validator = true - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" + image = "{{COL_IMAGE}}" + command = "test-parachain" args = ["-lparachain=debug"] # Run dave as parachain collator and eve as parachain full node @@ -33,14 +31,14 @@ cumulus_based = true [[parachains.collators]] name = "dave" validator = true - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie}}", "--use-null-consensus", "--disable-block-announcements"] + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie('multiAddress')}}", "--use-null-consensus", "--disable-block-announcements"] # run eve as parachain full node that is only connected to dave [[parachains.collators]] name = "eve" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie}}", "--use-null-consensus", "--disable-block-announcements"] + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie('multiAddress')}}", "--use-null-consensus", "--disable-block-announcements"] diff --git a/cumulus/zombienet_tests/0003-test_full_node_catching_up.feature b/cumulus/zombienet_tests/0003-full_node_catching_up.feature similarity index 75% rename from cumulus/zombienet_tests/0003-test_full_node_catching_up.feature rename to cumulus/zombienet_tests/0003-full_node_catching_up.feature index f7e5e4df3a..de8353bb13 100644 --- a/cumulus/zombienet_tests/0003-test_full_node_catching_up.feature +++ b/cumulus/zombienet_tests/0003-full_node_catching_up.feature @@ -1,8 +1,7 @@ -Description: Small Network test -Network: ./0003-test_full_node_catching_up.toml +Description: Full node catching up test +Network: ./0003-full_node_catching_up.toml Creds: config - alice: is up bob: is up charlie: is up diff --git a/cumulus/zombienet_tests/0003-test_full_node_catching_up.toml b/cumulus/zombienet_tests/0003-full_node_catching_up.toml similarity index 65% rename from cumulus/zombienet_tests/0003-test_full_node_catching_up.toml rename to cumulus/zombienet_tests/0003-full_node_catching_up.toml index 59ec912181..48ce352975 100644 --- a/cumulus/zombienet_tests/0003-test_full_node_catching_up.toml +++ b/cumulus/zombienet_tests/0003-full_node_catching_up.toml @@ -1,5 +1,5 @@ [relaychain] -default_image = "docker.io/paritypr/polkadot-debug:master" +default_image = "{{RELAY_IMAGE}}" default_command = "polkadot" default_args = [ "-lparachain=debug" ] @@ -11,9 +11,7 @@ chain = "rococo-local" [[relaychain.nodes]] name = "bob" - image = "docker.io/paritypr/polkadot-debug:5236-0.9.18-c55660e9-be16bd72" validator = true - args = ["--database=paritydb-experimental"] [[parachains]] id = 2000 @@ -23,22 +21,22 @@ cumulus_based = true [[parachains.collators]] name = "charlie" validator = true - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" + image = "{{COL_IMAGE}}" + command = "test-parachain" args = ["-lparachain=debug"] # run cumulus dave (a parachain full node) and wait for it to sync some blocks [[parachains.collators]] name = "dave" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie}}"] + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie('multiAddress')}}"] # run cumulus eve (a parachain full node) and wait for it to sync some blocks [[parachains.collators]] name = "eve" validator = false - image = "docker.io/parity/polkadot-collator:latest" - command = "test-collator" - args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie}}"] + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["--reserved-only", "--reserved-nodes {{'charlie'|zombie('multiAddress')}}", "--relay-chain-rpc-url {{'alice'|zombie('wsUri')}}"] diff --git a/cumulus/zombienet_tests/0004-runtime_upgrade.feature b/cumulus/zombienet_tests/0004-runtime_upgrade.feature new file mode 100644 index 0000000000..eca3cb3366 --- /dev/null +++ b/cumulus/zombienet_tests/0004-runtime_upgrade.feature @@ -0,0 +1,13 @@ +Description: Runtime Upgrade test +Network: ./0004-runtime_upgrade.toml +Creds: config + +alice: is up +bob: is up +charlie: is up +dave: is up +alice: parachain 2000 is registered within 225 seconds +charlie: reports block height is at least 5 within 250 seconds +charlie: parachain 2000 perform upgrade with /tmp/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm within 200 seconds +dave: reports block height is at least 20 within 250 seconds +dave: js-script ./runtime_upgrade.js within 200 seconds diff --git a/cumulus/zombienet_tests/0004-runtime_upgrade.toml b/cumulus/zombienet_tests/0004-runtime_upgrade.toml new file mode 100644 index 0000000000..fbf0dfc691 --- /dev/null +++ b/cumulus/zombienet_tests/0004-runtime_upgrade.toml @@ -0,0 +1,33 @@ +[relaychain] +default_image = "{{RELAY_IMAGE}}" +default_command = "polkadot" +default_args = [ "-lparachain=debug" ] + +chain = "rococo-local" + + [[relaychain.nodes]] + name = "alice" + validator = true + + [[relaychain.nodes]] + name = "bob" + validator = true + +[[parachains]] +id = 2000 +cumulus_based = true + + # run charlie as parachain collator + [[parachains.collators]] + name = "charlie" + validator = true + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["-lparachain=debug"] + + # Run dave as parachain full node + [[parachains.collators]] + name = "dave" + validator = false + image = "{{COL_IMAGE}}" + command = "test-parachain" diff --git a/cumulus/zombienet_tests/0005-migrate_solo_to_para.feature b/cumulus/zombienet_tests/0005-migrate_solo_to_para.feature new file mode 100644 index 0000000000..c546e49d1c --- /dev/null +++ b/cumulus/zombienet_tests/0005-migrate_solo_to_para.feature @@ -0,0 +1,13 @@ +Description: Migrate solo to para +Network: ./0005-migrate_solo_to_para.toml +Creds: config + +alice: is up +bob: is up +dave: is up +eve: is up +alice: parachain 2000 is registered within 225 seconds +alice: reports block height is at least 10 within 250 seconds +alice: parachain 2000 block height is at least 10 within 250 seconds +eve: reports block height is 0 within 20 seconds +dave: js-script ./migrate_solo_to_para.js with "dave,2000-1,eve" within 200 seconds diff --git a/cumulus/zombienet_tests/0005-migrate_solo_to_para.toml b/cumulus/zombienet_tests/0005-migrate_solo_to_para.toml new file mode 100644 index 0000000000..f98c0e6f25 --- /dev/null +++ b/cumulus/zombienet_tests/0005-migrate_solo_to_para.toml @@ -0,0 +1,45 @@ +[relaychain] +default_image = "{{RELAY_IMAGE}}" +default_command = "polkadot" +default_args = [ "-lparachain=debug" ] + +chain = "rococo-local" + + [[relaychain.nodes]] + name = "alice" + validator = true + + [[relaychain.nodes]] + name = "bob" + validator = true + + +[[parachains]] +id = 2000 +cumulus_based = true + + # run the solo chain (in our case this is also already a parachain, but as it has a different genesis it will not produce any blocks.) + [[parachains.collators]] + name = "dave" + validator = true + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["-lparachain=debug"] + +[[parachains]] +id = 2000 +cumulus_based = true +add_to_genesis = false +register_para = false +# Set some random value in the genesis state to create a different genesis hash. +[parachains.genesis.runtime.runtime_genesis_config.sudo] +key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" + + # run the parachain that will be used to return the header of the solo chain. + [[parachains.collators]] + name = "eve" + validator = true + add_to_bootnodes = true + image = "{{COL_IMAGE}}" + command = "test-parachain" + args = ["-lparachain=debug"] diff --git a/cumulus/zombienet_tests/migrate_solo_to_para.js b/cumulus/zombienet_tests/migrate_solo_to_para.js new file mode 100644 index 0000000000..c43e36e837 --- /dev/null +++ b/cumulus/zombienet_tests/migrate_solo_to_para.js @@ -0,0 +1,57 @@ +const assert = require("assert"); +const polkadotApi = require("@polkadot/api"); +const utilCrypto = require("@polkadot/util-crypto"); +const fs = require("fs").promises; + +async function connect(apiUrl, types) { + const provider = new polkadotApi.WsProvider(apiUrl); + const api = new polkadotApi.ApiPromise({ provider, types }); + await api.isReady; + return api; +} + +async function run(nodeName, networkInfo, args) { + const [paraNode, partialPath, soloNode ] = args; + const {wsUri, userDefinedTypes} = networkInfo.nodesByName[paraNode]; + const {wsUri: wsUri_solo, userDefinedTypes: userDefinedTypes_solo } = networkInfo.nodesByName[soloNode]; + const para = await connect(wsUri, userDefinedTypes); + const solo = await connect(wsUri_solo, userDefinedTypes_solo); + + await utilCrypto.cryptoWaitReady(); + + // account to submit tx + const keyring = new polkadotApi.Keyring({ type: "sr25519" }); + const alice = keyring.addFromUri("//Alice"); + + // get genesis to update + const filePath = `${networkInfo.tmpDir}/${partialPath}/genesis-state`; + const customHeader = await fs.readFile(filePath); + + // get current header + await para.tx.testPallet.setCustomValidationHeadData(customHeader.toString()).signAndSend(alice); + + let parachain_best; + let count = 0; + + assertParachainBest = async (parachain_best) => { + const current = await para.rpc.chain.getHeader(); + assert.equal(parachain_best.toHuman().number, current.toHuman().number, "parachain should not produce more blocks"); + } + + + await new Promise( async (resolve, reject) => { + const unsubscribe = await solo.rpc.chain.subscribeNewHeads(async (header) => { + console.log(`Solo chain is at block: #${header.number}`); + count++; + if(count === 2) parachain_best = await para.rpc.chain.getHeader(); + + if(count > 4) { + unsubscribe(); + await assertParachainBest(parachain_best); + resolve(); + } + }); + }); +} + +module.exports = { run } \ No newline at end of file diff --git a/cumulus/zombienet_tests/runtime_upgrade.js b/cumulus/zombienet_tests/runtime_upgrade.js new file mode 100644 index 0000000000..7692d3cef3 --- /dev/null +++ b/cumulus/zombienet_tests/runtime_upgrade.js @@ -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 } \ No newline at end of file