difftreelog
remove dotenv
in: master
3 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -17,7 +17,6 @@
"@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';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 DESTINATION_SPEC_VERSION = process.env.DESTINATION_SPEC_VERSION!;38const PARACHAIN_BLOCK_TIME = 12_000;39const SUPERUSER_KEY = '//Alice';4041let network: zombie.Network | undefined;4243// Stop the network if it is running44const stop = async () => {45 await network?.stop();46};4748// Promise of a timeout49function delay(ms: number) {50 return new Promise(resolve => setTimeout(resolve, ms));51}5253// Countdown with time left on display54async function waitWithTimer(time: number) {55 const secondsTotal = Math.ceil(time / 1000);56 for(let i = secondsTotal; i > 0; i--) {57 // could also introduce hours, but wth58 const seconds = i % 60;59 const text = `Time left: ${Math.floor(i/60)}:${seconds<10'0'+secondsseconds}`;60 if(process.stdout.isTTY)61 process.stdout.write(text);62 else if(seconds % 10 == 0)63 console.log(text);64 await delay(1000);65 if(process.stdout.isTTY) {66 process.stdout.clearLine(0);67 process.stdout.cursorTo(0);68 }69 }70}7172// Get the runtime's current version73function getSpecVersion(api: ApiPromise): number {74 return (api.consts.system.version as any).specVersion.toNumber();75}7677// Get the required information on the relay chain78function getRelayInfo(api: ApiPromise): {specVersion: number, epochBlockLength: number, blockTime: number, epochTime: number} {79 const info = {80 specVersion: getSpecVersion(api),81 epochBlockLength: (api.consts.babe.epochDuration as any).toNumber(),82 blockTime: (api.consts.babe.expectedBlockTime as any).toNumber(),83 epochTime: 0,84 };85 info.epochTime = info.epochBlockLength * info.blockTime;86 return info;87}8889// Enable or disable maintenance mode if present on the chain90async function toggleMaintenanceMode(value: boolean, wsUri: string) {91 await usingPlaygrounds(async (helper, privateKey) => {92 const superuser = await privateKey(SUPERUSER_KEY);93 try {94 const toggle = value ? 'enable' : 'disable';95 await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);96 console.log(`Maintenance mode ${value'engaged''disengaged'}.`);97 } catch (e) {98 console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);99 }100 }, wsUri);101}102103const raiseZombienet = async (): Promise<void> => {104 const isUpgradeTesting = !!NEW_RELAY_BIN || !!NEW_RELAY_WASM || !!NEW_PARA_BIN || !!NEW_PARA_WASM;105 /*106 // If there is nothing to upgrade, what is the point107 if (!isUpgradeTesting) {108 console.warn('\nNeither the relay nor the parachain were selected for an upgrade! ' +109 'Please pass environment vars `NEW_RELAY_BIN`, `NEW_RELAY_WASM`, `NEW_PARA_BIN`, `NEW_PARA_WASM`.');110 process.exit(1);111 }112 */113114 // an unsavory practice, but very convenient, mwahahah115 process.env.PARA_DIR = PARA_DIR;116 process.env.RELAY_DIR = RELAY_DIR;117 process.env.REPLICA_FROM = REPLICA_FROM;118119 const configPath = resolve(NETWORK_CONFIG_FILE);120 const networkConfig = readNetworkConfig(configPath);121 // console.log(networkConfig);122 if(networkConfig.settings.provider !== 'native') {123 throw new Error(`Oh no! Expected native network, got ${networkConfig.settings.provider}.`);124 }125126 await cryptoWaitReady();127128 // Launch Zombienet!129 network = await zombie.start(ZOMBIENET_CREDENTIALS, networkConfig, {silent: false});130131 // Get the relay chain info like the epoch length and spec version132 // Then restart each parachain's binaries133 // // Stop and restart each node134 // // Send specified keys to parachain nodes in case the parachain requires it135 // If it is not needed to upgrade runtimes themselves, the job is done!136137 // Record some required information regarding the relay chain138 await network.relay[0].connectApi();139 let relayInfo = getRelayInfo((network.relay[0] as any).apiInstance!);140 await network.relay[0].apiInstance!.disconnect();141 if(isUpgradeTesting) {142 console.log('Relay stats:', relayInfo);143 }144145 // non-exported functionality of NativeClient146 const networkClient = (network.client as any);147148 if(NEW_RELAY_BIN) {149 console.log('\n🧶 Restarting relay nodes');150151 for(const [index, node] of network.relay.entries()) {152 await node.apiInstance?.disconnect();153154 console.log(`\n🚦 Starting timeout for the epoch change (node ${index+1}/${network.relay.length})...`);155 await waitWithTimer(relayInfo.epochTime);156157 // Replace the node-starting command with the new binary158 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];159 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_RELAY_BIN));160161 await node.restart();162 }163164 console.log('\n🌒 All relay nodes restarted with the new binaries.');165 }166167 if(NEW_PARA_BIN) {168 for(const paraId in network.paras) {169 const para = network.paras[paraId];170 console.log(`\n🧶 Restarting collator nodes of parachain ${paraId}`);171172 for(const [_index, node] of para.nodes.entries()) {173 await node.apiInstance?.disconnect();174175 // Replace the node-starting command with the new binary176 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];177 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_PARA_BIN));178179 await node.restart();180 // applyaurakey?181 // Zombienet handles it on first-time node creation182 }183 }184185 console.log('\n🌗 All parachain collators restarted with the new binaries.');186 }187188 // Re-establish connection to the relay node and get the runtime upgrade validation delay for parachains189 // For the relay, connect and set the new runtime code190 // For each parachain, connect, authorize and upgrade its runtime191 // Ping the the chains for the runtime upgrade after the minimal time and then every few blocks192 // // For each parachain, re-connect and verify that the runtime upgrade is successful193194 let relayUpgradeCompleted = false, paraUpgradeCompleted = false;195196 if(NEW_RELAY_WASM) {197 const relayOldVersion = relayInfo.specVersion;198 console.log('\n🚦 Starting timeout for the next epoch before upgrading the relay runtime code...');199 await waitWithTimer(relayInfo.epochTime);200201 console.log('--- Upgrading the relay chain runtime \t---');202203 // Read the new WASM code and set it as the relay's new code204 const code = fs.readFileSync(NEW_RELAY_WASM).toString('hex');205 await usingPlaygrounds(async (helper, privateKey) => {206 const superuser = await privateKey(SUPERUSER_KEY);207208 const result = await helper.executeExtrinsic(209 superuser,210 'api.tx.sudo.sudoUncheckedWeight',211 [helper.constructApiCall('api.tx.system.setCode', [`0x${code}`]), {}],212 );213214 if(result.status == 'Fail') {215 console.error('Failed to upgrade the runtime:', result);216 }217218 // Get the updated information from the relay's new runtime219 relayInfo = getRelayInfo(helper.getApi());220 }, network.relay[0].wsUri);221222 if(relayOldVersion != relayInfo.specVersion) {223 // eslint-disable-next-line no-useless-escape224 console.log(`\n\🛰️ The relay has successfully upgraded from version ${relayOldVersion} to ${relayInfo.specVersion}!`);225 relayUpgradeCompleted = true;226 } else {227 console.error(`\nThe relay did not upgrade from version ${relayOldVersion}!`);228 }229 } else {230 // If the relay did not need to be upgraded, it's already technically completed231 relayUpgradeCompleted = true;232 }233234 if(NEW_PARA_WASM) {235 let codeValidationDelayBlocks = 0;236 const upgradingParas: {[id: string]: {version: number, upgraded: boolean}} = {};237 // Calculate the code validation delay of the relay chain,238 // so that we know how much to wait before the parachains can be upgraded after the extrinsic239 await usingPlaygrounds(async (helper) => {240 const {validationUpgradeDelay, minimumValidationUpgradeDelay} =241 (await helper.callRpc('api.query.configuration.activeConfig', [])).toJSON() as any;242243 codeValidationDelayBlocks = Math.max(validationUpgradeDelay ?? 0, minimumValidationUpgradeDelay ?? 0);244 }, network.relay[0].wsUri);245246 // Wait for the next epoch so that the parachains will start cooperating with the relay247 if(relayUpgradeCompleted && NEW_RELAY_WASM) {248 console.log('\n🚥 Starting timeout for the next epoch before upgrading the parachains code...');249 await waitWithTimer(relayInfo.epochTime);250 }251252 const migration = migrations[DESTINATION_SPEC_VERSION];253 console.log('⭐️⭐️⭐️ DESTINATION_SPEC_VERSION ⭐️⭐️⭐️', DESTINATION_SPEC_VERSION);254 for(const paraId in network.paras) {255 console.log(`\n--- Upgrading the runtime of parachain ${paraId} \t---`);256 const para = network.paras[paraId];257258 // Enable maintenance mode if present259 await toggleMaintenanceMode(true, para.nodes[0].wsUri);260 if(migration) {261 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');262 console.log('⭐️⭐️⭐️ Running pre-upgrade scripts... ⭐️⭐️⭐️');263 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');264 await migration.before();265 }266267 // Read the WASM code and authorize the upgrade with its hash and set it as the new runtime268 const code = fs.readFileSync(NEW_PARA_WASM);269 const codeHash = blake2AsHex(code);270 await usingPlaygrounds(async (helper, privateKey) => {271 const superuser = await privateKey(SUPERUSER_KEY);272273 upgradingParas[paraId] = {version: getSpecVersion(helper.getApi()), upgraded: false};274275 console.log('--- Authorizing the parachain runtime upgrade \t---');276 let result = await helper.executeExtrinsic(277 superuser,278 'api.tx.sudo.sudoUncheckedWeight',279 [helper.constructApiCall('api.tx.parachainSystem.authorizeUpgrade', [codeHash, false]), {}],280 );281282 if(result.status == 'Fail') {283 console.error('Failed to authorize the upgrade:', result);284 return;285 }286287 console.log('--- Enacting the parachain runtime upgrade \t---');288 result = await helper.executeExtrinsic(289 superuser,290 'api.tx.sudo.sudoUncheckedWeight',291 [helper.constructApiCall('api.tx.parachainSystem.enactAuthorizedUpgrade', [`0x${code.toString('hex')}`]), {}],292 );293294 if(result.status == 'Fail') {295 console.error('Failed to upgrade the runtime:', result);296 }297 }, para.nodes[0].wsUri);298 }299300 // Check the upgrades of the parachains, first after the minimum code validation delay, and then after some block time increments301 let firstPass = true;302 for(let attempt = 0; attempt < 3 && !paraUpgradeCompleted; attempt++) {303 if(firstPass) {304 console.log('\nCode validation delay:', codeValidationDelayBlocks, 'blocks');305 console.log('🚥 Waiting for the minimum code validation delay before the parachain can upgrade...');306 await waitWithTimer(relayInfo.blockTime * codeValidationDelayBlocks);307 firstPass = false;308 } else {309 console.log('\n🚥 Waiting for a few blocks more to verify that the parachain upgrades are successful...');310 await waitWithTimer(PARACHAIN_BLOCK_TIME * 3);311 }312313 // Ping the parachains' nodes for new runtime versions314 let upgradeFailed = false;315 for(const paraId in network.paras) {316 if(upgradingParas[paraId].upgraded) continue;317318 const para = network.paras[paraId];319 // eslint-disable-next-line require-await320 await usingPlaygrounds(async (helper) => {321 const specVersion = getSpecVersion(helper.getApi());322323 if(specVersion != upgradingParas[paraId].version) {324 // eslint-disable-next-line no-useless-escape325 console.log(`\n\🛰️ Parachain ${paraId} has successfully upgraded from version ${upgradingParas[paraId].version} to ${specVersion}!`);326 upgradingParas[paraId].upgraded = true;327 } else {328 console.error(`\nParachain ${paraId} failed to upgrade from version ${upgradingParas[paraId].version}!`);329 upgradeFailed = true;330 }331 }, para.nodes[0].wsUri);332333 paraUpgradeCompleted = !upgradeFailed;334 }335 }336337 // Disable maintenance mode if present338 for(const paraId in network.paras) {339 // TODO only if our parachain340 if(migration) {341 console.log('⭐️⭐️⭐️ Running post-upgrade scripts... ⭐️⭐️⭐️');342 await migration.after();343 }344 await toggleMaintenanceMode(false, network.paras[paraId].nodes[0].wsUri);345 }346 } else {347 // If the relay did not need to be upgraded, it's already technically completed348 paraUpgradeCompleted = true;349 }350351 // await network.stop();352353 if(isUpgradeTesting) {354 if(paraUpgradeCompleted && relayUpgradeCompleted) {355 console.log("\n🛸 PARACHAINS' RUNTIME UPGRADE TESTING COMPLETE 🛸");356 } else {357 console.error("\n🚧 PARACHAINS' RUNTIME UPGRADE TESTING FAILED 🚧");358 }359 } else {360 console.log('🚀 ZOMBIENET RAISED 🚀');361 }362};363364raiseZombienet()/*.then(async () => await stop())*/.catch(async (e) => {365 console.error(e);366 await stop();367 process.exit(1);368});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';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 DESTINATION_SPEC_VERSION = process.env.DESTINATION_SPEC_VERSION!;36const PARACHAIN_BLOCK_TIME = 12_000;37const SUPERUSER_KEY = '//Alice';3839let network: zombie.Network | undefined;4041// Stop the network if it is running42const stop = async () => {43 await network?.stop();44};4546// Promise of a timeout47function delay(ms: number) {48 return new Promise(resolve => setTimeout(resolve, ms));49}5051// Countdown with time left on display52async function waitWithTimer(time: number) {53 const secondsTotal = Math.ceil(time / 1000);54 for(let i = secondsTotal; i > 0; i--) {55 // could also introduce hours, but wth56 const seconds = i % 60;57 const text = `Time left: ${Math.floor(i/60)}:${seconds<10'0'+secondsseconds}`;58 if(process.stdout.isTTY)59 process.stdout.write(text);60 else if(seconds % 10 == 0)61 console.log(text);62 await delay(1000);63 if(process.stdout.isTTY) {64 process.stdout.clearLine(0);65 process.stdout.cursorTo(0);66 }67 }68}6970// Get the runtime's current version71function getSpecVersion(api: ApiPromise): number {72 return (api.consts.system.version as any).specVersion.toNumber();73}7475// Get the required information on the relay chain76function getRelayInfo(api: ApiPromise): {specVersion: number, epochBlockLength: number, blockTime: number, epochTime: number} {77 const info = {78 specVersion: getSpecVersion(api),79 epochBlockLength: (api.consts.babe.epochDuration as any).toNumber(),80 blockTime: (api.consts.babe.expectedBlockTime as any).toNumber(),81 epochTime: 0,82 };83 info.epochTime = info.epochBlockLength * info.blockTime;84 return info;85}8687// Enable or disable maintenance mode if present on the chain88async function toggleMaintenanceMode(value: boolean, wsUri: string) {89 await usingPlaygrounds(async (helper, privateKey) => {90 const superuser = await privateKey(SUPERUSER_KEY);91 try {92 const toggle = value ? 'enable' : 'disable';93 await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);94 console.log(`Maintenance mode ${value'engaged''disengaged'}.`);95 } catch (e) {96 console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);97 }98 }, wsUri);99}100101const raiseZombienet = async (): Promise<void> => {102 const isUpgradeTesting = !!NEW_RELAY_BIN || !!NEW_RELAY_WASM || !!NEW_PARA_BIN || !!NEW_PARA_WASM;103 /*104 // If there is nothing to upgrade, what is the point105 if (!isUpgradeTesting) {106 console.warn('\nNeither the relay nor the parachain were selected for an upgrade! ' +107 'Please pass environment vars `NEW_RELAY_BIN`, `NEW_RELAY_WASM`, `NEW_PARA_BIN`, `NEW_PARA_WASM`.');108 process.exit(1);109 }110 */111112 // an unsavory practice, but very convenient, mwahahah113 process.env.PARA_DIR = PARA_DIR;114 process.env.RELAY_DIR = RELAY_DIR;115 process.env.REPLICA_FROM = REPLICA_FROM;116117 const configPath = resolve(NETWORK_CONFIG_FILE);118 const networkConfig = readNetworkConfig(configPath);119 // console.log(networkConfig);120 if(networkConfig.settings.provider !== 'native') {121 throw new Error(`Oh no! Expected native network, got ${networkConfig.settings.provider}.`);122 }123124 await cryptoWaitReady();125126 // Launch Zombienet!127 network = await zombie.start(ZOMBIENET_CREDENTIALS, networkConfig, {silent: false});128129 // Get the relay chain info like the epoch length and spec version130 // Then restart each parachain's binaries131 // // Stop and restart each node132 // // Send specified keys to parachain nodes in case the parachain requires it133 // If it is not needed to upgrade runtimes themselves, the job is done!134135 // Record some required information regarding the relay chain136 await network.relay[0].connectApi();137 let relayInfo = getRelayInfo((network.relay[0] as any).apiInstance!);138 await network.relay[0].apiInstance!.disconnect();139 if(isUpgradeTesting) {140 console.log('Relay stats:', relayInfo);141 }142143 // non-exported functionality of NativeClient144 const networkClient = (network.client as any);145146 if(NEW_RELAY_BIN) {147 console.log('\n🧶 Restarting relay nodes');148149 for(const [index, node] of network.relay.entries()) {150 await node.apiInstance?.disconnect();151152 console.log(`\n🚦 Starting timeout for the epoch change (node ${index+1}/${network.relay.length})...`);153 await waitWithTimer(relayInfo.epochTime);154155 // Replace the node-starting command with the new binary156 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];157 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_RELAY_BIN));158159 await node.restart();160 }161162 console.log('\n🌒 All relay nodes restarted with the new binaries.');163 }164165 if(NEW_PARA_BIN) {166 for(const paraId in network.paras) {167 const para = network.paras[paraId];168 console.log(`\n🧶 Restarting collator nodes of parachain ${paraId}`);169170 for(const [_index, node] of para.nodes.entries()) {171 await node.apiInstance?.disconnect();172173 // Replace the node-starting command with the new binary174 const cmd = networkClient.processMap[node.name].cmd[0].split(' ')[0];175 networkClient.processMap[node.name].cmd = networkClient.processMap[node.name].cmd.map((arg: string) => arg.replace(cmd, NEW_PARA_BIN));176177 await node.restart();178 // applyaurakey?179 // Zombienet handles it on first-time node creation180 }181 }182183 console.log('\n🌗 All parachain collators restarted with the new binaries.');184 }185186 // Re-establish connection to the relay node and get the runtime upgrade validation delay for parachains187 // For the relay, connect and set the new runtime code188 // For each parachain, connect, authorize and upgrade its runtime189 // Ping the the chains for the runtime upgrade after the minimal time and then every few blocks190 // // For each parachain, re-connect and verify that the runtime upgrade is successful191192 let relayUpgradeCompleted = false, paraUpgradeCompleted = false;193194 if(NEW_RELAY_WASM) {195 const relayOldVersion = relayInfo.specVersion;196 console.log('\n🚦 Starting timeout for the next epoch before upgrading the relay runtime code...');197 await waitWithTimer(relayInfo.epochTime);198199 console.log('--- Upgrading the relay chain runtime \t---');200201 // Read the new WASM code and set it as the relay's new code202 const code = fs.readFileSync(NEW_RELAY_WASM).toString('hex');203 await usingPlaygrounds(async (helper, privateKey) => {204 const superuser = await privateKey(SUPERUSER_KEY);205206 const result = await helper.executeExtrinsic(207 superuser,208 'api.tx.sudo.sudoUncheckedWeight',209 [helper.constructApiCall('api.tx.system.setCode', [`0x${code}`]), {}],210 );211212 if(result.status == 'Fail') {213 console.error('Failed to upgrade the runtime:', result);214 }215216 // Get the updated information from the relay's new runtime217 relayInfo = getRelayInfo(helper.getApi());218 }, network.relay[0].wsUri);219220 if(relayOldVersion != relayInfo.specVersion) {221 // eslint-disable-next-line no-useless-escape222 console.log(`\n\🛰️ The relay has successfully upgraded from version ${relayOldVersion} to ${relayInfo.specVersion}!`);223 relayUpgradeCompleted = true;224 } else {225 console.error(`\nThe relay did not upgrade from version ${relayOldVersion}!`);226 }227 } else {228 // If the relay did not need to be upgraded, it's already technically completed229 relayUpgradeCompleted = true;230 }231232 if(NEW_PARA_WASM) {233 let codeValidationDelayBlocks = 0;234 const upgradingParas: {[id: string]: {version: number, upgraded: boolean}} = {};235 // Calculate the code validation delay of the relay chain,236 // so that we know how much to wait before the parachains can be upgraded after the extrinsic237 await usingPlaygrounds(async (helper) => {238 const {validationUpgradeDelay, minimumValidationUpgradeDelay} =239 (await helper.callRpc('api.query.configuration.activeConfig', [])).toJSON() as any;240241 codeValidationDelayBlocks = Math.max(validationUpgradeDelay ?? 0, minimumValidationUpgradeDelay ?? 0);242 }, network.relay[0].wsUri);243244 // Wait for the next epoch so that the parachains will start cooperating with the relay245 if(relayUpgradeCompleted && NEW_RELAY_WASM) {246 console.log('\n🚥 Starting timeout for the next epoch before upgrading the parachains code...');247 await waitWithTimer(relayInfo.epochTime);248 }249250 const migration = migrations[DESTINATION_SPEC_VERSION];251 console.log('⭐️⭐️⭐️ DESTINATION_SPEC_VERSION ⭐️⭐️⭐️', DESTINATION_SPEC_VERSION);252 for(const paraId in network.paras) {253 console.log(`\n--- Upgrading the runtime of parachain ${paraId} \t---`);254 const para = network.paras[paraId];255256 // Enable maintenance mode if present257 await toggleMaintenanceMode(true, para.nodes[0].wsUri);258 if(migration) {259 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');260 console.log('⭐️⭐️⭐️ Running pre-upgrade scripts... ⭐️⭐️⭐️');261 console.log('⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️');262 await migration.before();263 }264265 // Read the WASM code and authorize the upgrade with its hash and set it as the new runtime266 const code = fs.readFileSync(NEW_PARA_WASM);267 const codeHash = blake2AsHex(code);268 await usingPlaygrounds(async (helper, privateKey) => {269 const superuser = await privateKey(SUPERUSER_KEY);270271 upgradingParas[paraId] = {version: getSpecVersion(helper.getApi()), upgraded: false};272273 console.log('--- Authorizing the parachain runtime upgrade \t---');274 let result = await helper.executeExtrinsic(275 superuser,276 'api.tx.sudo.sudoUncheckedWeight',277 [helper.constructApiCall('api.tx.parachainSystem.authorizeUpgrade', [codeHash, false]), {}],278 );279280 if(result.status == 'Fail') {281 console.error('Failed to authorize the upgrade:', result);282 return;283 }284285 console.log('--- Enacting the parachain runtime upgrade \t---');286 result = await helper.executeExtrinsic(287 superuser,288 'api.tx.sudo.sudoUncheckedWeight',289 [helper.constructApiCall('api.tx.parachainSystem.enactAuthorizedUpgrade', [`0x${code.toString('hex')}`]), {}],290 );291292 if(result.status == 'Fail') {293 console.error('Failed to upgrade the runtime:', result);294 }295 }, para.nodes[0].wsUri);296 }297298 // Check the upgrades of the parachains, first after the minimum code validation delay, and then after some block time increments299 let firstPass = true;300 for(let attempt = 0; attempt < 3 && !paraUpgradeCompleted; attempt++) {301 if(firstPass) {302 console.log('\nCode validation delay:', codeValidationDelayBlocks, 'blocks');303 console.log('🚥 Waiting for the minimum code validation delay before the parachain can upgrade...');304 await waitWithTimer(relayInfo.blockTime * codeValidationDelayBlocks);305 firstPass = false;306 } else {307 console.log('\n🚥 Waiting for a few blocks more to verify that the parachain upgrades are successful...');308 await waitWithTimer(PARACHAIN_BLOCK_TIME * 3);309 }310311 // Ping the parachains' nodes for new runtime versions312 let upgradeFailed = false;313 for(const paraId in network.paras) {314 if(upgradingParas[paraId].upgraded) continue;315316 const para = network.paras[paraId];317 // eslint-disable-next-line require-await318 await usingPlaygrounds(async (helper) => {319 const specVersion = getSpecVersion(helper.getApi());320321 if(specVersion != upgradingParas[paraId].version) {322 // eslint-disable-next-line no-useless-escape323 console.log(`\n\🛰️ Parachain ${paraId} has successfully upgraded from version ${upgradingParas[paraId].version} to ${specVersion}!`);324 upgradingParas[paraId].upgraded = true;325 } else {326 console.error(`\nParachain ${paraId} failed to upgrade from version ${upgradingParas[paraId].version}!`);327 upgradeFailed = true;328 }329 }, para.nodes[0].wsUri);330331 paraUpgradeCompleted = !upgradeFailed;332 }333 }334335 // Disable maintenance mode if present336 for(const paraId in network.paras) {337 // TODO only if our parachain338 if(migration) {339 console.log('⭐️⭐️⭐️ Running post-upgrade scripts... ⭐️⭐️⭐️');340 await migration.after();341 }342 await toggleMaintenanceMode(false, network.paras[paraId].nodes[0].wsUri);343 }344 } else {345 // If the relay did not need to be upgraded, it's already technically completed346 paraUpgradeCompleted = true;347 }348349 // await network.stop();350351 if(isUpgradeTesting) {352 if(paraUpgradeCompleted && relayUpgradeCompleted) {353 console.log("\n🛸 PARACHAINS' RUNTIME UPGRADE TESTING COMPLETE 🛸");354 } else {355 console.error("\n🚧 PARACHAINS' RUNTIME UPGRADE TESTING FAILED 🚧");356 }357 } else {358 console.log('🚀 ZOMBIENET RAISED 🚀');359 }360};361362raiseZombienet()/*.then(async () => await stop())*/.catch(async (e) => {363 console.error(e);364 await stop();365 process.exit(1);366});tests/yarn.lockdiffbeforeafterboth--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -2116,11 +2116,6 @@
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"