Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load remote configs by name #264

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 20 additions & 2 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HexString } from '@polkadot/util/types'
import { accessSync, constants, readFileSync } from 'node:fs'
import { basename, extname } from 'node:path'
import { hideBin } from 'yargs/helpers'
import { readFileSync } from 'node:fs'
import _ from 'lodash'
import axios from 'axios'
import dotenv from 'dotenv'
Expand All @@ -13,17 +14,34 @@ 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 {
accessSync(path, constants.R_OK)
xlc marked this conversation as resolved.
Show resolved Hide resolved
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