Skip to content

Commit

Permalink
load remote configs by name (#264)
Browse files Browse the repository at this point in the history
* load remote configs by name
  • Loading branch information
ermalkaleci authored Apr 20, 2023
1 parent 82eecc4 commit 60b83ee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<config_file_path>`
You can run a test node with config with `npx @acala-network/chopsticks@latest dev --config=<url | path | config_file_name>` [configs can be found here](configs/)

`npx @acala-network/chopsticks@latest dev --config acala`

## Install

Expand All @@ -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=<file_path>` to print out JSON file
Expand All @@ -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=<block_hash_optional>
npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --html --open --extrinsic=0xff00000080969800 --address=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY --at=<block_hash_optional>
```

- Dry run a preimage:
```
yarn start dry-run --endpoint=wss://rpc.polkadot.io --preimage=<preimage> --open
npx @acala-network/chopsticks@latest dry-run --endpoint=wss://rpc.polkadot.io --preimage=<preimage> --open
```

- Dry run a preimage and execute an extrinsic after that:
```
yarn start dry-run --endpoint=wss://rpc.polkadot.io --preimage=<preimage> --extrinsic=<extrinsic> --open
npx @acala-network/chopsticks@latest dry-run --endpoint=wss://rpc.polkadot.io --preimage=<preimage> --extrinsic=<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=<preimage> --extrinsic=<call> --address=<who> --open
npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --preimage=<preimage> --extrinsic=<call> --address=<who> --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
Expand Down Expand Up @@ -92,13 +94,13 @@ yarn start dry-run --config=configs/mandala.yml --preimage=<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
Expand Down
19 changes: 18 additions & 1 deletion packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/build-block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down

0 comments on commit 60b83ee

Please sign in to comment.