-
Notifications
You must be signed in to change notification settings - Fork 288
E2E workflow example #2446
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
Draft
shamil-gadelshin
wants to merge
20
commits into
devnet-ready
Choose a base branch
from
e2e-lib
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
E2E workflow example #2446
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0cf1838
.gitignore
shamil-gadelshin 8684401
Add kill-nodes script
shamil-gadelshin be4e244
Add metadata
shamil-gadelshin dd7c6c4
Add shared package
shamil-gadelshin 7001402
Add start-nodes package
shamil-gadelshin 866ec36
Add staking-tests package
shamil-gadelshin 229fe36
E2E workflow
shamil-gadelshin 5544301
Add stake limit test
shamil-gadelshin 08b994d
Refactor params
shamil-gadelshin b495876
Refactor add_stake_* tests
shamil-gadelshin af7b9bf
Add remove_stake_* tests
shamil-gadelshin 10bcff2
Add unstake_all test.
shamil-gadelshin 43f2998
Add transfer_stake tests
shamil-gadelshin b7e0972
Add move-stake tests
shamil-gadelshin 03b74db
Add remove_stake_full_limit stake
shamil-gadelshin 18ba4a9
Add swap_stake tests.
shamil-gadelshin 13248f0
Add swap_stake_limit tests.
shamil-gadelshin cec5b28
Add unstake_all_alpha tests.
shamil-gadelshin a648c85
Add root claim type tests
shamil-gadelshin e4be0ac
More root claim test.
shamil-gadelshin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| name: E2E Tests | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: e2e-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
| RUST_BACKTRACE: full | ||
|
|
||
| jobs: | ||
| e2e-tests: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install system dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| protobuf-compiler \ | ||
| libprotobuf-dev \ | ||
| libclang-dev \ | ||
| clang \ | ||
| cmake \ | ||
| build-essential | ||
|
|
||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| components: rustfmt, clippy | ||
|
|
||
| - name: Build node with release, fast-runtime, and metadata-hash | ||
| run: | | ||
| cargo build \ | ||
| --profile release \ | ||
| --features "fast-runtime metadata-hash pow-faucet" \ | ||
| -p node-subtensor | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "24" | ||
|
|
||
| - name: Install start-nodes dependencies | ||
| working-directory: e2e/start-nodes | ||
| run: npm install | ||
|
|
||
| - name: Start validator nodes | ||
| working-directory: e2e/start-nodes | ||
| run: npx tsx main.ts | ||
|
|
||
| - name: Install polkadot-api for papi CLI | ||
| working-directory: e2e | ||
| run: npm install | ||
|
|
||
| - name: Generate PAPI descriptors from running node | ||
| working-directory: e2e | ||
| run: | | ||
| rm -rf .papi | ||
| npx papi add devnet -w ws://localhost:9944 | ||
|
|
||
| - name: Install shared dependencies | ||
| working-directory: e2e/shared | ||
| run: npm install | ||
|
|
||
| - name: Install staking-tests dependencies | ||
| working-directory: e2e/staking-tests | ||
| run: npm install | ||
|
|
||
| - name: Run staking tests | ||
| working-directory: e2e/staking-tests | ||
| run: npm test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,3 +50,5 @@ scripts/specs/local.json | |
|
|
||
| # Node modules | ||
| node_modules | ||
|
|
||
| .claude | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules | ||
| .papi | ||
| .env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| rm -rf .papi | ||
| npx papi add devnet -w ws://localhost:9944 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/bash | ||
|
|
||
| pkill -9 -f node-subtensor | ||
|
|
||
| rm -r /tmp/one | ||
| rm -r /tmp/two |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "e2e", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "dependencies": { | ||
| "polkadot-api": "^1.22.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; | ||
| import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy, KeyPair } from "@polkadot-labs/hdkd-helpers"; | ||
| import { getPolkadotSigner } from "polkadot-api/signer"; | ||
| import { PolkadotSigner } from "polkadot-api"; | ||
| import { randomBytes } from "crypto"; | ||
| import { ss58Address } from "@polkadot-labs/hdkd-helpers"; | ||
|
|
||
| export const SS58_PREFIX = 42; | ||
|
|
||
| // ─── KEYPAIR UTILITIES ─────────────────────────────────────────────────────── | ||
|
|
||
| export function getKeypairFromPath(path: string): KeyPair { | ||
| const entropy = mnemonicToEntropy(DEV_PHRASE); | ||
| const miniSecret = entropyToMiniSecret(entropy); | ||
| const derive = sr25519CreateDerive(miniSecret); | ||
| return derive(path); | ||
| } | ||
|
|
||
| export const getAlice = () => getKeypairFromPath("//Alice"); | ||
|
|
||
| export function getRandomSubstrateKeypair(): KeyPair { | ||
| const seed = randomBytes(32); | ||
| const miniSecret = entropyToMiniSecret(seed); | ||
| const derive = sr25519CreateDerive(miniSecret); | ||
| return derive(""); | ||
| } | ||
|
|
||
| // ─── SIGNER UTILITIES ──────────────────────────────────────────────────────── | ||
|
|
||
| export function getSignerFromKeypair(keypair: KeyPair): PolkadotSigner { | ||
| return getPolkadotSigner(keypair.publicKey, "Sr25519", keypair.sign); | ||
| } | ||
|
|
||
| export function getSignerFromPath(path: string): PolkadotSigner { | ||
| return getSignerFromKeypair(getKeypairFromPath(path)); | ||
| } | ||
|
|
||
| export const getAliceSigner = () => getSignerFromPath("//Alice"); | ||
|
|
||
| // ─── ADDRESS UTILITIES ─────────────────────────────────────────────────────── | ||
|
|
||
| export function convertPublicKeyToSs58(publicKey: Uint8Array): string { | ||
| return ss58Address(publicKey, SS58_PREFIX); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { devnet, MultiAddress } from "@polkadot-api/descriptors"; | ||
| import { TypedApi } from "polkadot-api"; | ||
| import { getAliceSigner } from "./address.js"; | ||
| import { waitForTransactionWithRetry } from "./transactions.js"; | ||
|
|
||
| export const TAO = BigInt(1000000000); // 10^9 RAO per TAO | ||
|
|
||
| export function tao(value: number): bigint { | ||
| return TAO * BigInt(value); | ||
| } | ||
|
|
||
| export async function getBalance(api: TypedApi<typeof devnet>, ss58Address: string): Promise<bigint> { | ||
| const account = await api.query.System.Account.getValue(ss58Address); | ||
| return account.data.free; | ||
| } | ||
|
|
||
| export async function forceSetBalance( | ||
| api: TypedApi<typeof devnet>, | ||
| ss58Address: string, | ||
| amount: bigint = tao(1e10) | ||
| ): Promise<void> { | ||
| const alice = getAliceSigner(); | ||
| const internalCall = api.tx.Balances.force_set_balance({ | ||
| who: MultiAddress.Id(ss58Address), | ||
| new_free: amount, | ||
| }); | ||
| const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall }); | ||
| await waitForTransactionWithRetry(api, tx, alice, "force_set_balance"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { devnet } from "@polkadot-api/descriptors"; | ||
| import { TypedApi, PolkadotClient, createClient } from "polkadot-api"; | ||
| import { getWsProvider } from "polkadot-api/ws-provider/web"; | ||
|
|
||
| export const SUB_LOCAL_URL = "ws://localhost:9944"; | ||
|
|
||
| let client: PolkadotClient | undefined = undefined; | ||
| let api: TypedApi<typeof devnet> | undefined = undefined; | ||
|
|
||
| export async function getClient(): Promise<PolkadotClient> { | ||
| if (client === undefined) { | ||
| const provider = getWsProvider(SUB_LOCAL_URL); | ||
| client = createClient(provider); | ||
| } | ||
| return client; | ||
| } | ||
|
|
||
| export async function getDevnetApi(): Promise<TypedApi<typeof devnet>> { | ||
| if (api === undefined) { | ||
| const c = await getClient(); | ||
| api = c.getTypedApi(devnet); | ||
| } | ||
| return api; | ||
| } | ||
|
|
||
| export function destroyClient(): void { | ||
| client?.destroy(); | ||
| client = undefined; | ||
| api = undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export * from "./logger.js"; | ||
| export * from "./client.js"; | ||
| export * from "./address.js"; | ||
| export * from "./transactions.js"; | ||
| export * from "./balance.js"; | ||
| export * from "./subnet.js"; | ||
| export * from "./staking.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const LOG_INDENT = " "; | ||
|
|
||
| export const log = { | ||
| tx: (label: string, msg: string) => console.log(`${LOG_INDENT}[${label}] ${msg}`), | ||
| info: (msg: string) => console.log(`${LOG_INDENT}${msg}`), | ||
| error: (label: string, msg: string) => console.error(`${LOG_INDENT}[${label}] ${msg}`), | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 19 days ago
The fix is to explicitly restrict the
GITHUB_TOKENpermissions for this workflow to the minimum needed. The job only needs to read the repository contents (foractions/checkout@v4); it does not create releases, push commits, open issues, or modify PRs. Therefore, we can safely setcontents: readeither at the workflow root (applying to all jobs) or on thee2e-testsjob itself. To keep the change minimal and clear, add a top-levelpermissions:block just after theon:block.Concretely, in
.github/workflows/e2e.yml, insert:between the
on:section and theconcurrency:section (after line 5, before line 6 in the provided snippet). No additional imports or methods are needed, as this is purely a YAML configuration change.