Skip to content

Commit

Permalink
test(chain spec mutator): test components + add to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Fahrrader committed Apr 19, 2023
1 parent f504bf1 commit 9f51226
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions tests/0014-chain-spec-modification.toml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/0014-chain-spec-modification.zndsl
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/change-name-in-chain-spec.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/check-testnet-name.js
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit 9f51226

Please sign in to comment.