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

fix: ci integration tests chopsticks #839

Open
wants to merge 114 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
74b2fa5
first mvp
Ad96el May 31, 2024
12eae01
revert
Ad96el May 31, 2024
6dc7a5c
v3
Ad96el May 31, 2024
3e22e27
withdraw assets
Ad96el May 31, 2024
dc5428b
check validation
Ad96el Jun 3, 2024
bba0541
fix validateBalanceWithPrecision
Ad96el Jun 20, 2024
85e936f
fix withdraw assets
Ad96el Jun 20, 2024
3f1fbfe
update snapshots
Ad96el Jun 20, 2024
b3b1c83
passing tests
Ad96el Jun 21, 2024
1e0d171
passing tests
Ad96el Jun 21, 2024
91cc0e1
update readme
Ad96el Jun 21, 2024
e2df711
update comments
Ad96el Jun 21, 2024
5caf948
update comments
Ad96el Jun 21, 2024
447c412
Merge branch 'develop' into ag_chopsticks_design
Ad96el Jun 21, 2024
7c34af7
update CI
Ad96el Jun 21, 2024
58227db
Merge branch 'ag_chopsticks_design' of github.com:KILTprotocol/kilt-n…
Ad96el Jun 21, 2024
2dcafff
update CI
Ad96el Jun 21, 2024
69ab715
ci-skip-rust
Ad96el Jun 24, 2024
117b290
ci-skip-rust
Ad96el Jun 24, 2024
9fcf36e
start refactor
Ad96el Jan 6, 2025
c5ec5d4
first draft for full
Ad96el Jan 6, 2025
469617a
commit basic changes
Ad96el Jan 7, 2025
cc75667
Pr comments
Ad96el Jan 7, 2025
e0cf9ec
Merge branch 'develop' into ag_chopsticks_design_switch
Ad96el Jan 7, 2025
b66f6e5
Merge branch 'develop' into ag_chopsticks_design
Ad96el Jan 8, 2025
8443203
revert ci
Ad96el Jan 8, 2025
dc0eebf
Merge branch 'ag_chopsticks_design' into ag_chopsticks_design_switch
Ad96el Jan 8, 2025
e5eb568
recert chopsticks
Ad96el Jan 8, 2025
fdbcd26
test running
Ad96el Jan 8, 2025
b378738
lock file
Ad96el Jan 8, 2025
1bc2936
update events
Ad96el Jan 8, 2025
fd9463f
fixed events + invariant
Ad96el Jan 8, 2025
1285e5d
draft
Ad96el Jan 9, 2025
c031618
tx executing
Ad96el Jan 9, 2025
9b63285
fix dev wasm
Ad96el Jan 9, 2025
f3a9238
add test to switch eKilts
Ad96el Jan 9, 2025
ea8f0a5
switch kilts vs eKilts
Ad96el Jan 9, 2025
30b23f6
fmt
Ad96el Jan 9, 2025
1f8f7ed
send relay token paused switch
Ad96el Jan 13, 2025
47d14c9
switch kilts
Ad96el Jan 13, 2025
1e469ff
no switch tests
Ad96el Jan 13, 2025
9a608e7
no handling on receiver
Ad96el Jan 13, 2025
ca13358
other reserve location
Ad96el Jan 14, 2025
cf8e9e4
withdraw paused
Ad96el Jan 14, 2025
c1455f8
rename folders
Ad96el Jan 14, 2025
773f0fd
dust user
Ad96el Jan 14, 2025
bbb42b8
reclaim assets
Ad96el Jan 14, 2025
25cd688
refactor all test cases
Ad96el Jan 14, 2025
0277a87
random db
Ad96el Jan 14, 2025
7d80602
spelling error
Ad96el Jan 14, 2025
f0d5176
change configs
Ad96el Jan 14, 2025
5124cc3
intermediate
Ad96el Jan 16, 2025
9aa75c7
intermediate
Ad96el Jan 17, 2025
73c7471
intermediate
Ad96el Jan 17, 2025
06bd588
add invariant checks
Ad96el Jan 21, 2025
eb9986a
update events
Ad96el Jan 21, 2025
57253e6
ci-skip-rust
Ad96el Jan 21, 2025
073fbf9
ci-skip-rust lint
Ad96el Jan 21, 2025
12080e1
ci-skip-rust lint
Ad96el Jan 21, 2025
2a255a6
ci-skip-rust path
Ad96el Jan 21, 2025
34d9b55
no default exports
Ad96el Jan 21, 2025
9fec62a
alter types
Ad96el Jan 21, 2025
e5008ea
import type
Ad96el Jan 21, 2025
380099b
ci-skip-rust change timeout
Ad96el Jan 21, 2025
cf07fd0
ci-skip-rust change events
Ad96el Jan 22, 2025
9aaacd8
ci-skip-rust type for setup configs
Ad96el Jan 22, 2025
335e7e2
ci-skip-rust type update events
Ad96el Jan 22, 2025
ca5ee1e
ci-skip-rust increase timeout
Ad96el Jan 22, 2025
f31672b
ci-skip-rust remove wasm
Ad96el Jan 22, 2025
dc4fa42
update envs
Ad96el Jan 23, 2025
51945d2
rename hydration
Ad96el Jan 23, 2025
35f6f28
ci-skip-rust add docs
Ad96el Jan 23, 2025
12b8e54
ci-skip-rust revert script file
Ad96el Jan 23, 2025
25b723f
Merge branch 'develop' into ag_chopsticks_design
Ad96el Jan 23, 2025
39a9ba7
Merge branch 'ag_chopsticks_design' into ag_chopsticks_design_switch
Ad96el Jan 23, 2025
b939960
Merge branch 'develop' into ag_chopsticks_design
Ad96el Jan 23, 2025
43e6467
Merge branch 'ag_chopsticks_design' into ag_chopsticks_design_switch
Ad96el Jan 23, 2025
1338c96
ci-skip-rust revert did
Ad96el Jan 23, 2025
c49bc1f
ci-skip-rust rupdate events
Ad96el Jan 23, 2025
5306394
ci-skip-rust update ci
Ad96el Jan 24, 2025
e4b4339
ci-skip-rust update ci
Ad96el Jan 24, 2025
6b24332
ci-skip-rust update ci
Ad96el Jan 24, 2025
83369ab
rename interface
Ad96el Jan 27, 2025
62abac6
update full flow
Ad96el Jan 27, 2025
f145049
add utils test file
Ad96el Jan 30, 2025
8d1aa8c
change spinUp
Ad96el Jan 30, 2025
0eb45b2
ci-skip-rust update interface
Ad96el Jan 31, 2025
bd6916e
ci-skip-rust add comments
Ad96el Jan 31, 2025
1b237a5
ci-skip-rust update ci
Ad96el Jan 31, 2025
0b98fa7
chore: chopsticks utils (#857)
Ad96el Feb 6, 2025
f05f814
Merge branch 'develop' into ag_chopsticks_design_switch
Ad96el Feb 6, 2025
f3bb203
Merge branch 'develop' into ag_chopsticks_design_switch
Ad96el Feb 10, 2025
1b3dfbe
bigint
Ad96el Feb 17, 2025
914c8b4
replace filter with find
Ad96el Feb 17, 2025
76071c6
getPaidXcmFees
Ad96el Feb 17, 2025
0460f85
getReceivedNativeTokens
Ad96el Feb 17, 2025
d6aa9b8
rename timeout
Ad96el Feb 17, 2025
7e0a639
connect vertically in parallel
Ad96el Feb 17, 2025
712827f
no async describes
Ad96el Feb 17, 2025
5c0108a
check if event
Ad96el Feb 17, 2025
9b285ca
isPaused
Ad96el Feb 17, 2025
d9fd351
switchPair error
Ad96el Feb 17, 2025
83b19cb
afterEach closures
Ad96el Feb 17, 2025
f8c09dc
fix token queries
Ad96el Feb 17, 2025
93a9e23
falsy at
Ad96el Feb 18, 2025
6e71bf1
await
Ad96el Feb 18, 2025
dd4e24d
-balance
Ad96el Feb 18, 2025
fa32868
event
Ad96el Feb 18, 2025
423616b
less anys
Ad96el Feb 18, 2025
4eedb91
ci-skip-rust fix
Ad96el Feb 18, 2025
10c59f3
fix event filter
Ad96el Feb 19, 2025
753148d
ci-skip-rust change type
Ad96el Feb 19, 2025
ec881b6
ci-skip-rust expect to be true
Ad96el Feb 19, 2025
ddc0049
Merge branch 'develop' into ag_chopsticks_design_switch
Ad96el Feb 24, 2025
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
38 changes: 22 additions & 16 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ jobs:
env:
working-dir: ./integration-tests/chopsticks
CI: true
PEREGRINE_WASM_OVERRIDE: ../../target/debug/wbuild/peregrine-runtime/peregrine_runtime.wasm
SPIRITNET_BLOCK_NUMBER: 7850499
HYDRATION_BLOCK_NUMBER: 5235787
POLKADOT_BLOCK_NUMBER: 21010819
ASSETHUB_BLOCK_NUMBER: 7934113
SPIRITNET_WASM_OVERRIDE: ../../target/wasm32-unknown-unknown/debug/wbuild/spiritnet-runtime/spiritnet_runtime.wasm
PEREGRINE_WASM_OVERRIDE: ../../target/wasm32-unknown-unknown/debug/wbuild/peregrine-runtime/peregrine_runtime.wasm

defaults:
run:
working-directory: ${{ env.working-dir }}
Expand All @@ -148,6 +154,18 @@ jobs:
with:
tool-cache: true

- name: Set up Cargo cache
uses: actions/cache@v4
with:
# These paths are mounted inside the Docker container.
# We cannot mount the `.cargo/bin` folder since the container already contains binaries, and overriding with an empty one breaks compilation.
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ github.job }}-${{ github.ref }}-${{ matrix.features }}-${{ hashFiles('**/Cargo.lock') }}
save-always: true

- name: Setup environment
uses: actions/setup-node@v4
with:
Expand All @@ -162,23 +180,11 @@ jobs:
- name: Check lints
run: yarn lint

- name: Set up Cargo cache
uses: actions/cache@v4
with:
# Not executed in a container, so we cache the local paths as on the GH worker.
path: |
${HOME}/.cargo/bin/
${HOME}/.cargo/registry/index/
${HOME}/.cargo/registry/cache/
${HOME}/.cargo/git/db/
key: ${{ github.job }}-${{ github.ref }}-${{ hashFiles('**/Cargo.lock') }}
save-always: true

- name: Build Peregrine runtime
run: cargo build -p peregrine-runtime
- name: Build runtime wasms
run: cargo build -p peregrine-runtime -p spiritnet-runtime --no-default-features --target wasm32-unknown-unknown

- name: Run Chopsticks tests
run: yarn test:CI
run: yarn test

cargo-test:
name: Run Cargo tests
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ runtimes/spiritnet/src/xcm_tests/e2e/out
chopsticks/**/db.sqlite*
chopsticks/**/extra.yaml
chopsticks/**/.tmp.yaml
**/preview

integration-tests/**/db
40 changes: 36 additions & 4 deletions integration-tests/chopsticks/.env-example
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
HYDRADX_WS=
HYDRADX_PORT=
POLKADOT_WS=
POLKADOT_PORT=
# These env variables are mandatory for the tests to work.

# The Spiritnet block number to be used in the tests
SPIRITNET_BLOCK_NUMBER=
# The Hydration block number to be used in the tests
HYDRATION_BLOCK_NUMBER=
# The Polkadot block number to be used in the tests
POLKADOT_BLOCK_NUMBER=
# Directory path to the new WASM blob
SPIRITNET_WASM_OVERRIDE=
# The AssetHub block number to be used in the tests
ASSETHUB_BLOCK_NUMBER=


# Optional env variables
HYDRATION_TEST_WS=
HYDRATION_TEST_PORT=

HYDRATION_WS=
HYDRATION_PORT=

ASSETHUB_WSS=
ASSETHUB_MAIN_PORT=

ASSETHUB_TEST_WSS=
ASSETHUB_TEST_PORT=

SPIRITNET_WS=
SPIRITNET_PORT=

PEREGRINE_WS=
PEREGRINE_PORT=

POLKADOT_WS=
POLKADOT_PORT=

PASEO_WS=
PASEO_PORT=
148 changes: 148 additions & 0 deletions integration-tests/chopsticks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# e2e Chopsticks tests

This project is a set of end-to-end tests for the KILT protocol against other parachains.
Other functionalities such as a creation of DID can be easily added.

## Getting Started

These instructions will allow you to run the tests on your local machine for development and testing purposes.

### Prerequisites

- Node.js v20.11.0 (as specified in the [`.nvmrc`](https://github.com/nvm-sh/nvm)). With `nvm use` the right node version will be installed.
- npm (comes with Node.js)

### Installing

To install the node modules call:

```sh
yarn
```

### Running the tests

In the package.json a script is provided.

By calling the command below, the test will be executed:

```sh
yarn test
```

Please make sure an appropriate env is set.

### Env

The project uses environment variables for configuration.
You can find an example in the `.env-example` file. Copy this file to
.env and fill in the appropriate values.
Explanation for the values are in the `.env-example` file provided.

## Code Style

This project uses Prettier and ESLint for code formatting and linting.
The configuration for these tools can be found in the `.prettierrc` and `.eslintrc.json` files respectively.

To check your code for style issues, run:

```sh
yarn lint
```

To automatically fix style issues, run:

```sh
yarn lint:fix
```

## Adding a new test case

To add a new test case, you need to insert a new object into the list of test cases.
For example, if you want to add a new instance of `LimitedReserveTestConfiguration`, you would insert it into the `testPairsLimitedReserveTransfers` list.

The tests are configuration-driven, meaning they can be easily customized for different scenarios.
The test framework doesn't make assumptions about which parachain is sending which coin to which destination over which relay chain.
Fundamental events such as the moving of coins or the creation of a new account should be emitted during the test.

The test cases live in the tests folder and use mocks from the network directory.
The network directory contains helper functions to set the blockchain state and provides an abstraction over the chopsticks functionalities, such as creating a network.

For Adding a new test case scenario, a template folder is provided.

## Debugging Existence Tests

Each test case should have a unique ID. To execute a specific test case, run:

```sh
yarn test -t "REGULAR_EXPRESSION"
```

## UI

Vitest supports a UI to manage the test cases. To spin up the UI, call:

```sh
yarn ui
```

## CLI

The project provides a CLI to interact with the test framework.
To execute the cli run:

```sh
yarn cli [COMMAND]
```

Below are the available commands and their descriptions:

`spinUp`

Spins up the network using the definition in `./src/command/network.ts`.
The network configuration can be adjusted as needed.
A detailed step-by-step explanation of how to modify the network to a specific state is provided in the `network.ts` file.

```sh
yarn cli spinUp
```

`scheduleTx`

Executes a transaction on the network, creating a new Chopsticks instance.

```sh
yarn cli scheduleTx endpoint rawTx [options]
```

- endpoint: The endpoint of the network.
- rawTx: The raw transaction to execute.
- --origin: The origin of the transaction (default: Root).
- --port: The RPC port (default: 8888).

`stateTransition`

Shows the state transition of the network based on the latest block.
The command creates a preview folder containing an HTML file, which can be opened in a browser to inspect the state transition.

```sh
yarn cli stateTransition endpoint [option]
```

- endpoint: The endpoint of the network.
- --block: The block to do the state transition


## Recommended VS Code Extensions

- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint): Integrates ESLint into VS Code, a tool for identifying and reporting on patterns in JavaScript.
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode): An opinionated code formatter that supports many languages.
- [TypeScript Hero](https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero): Provides additional features for TypeScript development, such as import management and code navigation.
- [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer): Renders HTML files, useful for state transition HTML.
- [GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens): Supercharges the built-in Git capabilities of VS Code.

## Built With

[TypeScript](https://www.typescriptlang.org/)
[Chopsticks](https://github.com/AcalaNetwork/chopsticks)
[Polkadot API](https://github.com/polkadot-js/api)
21 changes: 13 additions & 8 deletions integration-tests/chopsticks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"author": "[\"KILT <info@kilt.io>\"]",
"license": "MIT",
"devDependencies": {
"@acala-network/chopsticks": "0.12.2",
"@acala-network/chopsticks-testing": "0.12.2",
"@polkadot/api": "^10.11.2",
"@acala-network/chopsticks": "1.0.1",
"@acala-network/chopsticks-testing": "1.0.1",
"@polkadot/api": "^14.3.1",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@vitest/ui": "2.1.8",
"eslint": "^8.0.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -24,17 +25,21 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"tsx": "^4.19.2",
"typescript": "*",
"vitest": "^1.4.0"
"vitest": "^2.1.8"
},
"scripts": {
"ts-check": "tsc --noEmit",
"lint": "eslint src && prettier --check src",
"lint:fix": "eslint --fix src && prettier --write src",
"clean": "rm -rf ./db",
"test": "LOG_LEVEL=error vitest",
"test:CI": "vitest --retry 3 --no-file-parallelism"
"test": "LOG_LEVEL=error vitest --config ./src/vitest.config.ts",
"ui": "vitest --ui --config ./src/vitest.config.ts",
"cli": "tsx ./src/cli.ts"
},
"dependencies": {
"commander": "^13.1.0",
"execa": "^9.5.2"
}
}
50 changes: 50 additions & 0 deletions integration-tests/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Command } from 'commander'

import { createTestNetwork, scheduleTxCommand, stateTransition } from './command/index.js'

const program = new Command()

program.name('chopsticks utils').description('CLI to mange some chopsticks instances').version('0.0.1')

program
.command('spinUp')
.description('Spin up the network')
.action(async () => {
await createTestNetwork()
})

program
.command('scheduleTx')
.description('Executes a transaction on the network')
.argument('<endpoint>', 'The endpoint of the network')
.argument('<rawTx>', 'The raw transaction to execute')
.option(
'--origin, <origin>',
'The origin of the transaction Either "Root" or "Signed""',
(value) => {
if (value !== 'Root' && value !== 'Signed') {
throw new Error('Invalid origin. Must be either "Root" or "Signed"')
}
return value
},
'Root'
)
.option('--port <port>', 'The RPC port', '8888')
.action(async (endpoint, rawTx, options) => {
const { origin, port } = options

await scheduleTxCommand(endpoint, rawTx, origin, +port)
})

program
.command('stateTransition')
.description('Shows the state transition of the network by the latest block')
.argument('<endpoint>', 'The endpoint of the network')
.option('--block', 'The block number to do the state transition', 'undefined')
.action(async (endpoint, options) => {
const { block } = options
const blockNumber = block === 'undefined' ? undefined : +block
await stateTransition(endpoint, blockNumber)
})

program.parse()
5 changes: 5 additions & 0 deletions integration-tests/chopsticks/src/command/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createTestNetwork } from './network.js'
import { scheduleTxCommand } from './scheduleTx.js'
import { stateTransition } from './stateTransition.js'

export { createTestNetwork, scheduleTxCommand, stateTransition }
24 changes: 24 additions & 0 deletions integration-tests/chopsticks/src/command/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mainChains } from '../network/index.js'
import { setStorage, setupNetwork } from '../network/utils.js'

export async function createTestNetwork() {
const relayConfig = mainChains.polkadot.getConfig({})

// 1. Create the network specific state
const kiltStorage = mainChains.kilt.storage.assignNativeTokensToAccounts([
'4pF5Y2Eo6doQHPLQj5AkndZwtomVB8ab2sRftRS2D9JDdELr',
])

// 2. Create the network specific config
const kiltConfig = mainChains.kilt.getConfig({})

// 2. Add the different parachainContexts here. The order of parachainContexts and parachainStorage should match.
const parachainOptions = [kiltConfig]
const parachainStorage = [kiltStorage]

const { relayChainContext, parachainContexts } = await setupNetwork(relayConfig, parachainOptions)

await Promise.all(parachainStorage.map((storage, index) => setStorage(parachainContexts[index], storage)))

await Promise.all([...parachainContexts, relayChainContext].map((context) => context.pause()))
}
Loading
Loading