Skip to content
Draft
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
78 changes: 78 additions & 0 deletions .github/workflows/e2e.yml
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
Comment on lines +16 to +78

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 19 days ago

The fix is to explicitly restrict the GITHUB_TOKEN permissions for this workflow to the minimum needed. The job only needs to read the repository contents (for actions/checkout@v4); it does not create releases, push commits, open issues, or modify PRs. Therefore, we can safely set contents: read either at the workflow root (applying to all jobs) or on the e2e-tests job itself. To keep the change minimal and clear, add a top-level permissions: block just after the on: block.

Concretely, in .github/workflows/e2e.yml, insert:

permissions:
  contents: read

between the on: section and the concurrency: 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.

Suggested changeset 1
.github/workflows/e2e.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -3,6 +3,9 @@
 on:
   workflow_dispatch:
 
+permissions:
+  contents: read
+
 concurrency:
   group: e2e-${{ github.ref }}
   cancel-in-progress: true
EOF
@@ -3,6 +3,9 @@
on:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: e2e-${{ github.ref }}
cancel-in-progress: true
Copilot is powered by AI and may make mistakes. Always verify output.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ scripts/specs/local.json

# Node modules
node_modules

.claude
3 changes: 3 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.papi
.env
2 changes: 2 additions & 0 deletions e2e/get-metadata.sh
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
6 changes: 6 additions & 0 deletions e2e/kill-nodes.sh
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
9 changes: 9 additions & 0 deletions e2e/package.json
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"
}
}
44 changes: 44 additions & 0 deletions e2e/shared/address.ts
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);
}
29 changes: 29 additions & 0 deletions e2e/shared/balance.ts
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");
}
30 changes: 30 additions & 0 deletions e2e/shared/client.ts
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;
}
7 changes: 7 additions & 0 deletions e2e/shared/index.ts
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";
7 changes: 7 additions & 0 deletions e2e/shared/logger.ts
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}`),
};
Loading
Loading