## Running vanilla chopsticks with your local code This post focuses on how to test your unreleased changes (the one living on your git branch) with Chopsticks. It assumes that you have the same folder structure, as presented in [PR#6572](https://github.com/paritytech/polkadot-sdk/pull/6572) **chopsticks** directory. ### Motivation Whenever we develop a customer facing feature: be it a new XCM instruction or a modification of the runtime APIs, we want to make sure that our new feature won't break the system. We need an extra layer of testing for this. That's where chopsticks come into play. A quick refresher what chopsticks are: >>> Chopsticks provides a developer-friendly method of locally forking existing Substrate based chains. It allows for the replaying of blocks to easily examine how extrinsics effect state, the forking of multiple blocks for XCM testing, and more. This allows developers to test and experiment with their own custom blockchain configurations in a local development environment, without the need to deploy a live network. ### Building wasm(s) Checkout to the branch where your changes live and build a new runtime, by using: ```bash cargo build --release -p westend-runtime ``` That wasm is stored under ```bash polkadot-sdk/target/release/wbuild/westend-runtime/westend_runtime.compact.compressed.wasm ``` You can build as many runtimes as needed. The you'll need to supply chopsticks with the paths to wasms. ### Configuring chopsticks Here is an example of westend relay config. ```yaml= endpoint: - wss://westend-rpc.dwellir.com mock-signature-host: true block: ${env.WESTEND_BLOCK_NUMBER} db: ./db.sqlite runtime-log-level: 5 wasm-override: wasms/westend_runtime.compact.compressed.wasm import-storage: XcmPallet: SafeXcmVersion: 5 System: Account: - - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY - providers: 1 data: free: '10000000000000000000' ParasDisputes: $removePrefix: ['disputes'] ``` As you can see under `wasm-override` lives our wasm path that point to the new runtime we've built. ### Run chopsticks with new wasms To run chopsticks you need to install [bun](bun.sh) by running: ```bash= curl -fsSL https://bun.sh/install | bash ``` Don't forget to execute the commands that it outputs. After that, from **chopsticks** directory run: ```bash bunx @acala-network/chopsticks@latest xcm \n -r configs/westend-override.yaml \n -p configs/westend-asset-hub-override.yaml \n ``` It will spin up nodes for westend relay and asset hub system parachain, as well as print the ports those chains are using. > Note: you can find an example of Asset Hub + Westend Relay set-up in the pr iteslf. ### Set-up scripts folder We use PAPI (a.k.a Polkadot API) as an interface to interact with substrate based chains. It's a successor of [PJS](https://polkadot.js.org/apps/#/explorer) that you may know. The scripts live under `cumulus/parachains/integration-tests/chopsticks/tests/v5-tests` directory. Open a new terminal window and `cd` there. To make papi scripts work, you need to install required dependecies: ```bash bun add polkadot-api bun add @polkadot-labs/hdkd ``` and generate chain metadata: ```bash bun papi add wnd_ah -w ws://localhost:8000 ``` In this case we take asset hub westned port that `bunx` command printed. ### Running scripts To run scripts simply execute: ```bash= bun test ./index.ts ``` > note: the test may time-out during the first run. A single retry usually helps. ### Writing your own scripts As you can see **v5-tests** provides you with code snippets how to create and initialize Asset Hub API client: ```typescript= const client = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); const AHApi = client.getTypedApi(wnd_ah); ``` You can use the client to: query a runtime API: ```typescript= AHApi.apis.XcmPaymentApi.query_xcm_weight(message); ``` or execute XCM programs using XCM pallet: ```typescript= AHApi.tx.PolkadotXcm.execute({ message: msg, max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, }); ``` You can easily plug-and-play your xcm programs inside `msg` and execute them against the parachain you want. ### Difference between vanilla chopsticks and ecosystem tests As you might know there are [ecosystem tests](https://github.com/open-web3-stack/polkadot-ecosystem-tests/tree/master) which are a framework on top of chopsticks to run and validate tests. For the moment of writing this article the framework has some limitations, like PAPI support or multi-hop (3+) XCMs. To overcome those temporary limitations and have the freedom of development, you may use vanilla chopsticks approach presented above. Vanilla chopsticks are also useful to trace XCM command exeuction among the chains. Previously, it was not feasible to do with ecosystem tests.