From 44a751330254499b996ad2a8adec69e9de4e56fb Mon Sep 17 00:00:00 2001 From: Fahrrader Date: Wed, 19 Apr 2023 07:55:17 +0000 Subject: [PATCH] test(chain spec mutator): test components + add to CI --- .gitlab-ci.yml | 31 ++++++++++++++++++++++++ tests/0014-chain-spec-modification.toml | 18 ++++++++++++++ tests/0014-chain-spec-modification.zndsl | 10 ++++++++ tests/change-name-in-chain-spec.sh | 11 +++++++++ tests/check-testnet-name.js | 12 +++++++++ 5 files changed, 82 insertions(+) create mode 100644 tests/0014-chain-spec-modification.toml create mode 100644 tests/0014-chain-spec-modification.zndsl create mode 100755 tests/change-name-in-chain-spec.sh create mode 100644 tests/check-testnet-name.js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03320931b4..67a076efc9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -459,3 +459,34 @@ db-snapshot: retry: 2 tags: - zombienet-polkadot-integration-test + +zombienet-chain-spec-custom-modification: + stage: deploy + <<: *kubernetes-env + image: "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" + rules: + - if: $CI_PIPELINE_SOURCE == "schedule" + - if: $CI_COMMIT_REF_NAME == "master" + - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs + - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 + # needs: + # - job: publish-docker-pr + + variables: + GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests" + + before_script: + - echo "Zombienet Tests Custom Chain Spec Modification" + - echo "paritypr/zombienet:${CI_COMMIT_SHORT_SHA}" + - echo "${GH_DIR}" + - export DEBUG=zombie* + - export ZOMBIENET_INTEGRATION_TEST_IMAGE="docker.io/paritypr/polkadot-debug:master" + - export COL_IMAGE="docker.io/paritypr/colander:master" + + script: + - /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh + --test="0014-chain-spec-modification.zndsl" + allow_failure: true + retry: 2 + tags: + - zombienet-polkadot-integration-test diff --git a/tests/0014-chain-spec-modification.toml b/tests/0014-chain-spec-modification.toml new file mode 100644 index 0000000000..1052dc61c2 --- /dev/null +++ b/tests/0014-chain-spec-modification.toml @@ -0,0 +1,18 @@ +[relaychain] +default_image = "docker.io/parity/polkadot:latest" +default_command = "polkadot" +default_args = [ "-lparachain=debug" ] +chain = "rococo-local" + +chain_spec_modifier_commands = [[ + "./change-name-in-chain-spec.sh", + "{{'plain'|chainSpec}}", +]] + + [[relaychain.nodes]] + name = "alice" + validator = true + + [[relaychain.nodes]] + name = "bob" + validator = true diff --git a/tests/0014-chain-spec-modification.zndsl b/tests/0014-chain-spec-modification.zndsl new file mode 100644 index 0000000000..a2362f0f1d --- /dev/null +++ b/tests/0014-chain-spec-modification.zndsl @@ -0,0 +1,10 @@ +Description: Chain Spec Modification +Network: ./0014-chain-spec-modification.toml +Creds: config + + +alice: is up +bob: is up +alice: log line matches "Imported #[0-9]+" within 10 seconds + +alice: js-script ./check-testnet-name.js with "Tentset Lacol Ococor" return is true diff --git a/tests/change-name-in-chain-spec.sh b/tests/change-name-in-chain-spec.sh new file mode 100755 index 0000000000..eb13646057 --- /dev/null +++ b/tests/change-name-in-chain-spec.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# The first argument sent to the script must be the path of the chain spec +chain_spec_path = $1 +# Assume that the name +old_name="Rococo Local Testnet" +# Set the new name for the network +new_name="Tentset Lacol Ococor" + +# Replace the name field in the JSON file +sed -i "s/\"name\": \"$old_name\"/\"name\": \"$new_name\"/" $chain_spec_path diff --git a/tests/check-testnet-name.js b/tests/check-testnet-name.js new file mode 100644 index 0000000000..6a845cd25b --- /dev/null +++ b/tests/check-testnet-name.js @@ -0,0 +1,12 @@ +// Check if the testnet's name is the same as the expected name from the args +async function run(nodeName, networkInfo, args) { + const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName]; + const api = await zombie.connect(wsUri, userDefinedTypes); + + const expectedName = args[0] ?? "Rococo Local Testnet"; + const testnetName = await api.rpc.system.chain(); + + return testnetName == expectedName; +} + +module.exports = { run } \ No newline at end of file