From 4c664c500bbbf745770df887c8cd134d8f0b94d0 Mon Sep 17 00:00:00 2001 From: girazoki Date: Wed, 5 Jun 2024 13:38:51 +0200 Subject: [PATCH] Add zombie upgrade tests containers (#560) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add possibility of running upgrade tests against containers with zombieç * add jobs to release * fmt * lint * fix * download binearies * fixç * fix * fixes * hopefully last fix --- .github/workflows/release.yml | 47 ++++++++ test/configs/zombieTanssiKeepDb.json | 6 +- test/configs/zombieTanssiMetrics.json | 6 +- test/configs/zombieTanssiWarpSync.json | 6 +- .../zombieTemplateUpgradeFrontier.json | 101 ++++++++++++++++++ test/configs/zombieTemplateUpgradeSimple.json | 101 ++++++++++++++++++ test/moonwall.config.json | 94 ++++++++++++++-- test/scripts/build-spec-single-container.sh | 23 ++++ test/scripts/build-spec-warp-sync.sh | 11 -- test/scripts/download-latest-rt-binaries.sh | 58 ++++++++++ .../test-upgrade-chain.ts | 71 ++++++++++++ .../test-upgrade-chain.ts | 5 + 12 files changed, 500 insertions(+), 29 deletions(-) create mode 100644 test/configs/zombieTemplateUpgradeFrontier.json create mode 100644 test/configs/zombieTemplateUpgradeSimple.json create mode 100755 test/scripts/build-spec-single-container.sh delete mode 100755 test/scripts/build-spec-warp-sync.sh create mode 100755 test/scripts/download-latest-rt-binaries.sh create mode 100644 test/suites/rt-upgrade-templates-zombienet/test-upgrade-chain.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee966ff7e..90647415a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -835,6 +835,53 @@ jobs: name: failed-node-logs path: ${{ env.NODE_LOGS_ZIP }} + zombienet-test-upgrade-containers: + runs-on: self-hosted + needs: ["set-tags", "build"] + strategy: + matrix: + chains: [ + { chain: "frontier_template", runtime: "container-chain-template-frontier" }, + { chain: "simple_template", runtime: "container-chain-template-simple" }, + ] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ needs.set-tags.outputs.git_ref }} + + - name: Pnpm + uses: pnpm/action-setup@v3.0.0 + with: + version: 8 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: "pnpm" + + - name: Create local folders + run: | + mkdir -p target/release/wbuild/${{ matrix.chains.runtime }}-runtime/ + mkdir -p test/tmp + - name: "Download binaries" + uses: actions/download-artifact@v4 + with: + name: binaries + path: target/release + - name: "Download runtime" + uses: actions/download-artifact@v4 + with: + name: runtimes + path: target/release/wbuild/${{ matrix.chains.runtime }}-runtime/ + + - name: "Install and run upgrade test" + run: | + cd test + pnpm install + pnpm moonwall test zombie_${{ matrix.chains.chain }}_upgrade + docker-tanssi: runs-on: ubuntu-latest needs: ["set-tags", "build"] diff --git a/test/configs/zombieTanssiKeepDb.json b/test/configs/zombieTanssiKeepDb.json index 2c48d644c..f46656d5f 100644 --- a/test/configs/zombieTanssiKeepDb.json +++ b/test/configs/zombieTanssiKeepDb.json @@ -45,8 +45,8 @@ "parachains": [ { "id": 1000, - "chain_spec_path": "specs/warp-sync-tanssi-1000.json", - "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-warp-sync.sh`", + "chain_spec_path": "specs/single-container-tanssi-1000.json", + "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-single-container.sh`", "collators": [ { "name": "FullNode-1000", @@ -89,7 +89,7 @@ }, { "id": 2000, - "chain_spec_path": "specs/warp-sync-template-container-2000.json", + "chain_spec_path": "specs/single-container-template-container-2000.json", "collators": [ { "name": "FullNode-2000", diff --git a/test/configs/zombieTanssiMetrics.json b/test/configs/zombieTanssiMetrics.json index a64191900..d1da709a1 100644 --- a/test/configs/zombieTanssiMetrics.json +++ b/test/configs/zombieTanssiMetrics.json @@ -45,8 +45,8 @@ "parachains": [ { "id": 1000, - "chain_spec_path": "specs/warp-sync-tanssi-1000.json", - "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-warp-sync.sh`", + "chain_spec_path": "specs/single-container-tanssi-1000.json", + "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-single-container.sh`", "collators": [ { "name": "FullNode-1000", @@ -94,7 +94,7 @@ }, { "id": 2000, - "chain_spec_path": "specs/warp-sync-template-container-2000.json", + "chain_spec_path": "specs/single-container-template-container-2000.json", "collators": [ { "name": "FullNode-2000", diff --git a/test/configs/zombieTanssiWarpSync.json b/test/configs/zombieTanssiWarpSync.json index de7243fcb..15637b4f5 100644 --- a/test/configs/zombieTanssiWarpSync.json +++ b/test/configs/zombieTanssiWarpSync.json @@ -37,8 +37,8 @@ "parachains": [ { "id": 1000, - "chain_spec_path": "specs/warp-sync-tanssi-1000.json", - "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-warp-sync.sh`", + "chain_spec_path": "specs/single-container-tanssi-1000.json", + "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec-single-container.sh`", "collators": [ { "name": "FullNode-1000", @@ -76,7 +76,7 @@ }, { "id": 2000, - "chain_spec_path": "specs/warp-sync-template-container-2000.json", + "chain_spec_path": "specs/single-container-template-container-2000.json", "collators": [ { "name": "FullNode-2000", diff --git a/test/configs/zombieTemplateUpgradeFrontier.json b/test/configs/zombieTemplateUpgradeFrontier.json new file mode 100644 index 000000000..e4cd679ba --- /dev/null +++ b/test/configs/zombieTemplateUpgradeFrontier.json @@ -0,0 +1,101 @@ +{ + "settings": { + "timeout": 1000, + "provider": "native" + }, + "relaychain": { + "chain": "rococo-local", + "default_command": "tmp/polkadot", + "default_args": ["--no-hardware-benchmarks", "-lparachain=debug", "--database=paritydb", "--no-beefy"], + "genesis": { + "runtimeGenesis": { + "patch": { + "configuration": { + "config": { + "async_backing_params": { + "allowed_ancestry_len": 2, + "max_candidate_depth": 3 + }, + "scheduling_lookahead": 2 + } + } + } + } + }, + "nodes": [ + { + "name": "alice", + "ws_port": "9947", + "validator": true + }, + { + "name": "bob", + "validator": true + }, + { + "name": "charlie", + "validator": true + }, + { + "name": "dave", + "validator": true + } + ] + }, + "parachains": [ + { + "id": 1000, + "chain_spec_path": "specs/single-container-tanssi-1000.json", + "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec.sh`", + "collators": [ + { + "name": "Collator1000-01", + "ws_port": "9948", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator1000-02", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator2000-01", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator2000-02", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator1000-03", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + } + ] + }, + { + "id": 2000, + "chain_spec_path": "specs/single-container-template-container-2000.json", + "collators": [ + { + "name": "FullNode-2000", + "validator": false, + "command": "../target/release/container-chain-frontier-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"], + "ws_port": 9949, + "p2p_port": 33049 + } + ] + } + ], + "types": { + "Header": { + "number": "u64", + "parent_hash": "Hash", + "post_state": "Hash" + } + } +} diff --git a/test/configs/zombieTemplateUpgradeSimple.json b/test/configs/zombieTemplateUpgradeSimple.json new file mode 100644 index 000000000..82b26f4dd --- /dev/null +++ b/test/configs/zombieTemplateUpgradeSimple.json @@ -0,0 +1,101 @@ +{ + "settings": { + "timeout": 1000, + "provider": "native" + }, + "relaychain": { + "chain": "rococo-local", + "default_command": "tmp/polkadot", + "default_args": ["--no-hardware-benchmarks", "-lparachain=debug", "--database=paritydb", "--no-beefy"], + "genesis": { + "runtimeGenesis": { + "patch": { + "configuration": { + "config": { + "async_backing_params": { + "allowed_ancestry_len": 2, + "max_candidate_depth": 3 + }, + "scheduling_lookahead": 2 + } + } + } + } + }, + "nodes": [ + { + "name": "alice", + "ws_port": "9947", + "validator": true + }, + { + "name": "bob", + "validator": true + }, + { + "name": "charlie", + "validator": true + }, + { + "name": "dave", + "validator": true + } + ] + }, + "parachains": [ + { + "id": 1000, + "chain_spec_path": "specs/single-container-tanssi-1000.json", + "COMMENT": "Important: these collators will not be injected to pallet-invulnerables because zombienet does not support that. When changing the collators list, make sure to update `scripts/build-spec.sh`", + "collators": [ + { + "name": "Collator1000-01", + "ws_port": "9948", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator1000-02", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator2000-01", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator2000-02", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + }, + { + "name": "Collator1000-03", + "command": "../target/release/tanssi-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"] + } + ] + }, + { + "id": 2000, + "chain_spec_path": "specs/single-container-template-container-2000.json", + "collators": [ + { + "name": "FullNode-2000", + "validator": false, + "command": "../target/release/container-chain-simple-node", + "args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"], + "ws_port": 9949, + "p2p_port": 33049 + } + ] + } + ], + "types": { + "Header": { + "number": "u64", + "parent_hash": "Hash", + "post_state": "Hash" + } + } +} diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 895324efc..a8a425369 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -187,10 +187,10 @@ "name": "zombie_tanssi_keep_db", "testFileDir": ["suites/keep-db"], "runScripts": [ - "build-spec-warp-sync.sh", + "build-spec-single-container.sh", "download-polkadot.sh", - "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/warp-sync-tanssi-1000.json", - "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/warp-sync-template-container-2000.json" + "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json", + "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json" ], "timeout": 600000, "foundation": { @@ -221,10 +221,10 @@ "name": "zombie_tanssi_metrics", "testFileDir": ["suites/metrics"], "runScripts": [ - "build-spec-warp-sync.sh", + "build-spec-single-container.sh", "download-polkadot.sh", - "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/warp-sync-tanssi-1000.json", - "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/warp-sync-template-container-2000.json" + "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json", + "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json" ], "timeout": 600000, "foundation": { @@ -385,10 +385,10 @@ "name": "zombie_tanssi_warp_sync", "testFileDir": ["suites/warp-sync"], "runScripts": [ - "build-spec-warp-sync.sh", + "build-spec-single-container.sh", "download-polkadot.sh", - "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/warp-sync-tanssi-1000.json", - "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/warp-sync-template-container-2000.json" + "compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json", + "compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json" ], "timeout": 600000, "foundation": { @@ -429,6 +429,82 @@ } } }, + { + "name": "zombie_simple_template_upgrade", + "testFileDir": ["suites/rt-upgrade-templates-zombienet"], + "runScripts": [ + "download-latest-rt-binaries.sh", + "build-spec-single-container.sh tmp container-chain-simple-node", + "download-polkadot.sh", + "compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json", + "compile-wasm.ts compile -b tmp/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json" + ], + + "timeout": 600000, + "foundation": { + "rtUpgradePath": "../target/release/wbuild/container-chain-template-simple-runtime/container_chain_template_simple_runtime.compact.compressed.wasm", + "type": "zombie", + "zombieSpec": { + "configPath": "./configs/zombieTemplateUpgradeSimple.json", + "disableDefaultEthProviders": true + } + }, + "connections": [ + { + "name": "Relay", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9947"] + }, + { + "name": "Tanssi", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9948"] + }, + { + "name": "parachain", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9949"] + } + ] + }, + { + "name": "zombie_frontier_template_upgrade", + "testFileDir": ["suites/rt-upgrade-templates-zombienet"], + "runScripts": [ + "download-latest-rt-binaries.sh", + "build-spec-single-container.sh tmp container-chain-frontier-node", + "download-polkadot.sh", + "compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json", + "compile-wasm.ts compile -b tmp/container-chain-frontier-node -o wasm -c specs/single-container-template-container-2000.json" + ], + + "timeout": 600000, + "foundation": { + "rtUpgradePath": "../target/release/wbuild/container-chain-template-frontier-runtime/container_chain_template_frontier_runtime.compact.compressed.wasm", + "type": "zombie", + "zombieSpec": { + "configPath": "./configs/zombieTemplateUpgradeFrontier.json", + "disableDefaultEthProviders": true + } + }, + "connections": [ + { + "name": "Relay", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9947"] + }, + { + "name": "Tanssi", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9948"] + }, + { + "name": "parachain", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:9949"] + } + ] + }, { "name": "dancebox_smoke", "testFileDir": ["suites/smoke-test-dancebox", "suites/smoke-test-common"], diff --git a/test/scripts/build-spec-single-container.sh b/test/scripts/build-spec-single-container.sh new file mode 100755 index 000000000..068f65696 --- /dev/null +++ b/test/scripts/build-spec-single-container.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Exit on any error +set -e + +# Always run the commands from the "test" dir +cd $(dirname $0)/.. + +if [[ -z "${1}" || ${1} == "undefined" ]]; then + BINARY_FOLDER="../target/release" +else + BINARY_FOLDER="${1}" +fi + +if [[ -z "${2}" || ${2} == "undefined" ]]; then + CONTAINER_BINARY="container-chain-simple-node" +else + CONTAINER_BINARY="${2}" +fi + +mkdir -p specs +$BINARY_FOLDER/$CONTAINER_BINARY build-spec --disable-default-bootnode --add-bootnode "/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" --parachain-id 2000 --raw > specs/single-container-template-container-2000.json +$BINARY_FOLDER/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/single-container-template-container-2000.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator1000-03" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" > specs/single-container-tanssi-1000.json diff --git a/test/scripts/build-spec-warp-sync.sh b/test/scripts/build-spec-warp-sync.sh deleted file mode 100755 index 6fba634e0..000000000 --- a/test/scripts/build-spec-warp-sync.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -# Always run the commands from the "test" dir -cd $(dirname $0)/.. - -mkdir -p specs -../target/release/container-chain-simple-node build-spec --disable-default-bootnode --add-bootnode "/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" --parachain-id 2000 --raw > specs/warp-sync-template-container-2000.json -../target/release/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/warp-sync-template-container-2000.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator1000-03" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" > specs/warp-sync-tanssi-1000.json diff --git a/test/scripts/download-latest-rt-binaries.sh b/test/scripts/download-latest-rt-binaries.sh new file mode 100755 index 000000000..3a7c2b310 --- /dev/null +++ b/test/scripts/download-latest-rt-binaries.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Exit on any error +set -e + +# Always run the commands from the "test" dir +cd $(dirname $0)/.. + +LATEST_RUNTIME_RELEASE=$(curl -s https://api.github.com/repos/moondance-labs/tanssi/releases | jq -r '.[] | select(.name | test("runtime";"i")) | .tag_name' | head -n 1 | tr -d '[:blank:]') && [[ ! -z "${LATEST_RUNTIME_RELEASE}" ]] +ENDPOINT="https://api.github.com/repos/moondance-labs/tanssi/git/refs/tags/$LATEST_RUNTIME_RELEASE" +RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $ENDPOINT) +TYPE=$(echo $RESPONSE | jq -r '.object.type') +if [[ $TYPE == "commit" ]] +then + LATEST_RT_SHA8=$(echo $RESPONSE | jq -r '.object.sha' | cut -c -8) +elif [[ $TYPE == "tag" ]] +then + URL=$(echo $RESPONSE | jq -r '.object.url') + TAG_RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $URL) + TAG_RESPONSE_CLEAN=$(echo $TAG_RESPONSE | tr -d '\000-\037') + LATEST_RT_SHA8=$(echo $TAG_RESPONSE_CLEAN | jq -r '.object.sha' | cut -c -8) +fi + +DOCKER_TAG_TANSSI="moondancelabs/tanssi:sha-$LATEST_RT_SHA8" + +docker rm -f tanssi_container 2> /dev/null | true +docker create --name tanssi_container $DOCKER_TAG_TANSSI bash +docker cp tanssi_container:tanssi/tanssi-node tmp/tanssi-node +docker rm -f tanssi_container +chmod uog+x ../target/release/tanssi-node +chmod uog+x tmp/tanssi-node + +DOCKER_TAG_CONTAINER_SIMPLE="moondancelabs/container-chain-simple-template:sha-$LATEST_RT_SHA8" +RUNTIME_VER=$(echo $LATEST_RUNTIME_RELEASE | tr -d -c 0-9) + +docker rm -f tanssi_container_simple 2> /dev/null | true +docker create --name tanssi_container_simple $DOCKER_TAG_CONTAINER_SIMPLE bash +if [ "$RUNTIME_VER" -ge 700 ]; then + docker cp tanssi_container_simple:container-chain-template-simple/container-chain-simple-node tmp/container-chain-simple-node +else + docker cp tanssi_container_simple:container-chain-template-simple/container-chain-template-simple-node tmp/container-chain-simple-node +fi +docker rm -f tanssi_container_simple +chmod uog+x ../target/release/container-chain-simple-node +chmod uog+x tmp/container-chain-simple-node + +DOCKER_TAG_CONTAINER_FRONTIER="moondancelabs/container-chain-evm-template:sha-$LATEST_RT_SHA8" + +docker rm -f tanssi_container_frontier 2> /dev/null | true +docker create --name tanssi_container_frontier $DOCKER_TAG_CONTAINER_FRONTIER bash +if [ "$RUNTIME_VER" -ge 700 ]; then + docker cp tanssi_container_frontier:container-chain-template-evm/container-chain-frontier-node tmp/container-chain-frontier-node +else + docker cp tanssi_container_frontier:container-chain-template-evm/container-chain-template-frontier-node tmp/container-chain-frontier-node +fi +docker rm -f tanssi_container_frontier +chmod uog+x ../target/release/container-chain-frontier-node +chmod uog+x tmp/container-chain-frontier-node diff --git a/test/suites/rt-upgrade-templates-zombienet/test-upgrade-chain.ts b/test/suites/rt-upgrade-templates-zombienet/test-upgrade-chain.ts new file mode 100644 index 000000000..a314b31e7 --- /dev/null +++ b/test/suites/rt-upgrade-templates-zombienet/test-upgrade-chain.ts @@ -0,0 +1,71 @@ +import { MoonwallContext, beforeAll, describeSuite, expect } from "@moonwall/cli"; +import { KeyringPair } from "@moonwall/util"; +import { ApiPromise, Keyring } from "@polkadot/api"; +import { alith } from "@moonwall/util"; + +import fs from "node:fs"; + +describeSuite({ + id: "R01", + title: "Zombie Container Template Upgrade Test", + foundationMethods: "zombie", + testCases: function ({ it, context, log }) { + let paraApi: ApiPromise; + let alice_or_alith: KeyringPair; + beforeAll(async () => { + paraApi = context.polkadotJs("parachain"); + const container2001Network = paraApi.consts.system.version.specName.toString(); + if (container2001Network.includes("frontier-template")) { + alice_or_alith = alith; + } else { + const keyring = new Keyring({ type: "sr25519" }); + alice_or_alith = keyring.addFromUri("//Alice", { name: "Alice default" }); + } + const currentBlock = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber(); + expect(currentBlock, "Parachain not producing blocks").to.be.greaterThan(0); + }, 120000); + + it({ + id: "T01", + title: "Blocks are being produced on parachain", + test: async function () { + const blockNum = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber(); + expect(blockNum).to.be.greaterThan(0); + }, + }); + + it({ + id: "T02", + title: "Chain can be upgraded", + timeout: 600000, + test: async function () { + const blockNumberBefore = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber(); + const currentCode = await paraApi.rpc.state.getStorage(":code"); + const codeString = currentCode.toString(); + const rtBefore = paraApi.consts.system.version.specVersion.toNumber(); + + const wasm = fs.readFileSync((await MoonwallContext.getContext()).rtUpgradePath); + const rtHex = `0x${wasm.toString("hex")}`; + + if (rtHex === codeString) { + log("Runtime already upgraded, skipping test"); + return; + } else { + log("Runtime not upgraded, proceeding with test"); + log("Current runtime hash: " + rtHex.slice(0, 10) + "..." + rtHex.slice(-10)); + log("New runtime hash: " + codeString.slice(0, 10) + "..." + codeString.slice(-10)); + } + + await context.upgradeRuntime({ from: alice_or_alith, logger: log }); + await context.waitBlock(2); + const rtafter = paraApi.consts.system.version.specVersion.toNumber(); + if (rtBefore === rtafter) { + throw new Error("Runtime upgrade failed"); + } + const blockNumberAfter = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber(); + log(`Before: #${blockNumberBefore}, After: #${blockNumberAfter}`); + expect(blockNumberAfter, "Block number did not increase").to.be.greaterThan(blockNumberBefore); + }, + }); + }, +}); diff --git a/test/suites/rt-upgrade-zombienet/test-upgrade-chain.ts b/test/suites/rt-upgrade-zombienet/test-upgrade-chain.ts index a9e3ff07d..a86bad47f 100644 --- a/test/suites/rt-upgrade-zombienet/test-upgrade-chain.ts +++ b/test/suites/rt-upgrade-zombienet/test-upgrade-chain.ts @@ -48,6 +48,7 @@ describeSuite({ const wasm = fs.readFileSync((await MoonwallContext.getContext()).rtUpgradePath); const rtHex = `0x${wasm.toString("hex")}`; + const rtBefore = paraApi.consts.system.version.specVersion.toNumber(); if (rtHex === codeString) { log("Runtime already upgraded, skipping test"); @@ -60,6 +61,10 @@ describeSuite({ await context.upgradeRuntime({ from: alice, logger: log }); await context.waitBlock(2); + const rtafter = paraApi.consts.system.version.specVersion.toNumber(); + if (rtBefore === rtafter) { + throw new Error("Runtime upgrade failed"); + } const blockNumberAfter = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber(); log(`Before: #${blockNumberBefore}, After: #${blockNumberAfter}`); expect(blockNumberAfter, "Block number did not increase").to.be.greaterThan(blockNumberBefore);