From 60b83eeffa023494e34baa5e300dc49db067f643 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 20 Apr 2023 10:59:46 +0200 Subject: [PATCH] load remote configs by name (#264) * load remote configs by name --- README.md | 26 ++++++++++++++------------ packages/chopsticks/src/cli.ts | 19 ++++++++++++++++++- packages/e2e/src/build-block.test.ts | 2 +- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 97604383..fe2ce5cb 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ Create parallel reality of your Substrate network. ## Quick Start -Fork Acala mainnet: `yarn dlx @acala-network/chopsticks dev --endpoint=wss://acala-rpc-2.aca-api.network/ws` +Fork Acala mainnet: `npx @acala-network/chopsticks@latest dev --endpoint=wss://acala-rpc-2.aca-api.network/ws` It is recommended to use config file. You can check [configs](configs/) for examples. -You can run a test node with config with `yarn dlx @acala-network/chopsticks dev --config=` +You can run a test node with config with `npx @acala-network/chopsticks@latest dev --config=` [configs can be found here](configs/) + +`npx @acala-network/chopsticks@latest dev --config acala` ## Install @@ -24,7 +26,7 @@ Make sure you have setup Rust environment (>= 1.64). ## Run - Replay latest block - - `yarn start run-block --endpoint=wss://acala-rpc-2.aca-api.network/ws` + - `npx @acala-network/chopsticks@latest run-block --endpoint=wss://acala-rpc-2.aca-api.network/ws` - This will replay the last block and print out the changed storages - Use option `--block` to replay certain block hash - Use option `--output-path=` to print out JSON file @@ -34,36 +36,36 @@ Make sure you have setup Rust environment (>= 1.64). - Dry run hep: ``` - yarn start dry-run --help + npx @acala-network/chopsticks@latest dry-run --help ``` - Dry run extrinsic, same as `run-block`, example: ``` -yarn start dry-run --config=configs/mandala.yml --html --open --extrinsic=0x39028400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01183abac17ff331f8b65dbeddd27f014dedd892020cfdc6c40b574f6930f8cf391bde95997ae2edc5b1192a4036ea97804956c4b5497175c8d68b630301685889450200000a00008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480284d717 +npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --html --open --extrinsic=0x39028400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01183abac17ff331f8b65dbeddd27f014dedd892020cfdc6c40b574f6930f8cf391bde95997ae2edc5b1192a4036ea97804956c4b5497175c8d68b630301685889450200000a00008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480284d717 ``` - Dry run call, make sure `mock-signature-host: true` to fake caller's signature: ``` -yarn start dry-run --config=configs/mandala.yml --html --open --extrinsic=0xff00000080969800 --address=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY --at= +npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --html --open --extrinsic=0xff00000080969800 --address=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY --at= ``` - Dry run a preimage: ``` -yarn start dry-run --endpoint=wss://rpc.polkadot.io --preimage= --open +npx @acala-network/chopsticks@latest dry-run --endpoint=wss://rpc.polkadot.io --preimage= --open ``` - Dry run a preimage and execute an extrinsic after that: ``` -yarn start dry-run --endpoint=wss://rpc.polkadot.io --preimage= --extrinsic= --open +npx @acala-network/chopsticks@latest dry-run --endpoint=wss://rpc.polkadot.io --preimage= --extrinsic= --open ``` - Dry run a preimage and execute a call after that, make sure `mock-signature-host: true` to fake caller's signature: ``` -yarn start dry-run --config=configs/mandala.yml --preimage= --extrinsic= --address= --open +npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --preimage= --extrinsic= --address= --open ``` - Run a test node - - `yarn start dev --endpoint=wss://acala-rpc-2.aca-api.network/ws` + - `npx @acala-network/chopsticks@latest dev --endpoint=wss://acala-rpc-2.aca-api.network/ws` - You have a test node running at `ws://localhost:8000` - You can use [Polkadot.js Apps](https://polkadot.js.org/apps/) to connect to this node - Submit any transaction to produce a new block in the in parallel reality @@ -92,13 +94,13 @@ yarn start dry-run --config=configs/mandala.yml --preimage= --extrinsi - Run Kusama fork - Edit configs/kusama.yml if needed. (e.g. update the block number) - - `yarn start dev --config=configs/kusama.yml` + - `npx @acala-network/chopsticks@latest dev --config=configs/kusama.yml` - Setup XCM multichain **_NOTE:_** You can also connect multiple parachains without a relaychain ```bash -yarn start xcm --relaychain=configs/kusama.yml --parachain=configs/karura.yml --parachain=configs/statemine.yml +npx @acala-network/chopsticks@latest xcm --relaychain=configs/kusama.yml --parachain=configs/karura.yml --parachain=configs/statemine.yml ``` ## Documentation diff --git a/packages/chopsticks/src/cli.ts b/packages/chopsticks/src/cli.ts index d42221c0..3a1d3890 100644 --- a/packages/chopsticks/src/cli.ts +++ b/packages/chopsticks/src/cli.ts @@ -1,4 +1,5 @@ import { HexString } from '@polkadot/util/types' +import { basename, extname } from 'node:path' import { hideBin } from 'yargs/helpers' import { readFileSync } from 'node:fs' import _ from 'lodash' @@ -13,17 +14,33 @@ import { decodeKey } from './utils/decoder' import { dryRun } from './dry-run' import { dryRunPreimage } from './dry-run-preimage' import { isUrl } from './utils' +import { logger } from './rpc/shared' import { runBlock } from './run-block' import { tryRuntime } from './try-runtime' dotenv.config() +const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/' + const processConfig = async (path: string) => { let file: string if (isUrl(path)) { file = await axios.get(path).then((x) => x.data) } else { - file = readFileSync(path, 'utf8') + try { + file = readFileSync(path, 'utf8') + } catch (err) { + if (basename(path) === path && ['', '.yml', '.yaml', '.json'].includes(extname(path))) { + if (extname(path) === '') { + path += '.yml' + } + const url = CONFIGS_BASE_URL + path + logger.info(`Loading config file ${url}`) + file = await axios.get(url).then((x) => x.data) + } else { + throw err + } + } } const config = yaml.load(_.template(file, { variable: 'env' })(process.env)) as any return configSchema.parse(config) diff --git a/packages/e2e/src/build-block.test.ts b/packages/e2e/src/build-block.test.ts index 1155a266..80901cc8 100644 --- a/packages/e2e/src/build-block.test.ts +++ b/packages/e2e/src/build-block.test.ts @@ -14,7 +14,7 @@ describe.each([ { chain: 'Westend', endpoint: 'wss://westend-rpc.polkadot.io' }, { chain: 'Westmint', endpoint: 'wss://westmint-rpc.polkadot.io' }, - { chain: 'Westend Collectives', endpoint: 'wss://westend-collectives-rpc.polkadot.io' }, + { chain: 'Westend Collectives', endpoint: 'wss://sys.ibp.network/collectives-westend' }, ])('Latest $chain can build blocks', async ({ endpoint }) => { const { setup, teardownAll } = await setupAll({ endpoint })