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

Chopsticks tests initial set-up and documentation #6227

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions cumulus/parachains/integration-tests/chopsticks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Chopsticks tests introduce a way of sending real-world API requests to Substrate-based networks, which are built and run locally, on your computer.
For now, we use it to test new APIs locally, before deploying it to any of the testnets. You can find comprehensive documentation under [this link](https://papermoonio.github.io/polkadot-ecosystem-docs-draft/dev-tools/chopsticks/overview/)

***NOTE***: this guide uses [Bun](https://bun.sh/) instead of [Node](nodejs.org).
If you are willing to use Node, please, refer to [Papermoon docs](https://papermoonio.github.io/polkadot-ecosystem-docs-draft/dev-tools/chopsticks/overview/).

To get started with chopsticks:
1. Make sure you have [Bun](https://bun.sh/docs/installation) installed, or you can use the following commands:
- `curl -fsSL https://bun.sh/install | bash`
- `export BUN_INSTALL="$HOME/.bun"`
- `export PATH="$BUN_INSTALL/bin:$PATH"`
2. Go through the instructions inside the `wasms` folder.
3. Once you have your WASM BLOBs in place, you can run a node using the following command:
- `bunx @acala-network/chopsticks@latest xcm -r configs/westend-override.yaml -p configs/westend-asset-hub-override.yaml`
This particular command should span up two RPC servers (you can specify as many parachains as needed by chaining `-p configs/another-parachain-config.yaml`) and
output the ports they reserved for themselves.
4. Once relay (and parachains) are up and running you can proceed with sending RPCs with the help of bun (see `tests` folder).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This folder serves as a reference documentation for chopstick tests and the Parity-owned ecosystems.
It provides a working set of configuration files together with the WASM BLOBs, specifically for the Westend ecosystem.
For additional resources and original Acala configuration files, including documentation, refer to the [Acala repository](https://github.com/AcalaNetwork/chopsticks/tree/master/configs) or [Papermoon chopsticks overview](https://papermoonio.github.io/polkadot-ecosystem-docs-draft/dev-tools/chopsticks/overview/#using-a-configuration-file)

Config files, especially `wasm-override:` fields there, assume that there is a `wasms` folder within the same parent directory, and it contains pre-built WASM BLOBs of the
ecosystem under tests.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
endpoint: wss://asset-hub-polkadot-rpc.dwellir.com
mock-signature-host: true
block: ${env.WESTEND_ASSET_HUB_BLOCK_NUMBER}
db: ./db.sqlite
runtime-log-level: 5
wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm

import-storage:
System:
Account:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- providers: 1
data:
free: 1000000000000000
-
-
- 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia
- providers: 1
data:
free: 1000000000000000
Assets:
Account:
- [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }]
- [[1984, 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { balance: 1000000000 }]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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:
System:
Account:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- providers: 1
data:
free: '10000000000000000000'
ParasDisputes:
$removePrefix: ['disputes']
10 changes: 10 additions & 0 deletions cumulus/parachains/integration-tests/chopsticks/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1. Please, create a separate folder for your decentralized APP or chopstick tests.
2. Make sure you have [Bun](https://bun.sh/docs/installation) installed:
3. Once you have your folder you can run `bun init` inside of it, and it will create a default set-up for you. Hit enter twice to choose the default options.
4. Now you need to add polkadot-api or papi:
- `bun add polkadot-api`
5. Add your ecosystem (`westend` or `wnd` in this case):
- `bun papi add wnd -w ws://localhost:8001`
- you can find the port as the output of running `bunx` command in the folder above
6. Once it's done you can implement your tests. Feel free to use other's tests as code reference.
7. To run the tests execute `bun test ./index.ts`
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { test, expect } from "bun:test";
import { wnd, XcmV3Junctions, XcmV3Junction, XcmV3MultiassetFungibility } from "@polkadot-api/descriptors";
import { Enum, createClient } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws-provider/web";
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";

let client = createClient(
withPolkadotSdkCompat(
getWsProvider("ws://localhost:8001")
)
);
let dotApi = client.getTypedApi(wnd);

const testCases = [
{
description: 'Test with trusted location',
asset: Enum('V4', {
id: {
parents: 0,
interior: XcmV3Junctions.Here(),
},
fun: XcmV3MultiassetFungibility.Fungible(1n),
}),
location: Enum('V4', {
parents: 0,
interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000))
}),
want: true
},
{
description: 'Test with untrusted location',
asset: Enum('V4', {
id: {
parents: 0,
interior: XcmV3Junctions.Here(),
},
fun: XcmV3MultiassetFungibility.Fungible(2n),
}),
location: Enum('V4', {
parents: 0,
interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2000))
}),
want: false
},
];

testCases.forEach(({ description, asset, location, want }) => {
test(description, async () => {
const resp = await dotApi.apis.TrustedQueryApi.is_trusted_teleporter(asset, location);

expect(resp.success).toBe(true);
expect(resp.value).toBe(want);

console.log(`Test: ${description}, want: ${want}, got: ${resp.value}`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This folder contains WASM BLOBs which are supposed to be used by chopstick tests.
To populate this folder with the required files you need to:
1. BUILD relevant runtimes: usually relay and parachain(s).
- `cargo build --release -p westend-runtime `
- `cargo build --release -p asset-hub-westend-runtime `
2. Copy compressed wasms from target folder into the current one:
- `WBUILD_PATH=../../../../../target/release/wbuild`
- `cp $WBUILD_PATH/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm .`
- `cp $WBUILD_PATH/westend-runtime/westend_runtime.compact.compressed.wasm .`
Loading