diff --git a/.github/workflows/runtime-upgrade.yml b/.github/workflows/runtime-upgrade.yml index 5b7b7a52cd..214f6af226 100644 --- a/.github/workflows/runtime-upgrade.yml +++ b/.github/workflows/runtime-upgrade.yml @@ -284,7 +284,7 @@ jobs: with: name: creditcoin_node_runtime.compact.compressed.wasm - - name: Upgrade WASM + - name: Upgrade WASM & switchToPos run: | yarn --cwd ./scripts/js upgrade 'creditcoin-js' echo "DEBUG: **** free memory before runtimeUpgrade ****" @@ -292,6 +292,8 @@ jobs: ps aux --sort=-%mem | head -n 20 echo "DEBUG: *********************" yarn --cwd ./scripts/js runtimeUpgrade ws://127.0.0.1:9944 ../../creditcoin_node_runtime.compact.compressed.wasm //Alice 0 + sleep 10 + yarn --cwd ./scripts/js switchToPos ws://127.0.0.1:9944 //Alice # TODO: wait & confirm wasm upgrade has finished, incl. migrations - name: Execute integration tests diff --git a/scripts/js/package.json b/scripts/js/package.json index 925f21f265..715b86427d 100644 --- a/scripts/js/package.json +++ b/scripts/js/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "runtimeUpgrade": "ts-node ./src/runtimeUpgrade.ts", + "switchToPos": "ts-node ./src/switchToPos.ts", "lint": "eslint -c .eslintrc.js --ext .ts ./src", "format": "prettier --write \"src/**/*.ts\"", "check-format": "prettier --check \"src/**/*.ts\"", diff --git a/scripts/js/src/runtimeUpgrade.ts b/scripts/js/src/runtimeUpgrade.ts index 4d9ee49646..e4dc3376f7 100644 --- a/scripts/js/src/runtimeUpgrade.ts +++ b/scripts/js/src/runtimeUpgrade.ts @@ -113,33 +113,6 @@ async function doRuntimeUpgrade( } }); }); - - // WARNING: only used during fork-and-migrate testing - if (scheduleDelay === 0) { - callback = api.tx.posSwitch.switchToPos(); - - await new Promise((resolve, reject) => { - const unsubscribe = api.tx.sudo - .sudoUncheckedWeight(callback, overrideWeight) - .signAndSend(keyring, { nonce: -1 }, (result) => { - const finish = (fn: () => void) => { - unsubscribe - .then((unsub) => { - unsub(); - fn(); - }) - .catch(reject); - }; - if (result.isInBlock && !result.isError) { - console.log('switchToPos called'); - finish(resolve); - } else if (result.isError) { - const error = new Error(`Failed calling switchToPos: ${result.toString()}`); - finish(() => reject(error)); - } - }); - }); - } } finally { await api.disconnect(); } diff --git a/scripts/js/src/switchToPos.ts b/scripts/js/src/switchToPos.ts new file mode 100644 index 0000000000..b5c1254f17 --- /dev/null +++ b/scripts/js/src/switchToPos.ts @@ -0,0 +1,50 @@ +import { creditcoinApi, Keyring } from 'creditcoin-js'; +import { createOverrideWeight } from 'creditcoin-js/lib/utils'; + +async function doSwitchToPos(wsUrl: string, sudoKeyUri: string): Promise { + // init the api client + const { api } = await creditcoinApi(wsUrl); + try { + // make the keyring for the sudo account + const keyring = new Keyring({ type: 'sr25519' }).createFromUri(sudoKeyUri); + const overrideWeight = createOverrideWeight(api); + const callback = api.tx.posSwitch.switchToPos(); + + await new Promise((resolve, reject) => { + const unsubscribe = api.tx.sudo + .sudoUncheckedWeight(callback, overrideWeight) + .signAndSend(keyring, { nonce: -1 }, (result) => { + const finish = (fn: () => void) => { + unsubscribe + .then((unsub) => { + unsub(); + fn(); + }) + .catch(reject); + }; + if (result.isInBlock && !result.isError) { + console.log('switchToPos called'); + finish(resolve); + } else if (result.isError) { + const error = new Error(`Failed calling switchToPos: ${result.toString()}`); + finish(() => reject(error)); + } + }); + }); + } finally { + await api.disconnect(); + } +} + +if (process.argv.length < 3) { + console.error('switchToPos.ts '); + process.exit(1); +} + +const inputWsUrl = process.argv[2]; +const inputSudoKeyUri = process.argv[3]; + +doSwitchToPos(inputWsUrl, inputSudoKeyUri).catch((reason) => { + console.error(reason); + process.exit(1); +});