Skip to content

Commit

Permalink
try runtime (AcalaNetwork#222)
Browse files Browse the repository at this point in the history
* try runtime

* fixed review comments

* testing

* require wasm
  • Loading branch information
dzmitry-lahoda authored and ns212 committed Apr 3, 2023
1 parent fc5a7e9 commit b1ca9cd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { dryRun } from './dry-run'
import { dryRunPreimage } from './dry-run-preimage'
import { isUrl } from './utils'
import { runBlock } from './run-block'
import { tryRuntime } from './try-runtime'

const processConfig = async (path: string) => {
let file: string
Expand Down Expand Up @@ -82,6 +83,27 @@ yargs(hideBin(process.argv))
await runBlock(await processArgv(argv))
}
)
.command(
'try-runtime',
'Runs runtime upgrade',
(yargs) =>
yargs.options({
...defaultOptions,
'output-path': {
desc: 'File path to print output',
string: true,
},
html: {
desc: 'Generate html with storage diff',
},
open: {
desc: 'Open generated html',
},
}),
async (argv) => {
await tryRuntime(await processArgv(argv))
}
)
.command(
'dry-run',
'Dry run an extrinsic',
Expand Down
37 changes: 37 additions & 0 deletions packages/chopsticks/src/try-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { writeFileSync } from 'node:fs'

import { Config } from './schema'
import { generateHtmlDiffPreviewFile } from './utils/generate-html-diff'
import { openHtml } from './utils/open-html'
import { setup } from './setup'

export const tryRuntime = async (argv: Config) => {
if (argv['wasm-override'] === undefined) throw Error('`wasm-override` with `try-runtime` feature must be defined')
const context = await setup(argv)
const block = context.chain.head
const registry = await block.registry
registry.register({
UpgradeCheckSelect: {
_enum: {
None: null,
},
},
})

const select_none = registry.createType('UpgradeCheckSelect', 'None')
const result = await block.call('TryRuntime_on_runtime_upgrade', [select_none.toHex()], [])

if (argv['html']) {
const filePath = await generateHtmlDiffPreviewFile(block, result.storageDiff, block.hash)
console.log(`Generated preview ${filePath}`)
if (argv['open']) {
openHtml(filePath)
}
} else if (argv['output-path']) {
writeFileSync(argv['output-path'], JSON.stringify(result, null, 2))
} else {
console.dir(result, { depth: null, colors: false })
}

process.exit(0)
}

0 comments on commit b1ca9cd

Please sign in to comment.