difftreelog
use dotenv
in: master
3 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -17,6 +17,7 @@
"@zombienet/utils": "https://gitpkg.now.sh/UniqueNetwork/zombienet/javascript/packages/utils?2476ea76a368f1b1e94038dbfec29c27f114288e",
"chai": "^4.3.6",
"chai-subset": "^1.6.0",
+ "dotenv": "^16.1.4",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "^10.1.0",
tests/src/util/frankenstein.tsdiffbeforeafterboth1// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {blake2AsHex, cryptoWaitReady} from '@polkadot/util-crypto';19import zombie from '@zombienet/orchestrator/dist';20import {readNetworkConfig} from '@zombienet/utils/dist';21import {resolve} from 'path';22import {usingPlaygrounds} from '.';23import {migrations} from './frankensteinMigrate';24import fs from 'fs';2526const ZOMBIENET_CREDENTIALS = process.env.ZOMBIENET_CREDENTIALS || '../.env';27const NETWORK_CONFIG_FILE = process.argv[2] ?? '../launch-zombienet.toml';28const PARA_DIR = process.env.PARA_DIR || '../';29const RELAY_DIR = process.env.RELAY_DIR || '../../polkadot/';30const REPLICA_FROM = process.env.REPLICA_FROM || 'wss://ws-opal.unique.network:443';31const NEW_RELAY_BIN = process.env.NEW_RELAY_BIN;32const NEW_RELAY_WASM = process.env.NEW_RELAY_WASM;33const NEW_PARA_BIN = process.env.NEW_PARA_BIN;34const NEW_PARA_WASM = process.env.NEW_PARA_WASM;35const PARACHAIN_BLOCK_TIME = 12_000;36const SUPERUSER_KEY = '//Alice';3738let network: zombie.Network | undefined;3940// Stop the network if it is running41const stop = async () => {42 await network?.stop();43};4445// Promise of a timeout46function delay(ms: number) {47 return new Promise(resolve => setTimeout(resolve, ms));48}4950// Countdown with time left on display51async function waitWithTimer(time: number) {52 const secondsTotal = Math.ceil(time / 1000);53 for(let i = secondsTotal; i > 0; i--) {54 // could also introduce hours, but wth55 const seconds = i % 60;56 const text = `Time left: ${Math.floor(i/60)}:${seconds<10'0'+secondsseconds}`;57 if(process.stdout.isTTY)58 process.stdout.write(text);59 else if(seconds % 10 == 0)60 console.log(text);61 await delay(1000);62 if(process.stdout.isTTY) {63 process.stdout.clearLine(0);64 process.stdout.cursorTo(0);65 }66 }67}6869// Get the runtime's current version70function getSpecVersion(api: ApiPromise): number {71 return (api.consts.system.version as any).specVersion.toNumber();72}7374// Get the required information on the relay chain75function getRelayInfo(api: ApiPromise): {specVersion: number, epochBlockLength: number, blockTime: number, epochTime: number} {76 const info = {77 specVersion: getSpecVersion(api),78 epochBlockLength: (api.consts.babe.epochDuration as any).toNumber(),79 blockTime: (api.consts.babe.expectedBlockTime as any).toNumber(),80 epochTime: 0,81 };82 info.epochTime = info.epochBlockLength * info.blockTime;83 return info;84}8586// Enable or disable maintenance mode if present on the chain87async function toggleMaintenanceMode(value: boolean, wsUri: string) {88 await usingPlaygrounds(async (helper, privateKey) => {89 const superuser = await privateKey(SUPERUSER_KEY);90 try {91 const toggle = value ? 'enable' : 'disable';92 await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);93 console.log(`Maintenance mode ${value'engaged''disengaged'}.`);94 } catch (e) {95 console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);96 }97 }, wsUri);98}99100const raiseZombienet = async (): Promise<void> => {101 const isUpgradeTesting = !!NEW_RELAY_BIN || !!NEW_RELAY_WASM || !!NEW_PARA_BIN || !!NEW_PARA_WASM;102 /*103 // If there is nothing to upgrade, what is the point104 if (!isUpgradeTesting) {105 console.warn('\nNeither the relay nor the parachain were selected for an upgrade! ' +106 'Please pass environment vars `NEW_RELAY_BIN`, `NEW_RELAY_WASM`, `NEW_PARA_BIN`, `NEW_PARA_WASM`.');107 process.exit(1);108 }109 */110111 // an unsavory practice, but very convenient, mwahahah112 process.env.PARA_DIR = PARA_DIR;113 process.env.RELAY_DIR = RELAY_DIR;114 process.env.REPLICA_FROM = REPLICA_FROM;115116 const configPath = resolve(NETWORK_CONFIG_FILE);117 const networkConfig = readNetworkConfig(configPath);118 // console.log(networkConfig);119 if(networkConfig.settings.provider !== 'native') {120 throw new Error(`Oh no! Expected native network, got ${networkConfig.settings.provider}.`);121 }122123 await cryptoWaitReady();124125 // Launch Zombienet!126 network = await zombie.start(ZOMBIENET_CREDENTIALS, networkConfig, {silent: false});127128 // Get the relay chain info like the epoch length and spec version129 // Then restart each parachain's binaries130 // // Stop and restart each node131 // // Send specified keys to parachain nodes in case the parachain requires it132 // If it is not needed to upgrade runtimes themselves, the job is done!133134 // Record some required information regarding the relay chain135 await network.relay[0].connectApi();136 let relayInfo = getRelayInfo((network.relay[0] as any).apiInstance!);137 await network.relay[0].apiInstance!.disconnect();138 if(isUpgradeTesting) {139 console.log('Relay stats:', relayInfo);140 }141142 // non-exported functionality of NativeClient143 const networkClient = (network.client as any);144145 if(NEW_RELAY_BIN) {146 console.log('\n🧶 Restarting relay nodes');147148 for(const [index, node] of network.relay.entries()) {149 await node.apiInstance?.disconnect();150151 console.log(`\n🚦 Starting timeout for the epoch change (node ${index+1}/${network.relay.length})...`);152 await waitWithTimer(relayInfo.epochTime);153154 // Replace the node-starting command with the new binary155 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];156 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_RELAY_BIN));157158 await node.restart();159 }160161 console.log('\n🌒 All relay nodes restarted with the new binaries.');162 }163164 if(NEW_PARA_BIN) {165 for(const paraId in network.paras) {166 const para = network.paras[paraId];167 console.log(`\n🧶 Restarting collator nodes of parachain ${paraId}`);168169 for(const [_index, node] of para.nodes.entries()) {170 await node.apiInstance?.disconnect();171172 // Replace the node-starting command with the new binary173 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];174 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_PARA_BIN));175176 await node.restart();177 // applyaurakey?178 // Zombienet handles it on first-time node creation179 }180 }181182 console.log('\n🌗 All parachain collators restarted with the new binaries.');183 }184185 // Re-establish connection to the relay node and get the runtime upgrade validation delay for parachains186 // For the relay, connect and set the new runtime code187 // For each parachain, connect, authorize and upgrade its runtime188 // Ping the the chains for the runtime upgrade after the minimal time and then every few blocks189 // // For each parachain, re-connect and verify that the runtime upgrade is successful190191 let relayUpgradeCompleted = false, paraUpgradeCompleted = false;192193 if(NEW_RELAY_WASM) {194 const relayOldVersion = relayInfo.specVersion;195 console.log('\n🚦 Starting timeout for the next epoch before upgrading the relay runtime code...');196 await waitWithTimer(relayInfo.epochTime);197198 console.log('--- Upgrading the relay chain runtime \t---');199200 // Read the new WASM code and set it as the relay's new code201 const code = fs.readFileSync(NEW_RELAY_WASM).toString('hex');202 await usingPlaygrounds(async (helper, privateKey) => {203 const superuser = await privateKey(SUPERUSER_KEY);204205 const result = await helper.executeExtrinsic(206 superuser,207 'api.tx.sudo.sudoUncheckedWeight',208 [helper.constructApiCall('api.tx.system.setCode', [`0x${code}`]), {}],209 );210211 if(result.status == 'Fail') {212 console.error('Failed to upgrade the runtime:', result);213 }214215 // Get the updated information from the relay's new runtime216 relayInfo = getRelayInfo(helper.getApi());217 }, network.relay[0].wsUri);218219 if(relayOldVersion != relayInfo.specVersion) {220 // eslint-disable-next-line no-useless-escape221 console.log(`\n\🛰️ The relay has successfully upgraded from version ${relayOldVersion} to ${relayInfo.specVersion}!`);222 relayUpgradeCompleted = true;223 } else {224 console.error(`\nThe relay did not upgrade from version ${relayOldVersion}!`);225 }226 } else {227 // If the relay did not need to be upgraded, it's already technically completed228 relayUpgradeCompleted = true;229 }230231 if(NEW_PARA_WASM) {232 let codeValidationDelayBlocks = 0;233 const upgradingParas: {[id: string]: {version: number, upgraded: boolean}} = {};234 // Calculate the code validation delay of the relay chain,235 // so that we know how much to wait before the parachains can be upgraded after the extrinsic236 await usingPlaygrounds(async (helper) => {237 const {validationUpgradeDelay, minimumValidationUpgradeDelay} =238 (await helper.callRpc('api.query.configuration.activeConfig', [])).toJSON() as any;239240 codeValidationDelayBlocks = Math.max(validationUpgradeDelay ?? 0, minimumValidationUpgradeDelay ?? 0);241 }, network.relay[0].wsUri);242243 // Wait for the next epoch so that the parachains will start cooperating with the relay244 if(relayUpgradeCompleted && NEW_RELAY_WASM) {245 console.log('\n🚥 Starting timeout for the next epoch before upgrading the parachains code...');246 await waitWithTimer(relayInfo.epochTime);247 }248249 const migration = migrations[process.env.DESTINATION_SPEC_VERSION!];250 console.log('⭐️⭐️⭐️ DESTINATION_SPEC_VERSION ⭐️⭐️⭐️', process.env.DESTINATION_SPEC_VERSION!);251 for(const paraId in network.paras) {252 console.log(`\n--- Upgrading the runtime of parachain ${paraId} \t---`);253 const para = network.paras[paraId];254255 // Enable maintenance mode if present256 await toggleMaintenanceMode(true, para.nodes[0].wsUri);257 if(migration) {258 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');259 console.log('⭐️⭐️⭐️ Running pre-upgrade scripts... ⭐️⭐️⭐️');260 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');261 await migration.before();262 }263264 // Read the WASM code and authorize the upgrade with its hash and set it as the new runtime265 const code = fs.readFileSync(NEW_PARA_WASM);266 const codeHash = blake2AsHex(code);267 await usingPlaygrounds(async (helper, privateKey) => {268 const superuser = await privateKey(SUPERUSER_KEY);269270 upgradingParas[paraId] = {version: getSpecVersion(helper.getApi()), upgraded: false};271272 console.log('--- Authorizing the parachain runtime upgrade \t---');273 let result = await helper.executeExtrinsic(274 superuser,275 'api.tx.sudo.sudoUncheckedWeight',276 [helper.constructApiCall('api.tx.parachainSystem.authorizeUpgrade', [codeHash, false]), {}],277 );278279 if(result.status == 'Fail') {280 console.error('Failed to authorize the upgrade:', result);281 return;282 }283284 console.log('--- Enacting the parachain runtime upgrade \t---');285 result = await helper.executeExtrinsic(286 superuser,287 'api.tx.sudo.sudoUncheckedWeight',288 [helper.constructApiCall('api.tx.parachainSystem.enactAuthorizedUpgrade', [`0x${code.toString('hex')}`]), {}],289 );290291 if(result.status == 'Fail') {292 console.error('Failed to upgrade the runtime:', result);293 }294 }, para.nodes[0].wsUri);295 }296297 // Check the upgrades of the parachains, first after the minimum code validation delay, and then after some block time increments298 let firstPass = true;299 for(let attempt = 0; attempt < 3 && !paraUpgradeCompleted; attempt++) {300 if(firstPass) {301 console.log('\nCode validation delay:', codeValidationDelayBlocks, 'blocks');302 console.log('🚥 Waiting for the minimum code validation delay before the parachain can upgrade...');303 await waitWithTimer(relayInfo.blockTime * codeValidationDelayBlocks);304 firstPass = false;305 } else {306 console.log('\n🚥 Waiting for a few blocks more to verify that the parachain upgrades are successful...');307 await waitWithTimer(PARACHAIN_BLOCK_TIME * 3);308 }309310 // Ping the parachains' nodes for new runtime versions311 let upgradeFailed = false;312 for(const paraId in network.paras) {313 if(upgradingParas[paraId].upgraded) continue;314315 const para = network.paras[paraId];316 // eslint-disable-next-line require-await317 await usingPlaygrounds(async (helper) => {318 const specVersion = getSpecVersion(helper.getApi());319320 if(specVersion != upgradingParas[paraId].version) {321 // eslint-disable-next-line no-useless-escape322 console.log(`\n\🛰️ Parachain ${paraId} has successfully upgraded from version ${upgradingParas[paraId].version} to ${specVersion}!`);323 upgradingParas[paraId].upgraded = true;324 } else {325 console.error(`\nParachain ${paraId} failed to upgrade from version ${upgradingParas[paraId].version}!`);326 upgradeFailed = true;327 }328 }, para.nodes[0].wsUri);329330 paraUpgradeCompleted = !upgradeFailed;331 }332 }333334 // Disable maintenance mode if present335 for(const paraId in network.paras) {336 // TODO only if our parachain337 if(migration) {338 console.log('⭐️⭐️⭐️ Running post-upgrade scripts... ⭐️⭐️⭐️');339 await migration.after();340 }341 await toggleMaintenanceMode(false, network.paras[paraId].nodes[0].wsUri);342 }343 } else {344 // If the relay did not need to be upgraded, it's already technically completed345 paraUpgradeCompleted = true;346 }347348 // await network.stop();349350 if(isUpgradeTesting) {351 if(paraUpgradeCompleted && relayUpgradeCompleted) {352 console.log("\n🛸 PARACHAINS' RUNTIME UPGRADE TESTING COMPLETE 🛸");353 } else {354 console.error("\n🚧 PARACHAINS' RUNTIME UPGRADE TESTING FAILED 🚧");355 }356 } else {357 console.log('🚀 ZOMBIENET RAISED 🚀');358 }359};360361raiseZombienet()/*.then(async () => await stop())*/.catch(async (e) => {362 console.error(e);363 await stop();364 process.exit(1);365});1// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {blake2AsHex, cryptoWaitReady} from '@polkadot/util-crypto';19import zombie from '@zombienet/orchestrator/dist';20import {readNetworkConfig} from '@zombienet/utils/dist';21import {resolve} from 'path';22import {usingPlaygrounds} from '.';23import {migrations} from './frankensteinMigrate';24import fs from 'fs';25import * as dotenv from 'dotenv';26dotenv.config();2728const ZOMBIENET_CREDENTIALS = process.env.ZOMBIENET_CREDENTIALS || '../.env';29const NETWORK_CONFIG_FILE = process.argv[2] ?? '../launch-zombienet.toml';30const PARA_DIR = process.env.PARA_DIR || '../';31const RELAY_DIR = process.env.RELAY_DIR || '../../polkadot/';32const REPLICA_FROM = process.env.REPLICA_FROM || 'wss://ws-opal.unique.network:443';33const NEW_RELAY_BIN = process.env.NEW_RELAY_BIN;34const NEW_RELAY_WASM = process.env.NEW_RELAY_WASM;35const NEW_PARA_BIN = process.env.NEW_PARA_BIN;36const NEW_PARA_WASM = process.env.NEW_PARA_WASM;37const PARACHAIN_BLOCK_TIME = 12_000;38const SUPERUSER_KEY = '//Alice';3940let network: zombie.Network | undefined;4142// Stop the network if it is running43const stop = async () => {44 await network?.stop();45};4647// Promise of a timeout48function delay(ms: number) {49 return new Promise(resolve => setTimeout(resolve, ms));50}5152// Countdown with time left on display53async function waitWithTimer(time: number) {54 const secondsTotal = Math.ceil(time / 1000);55 for(let i = secondsTotal; i > 0; i--) {56 // could also introduce hours, but wth57 const seconds = i % 60;58 const text = `Time left: ${Math.floor(i/60)}:${seconds<10'0'+secondsseconds}`;59 if(process.stdout.isTTY)60 process.stdout.write(text);61 else if(seconds % 10 == 0)62 console.log(text);63 await delay(1000);64 if(process.stdout.isTTY) {65 process.stdout.clearLine(0);66 process.stdout.cursorTo(0);67 }68 }69}7071// Get the runtime's current version72function getSpecVersion(api: ApiPromise): number {73 return (api.consts.system.version as any).specVersion.toNumber();74}7576// Get the required information on the relay chain77function getRelayInfo(api: ApiPromise): {specVersion: number, epochBlockLength: number, blockTime: number, epochTime: number} {78 const info = {79 specVersion: getSpecVersion(api),80 epochBlockLength: (api.consts.babe.epochDuration as any).toNumber(),81 blockTime: (api.consts.babe.expectedBlockTime as any).toNumber(),82 epochTime: 0,83 };84 info.epochTime = info.epochBlockLength * info.blockTime;85 return info;86}8788// Enable or disable maintenance mode if present on the chain89async function toggleMaintenanceMode(value: boolean, wsUri: string) {90 await usingPlaygrounds(async (helper, privateKey) => {91 const superuser = await privateKey(SUPERUSER_KEY);92 try {93 const toggle = value ? 'enable' : 'disable';94 await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);95 console.log(`Maintenance mode ${value'engaged''disengaged'}.`);96 } catch (e) {97 console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);98 }99 }, wsUri);100}101102const raiseZombienet = async (): Promise<void> => {103 const isUpgradeTesting = !!NEW_RELAY_BIN || !!NEW_RELAY_WASM || !!NEW_PARA_BIN || !!NEW_PARA_WASM;104 /*105 // If there is nothing to upgrade, what is the point106 if (!isUpgradeTesting) {107 console.warn('\nNeither the relay nor the parachain were selected for an upgrade! ' +108 'Please pass environment vars `NEW_RELAY_BIN`, `NEW_RELAY_WASM`, `NEW_PARA_BIN`, `NEW_PARA_WASM`.');109 process.exit(1);110 }111 */112113 // an unsavory practice, but very convenient, mwahahah114 process.env.PARA_DIR = PARA_DIR;115 process.env.RELAY_DIR = RELAY_DIR;116 process.env.REPLICA_FROM = REPLICA_FROM;117118 const configPath = resolve(NETWORK_CONFIG_FILE);119 const networkConfig = readNetworkConfig(configPath);120 // console.log(networkConfig);121 if(networkConfig.settings.provider !== 'native') {122 throw new Error(`Oh no! Expected native network, got ${networkConfig.settings.provider}.`);123 }124125 await cryptoWaitReady();126127 // Launch Zombienet!128 network = await zombie.start(ZOMBIENET_CREDENTIALS, networkConfig, {silent: false});129130 // Get the relay chain info like the epoch length and spec version131 // Then restart each parachain's binaries132 // // Stop and restart each node133 // // Send specified keys to parachain nodes in case the parachain requires it134 // If it is not needed to upgrade runtimes themselves, the job is done!135136 // Record some required information regarding the relay chain137 await network.relay[0].connectApi();138 let relayInfo = getRelayInfo((network.relay[0] as any).apiInstance!);139 await network.relay[0].apiInstance!.disconnect();140 if(isUpgradeTesting) {141 console.log('Relay stats:', relayInfo);142 }143144 // non-exported functionality of NativeClient145 const networkClient = (network.client as any);146147 if(NEW_RELAY_BIN) {148 console.log('\n🧶 Restarting relay nodes');149150 for(const [index, node] of network.relay.entries()) {151 await node.apiInstance?.disconnect();152153 console.log(`\n🚦 Starting timeout for the epoch change (node ${index+1}/${network.relay.length})...`);154 await waitWithTimer(relayInfo.epochTime);155156 // Replace the node-starting command with the new binary157 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];158 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_RELAY_BIN));159160 await node.restart();161 }162163 console.log('\n🌒 All relay nodes restarted with the new binaries.');164 }165166 if(NEW_PARA_BIN) {167 for(const paraId in network.paras) {168 const para = network.paras[paraId];169 console.log(`\n🧶 Restarting collator nodes of parachain ${paraId}`);170171 for(const [_index, node] of para.nodes.entries()) {172 await node.apiInstance?.disconnect();173174 // Replace the node-starting command with the new binary175 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];176 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_PARA_BIN));177178 await node.restart();179 // applyaurakey?180 // Zombienet handles it on first-time node creation181 }182 }183184 console.log('\n🌗 All parachain collators restarted with the new binaries.');185 }186187 // Re-establish connection to the relay node and get the runtime upgrade validation delay for parachains188 // For the relay, connect and set the new runtime code189 // For each parachain, connect, authorize and upgrade its runtime190 // Ping the the chains for the runtime upgrade after the minimal time and then every few blocks191 // // For each parachain, re-connect and verify that the runtime upgrade is successful192193 let relayUpgradeCompleted = false, paraUpgradeCompleted = false;194195 if(NEW_RELAY_WASM) {196 const relayOldVersion = relayInfo.specVersion;197 console.log('\n🚦 Starting timeout for the next epoch before upgrading the relay runtime code...');198 await waitWithTimer(relayInfo.epochTime);199200 console.log('--- Upgrading the relay chain runtime \t---');201202 // Read the new WASM code and set it as the relay's new code203 const code = fs.readFileSync(NEW_RELAY_WASM).toString('hex');204 await usingPlaygrounds(async (helper, privateKey) => {205 const superuser = await privateKey(SUPERUSER_KEY);206207 const result = await helper.executeExtrinsic(208 superuser,209 'api.tx.sudo.sudoUncheckedWeight',210 [helper.constructApiCall('api.tx.system.setCode', [`0x${code}`]), {}],211 );212213 if(result.status == 'Fail') {214 console.error('Failed to upgrade the runtime:', result);215 }216217 // Get the updated information from the relay's new runtime218 relayInfo = getRelayInfo(helper.getApi());219 }, network.relay[0].wsUri);220221 if(relayOldVersion != relayInfo.specVersion) {222 // eslint-disable-next-line no-useless-escape223 console.log(`\n\🛰️ The relay has successfully upgraded from version ${relayOldVersion} to ${relayInfo.specVersion}!`);224 relayUpgradeCompleted = true;225 } else {226 console.error(`\nThe relay did not upgrade from version ${relayOldVersion}!`);227 }228 } else {229 // If the relay did not need to be upgraded, it's already technically completed230 relayUpgradeCompleted = true;231 }232233 if(NEW_PARA_WASM) {234 let codeValidationDelayBlocks = 0;235 const upgradingParas: {[id: string]: {version: number, upgraded: boolean}} = {};236 // Calculate the code validation delay of the relay chain,237 // so that we know how much to wait before the parachains can be upgraded after the extrinsic238 await usingPlaygrounds(async (helper) => {239 const {validationUpgradeDelay, minimumValidationUpgradeDelay} =240 (await helper.callRpc('api.query.configuration.activeConfig', [])).toJSON() as any;241242 codeValidationDelayBlocks = Math.max(validationUpgradeDelay ?? 0, minimumValidationUpgradeDelay ?? 0);243 }, network.relay[0].wsUri);244245 // Wait for the next epoch so that the parachains will start cooperating with the relay246 if(relayUpgradeCompleted && NEW_RELAY_WASM) {247 console.log('\n🚥 Starting timeout for the next epoch before upgrading the parachains code...');248 await waitWithTimer(relayInfo.epochTime);249 }250251 const migration = migrations[process.env.DESTINATION_SPEC_VERSION!];252 console.log('⭐️⭐️⭐️ DESTINATION_SPEC_VERSION ⭐️⭐️⭐️', process.env.DESTINATION_SPEC_VERSION!);253 for(const paraId in network.paras) {254 console.log(`\n--- Upgrading the runtime of parachain ${paraId} \t---`);255 const para = network.paras[paraId];256257 // Enable maintenance mode if present258 await toggleMaintenanceMode(true, para.nodes[0].wsUri);259 if(migration) {260 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');261 console.log('⭐️⭐️⭐️ Running pre-upgrade scripts... ⭐️⭐️⭐️');262 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');263 await migration.before();264 }265266 // Read the WASM code and authorize the upgrade with its hash and set it as the new runtime267 const code = fs.readFileSync(NEW_PARA_WASM);268 const codeHash = blake2AsHex(code);269 await usingPlaygrounds(async (helper, privateKey) => {270 const superuser = await privateKey(SUPERUSER_KEY);271272 upgradingParas[paraId] = {version: getSpecVersion(helper.getApi()), upgraded: false};273274 console.log('--- Authorizing the parachain runtime upgrade \t---');275 let result = await helper.executeExtrinsic(276 superuser,277 'api.tx.sudo.sudoUncheckedWeight',278 [helper.constructApiCall('api.tx.parachainSystem.authorizeUpgrade', [codeHash, false]), {}],279 );280281 if(result.status == 'Fail') {282 console.error('Failed to authorize the upgrade:', result);283 return;284 }285286 console.log('--- Enacting the parachain runtime upgrade \t---');287 result = await helper.executeExtrinsic(288 superuser,289 'api.tx.sudo.sudoUncheckedWeight',290 [helper.constructApiCall('api.tx.parachainSystem.enactAuthorizedUpgrade', [`0x${code.toString('hex')}`]), {}],291 );292293 if(result.status == 'Fail') {294 console.error('Failed to upgrade the runtime:', result);295 }296 }, para.nodes[0].wsUri);297 }298299 // Check the upgrades of the parachains, first after the minimum code validation delay, and then after some block time increments300 let firstPass = true;301 for(let attempt = 0; attempt < 3 && !paraUpgradeCompleted; attempt++) {302 if(firstPass) {303 console.log('\nCode validation delay:', codeValidationDelayBlocks, 'blocks');304 console.log('🚥 Waiting for the minimum code validation delay before the parachain can upgrade...');305 await waitWithTimer(relayInfo.blockTime * codeValidationDelayBlocks);306 firstPass = false;307 } else {308 console.log('\n🚥 Waiting for a few blocks more to verify that the parachain upgrades are successful...');309 await waitWithTimer(PARACHAIN_BLOCK_TIME * 3);310 }311312 // Ping the parachains' nodes for new runtime versions313 let upgradeFailed = false;314 for(const paraId in network.paras) {315 if(upgradingParas[paraId].upgraded) continue;316317 const para = network.paras[paraId];318 // eslint-disable-next-line require-await319 await usingPlaygrounds(async (helper) => {320 const specVersion = getSpecVersion(helper.getApi());321322 if(specVersion != upgradingParas[paraId].version) {323 // eslint-disable-next-line no-useless-escape324 console.log(`\n\🛰️ Parachain ${paraId} has successfully upgraded from version ${upgradingParas[paraId].version} to ${specVersion}!`);325 upgradingParas[paraId].upgraded = true;326 } else {327 console.error(`\nParachain ${paraId} failed to upgrade from version ${upgradingParas[paraId].version}!`);328 upgradeFailed = true;329 }330 }, para.nodes[0].wsUri);331332 paraUpgradeCompleted = !upgradeFailed;333 }334 }335336 // Disable maintenance mode if present337 for(const paraId in network.paras) {338 // TODO only if our parachain339 if(migration) {340 console.log('⭐️⭐️⭐️ Running post-upgrade scripts... ⭐️⭐️⭐️');341 await migration.after();342 }343 await toggleMaintenanceMode(false, network.paras[paraId].nodes[0].wsUri);344 }345 } else {346 // If the relay did not need to be upgraded, it's already technically completed347 paraUpgradeCompleted = true;348 }349350 // await network.stop();351352 if(isUpgradeTesting) {353 if(paraUpgradeCompleted && relayUpgradeCompleted) {354 console.log("\n🛸 PARACHAINS' RUNTIME UPGRADE TESTING COMPLETE 🛸");355 } else {356 console.error("\n🚧 PARACHAINS' RUNTIME UPGRADE TESTING FAILED 🚧");357 }358 } else {359 console.log('🚀 ZOMBIENET RAISED 🚀');360 }361};362363raiseZombienet()/*.then(async () => await stop())*/.catch(async (e) => {364 console.error(e);365 await stop();366 process.exit(1);367});tests/yarn.lockdiffbeforeafterboth--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -2116,6 +2116,11 @@
dependencies:
webidl-conversions "^7.0.0"
+dotenv@^16.1.4:
+ version "16.1.4"
+ resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.1.4.tgz#67ac1a10cd9c25f5ba604e4e08bc77c0ebe0ca8c"
+ integrity sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==
+
ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"