Skip to content

Commit 46bc3b9

Browse files
committed
Merge branch 'devnet-ready' into neuron-registration
2 parents 2f075d9 + ac6ec70 commit 46bc3b9

File tree

153 files changed

+15350
-10105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+15350
-10105
lines changed

.github/workflows/eco-tests.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: eco-tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
placeholder:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- run: echo "ok"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Scheduled Smoke Tests
2+
3+
on:
4+
schedule:
5+
- cron: '0 */6 * * *'
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
run-smoke-tests:
15+
runs-on: [self-hosted, type-ccx33]
16+
timeout-minutes: 30
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- test: smoke_mainnet
23+
- test: smoke_testnet
24+
25+
name: "smoke-e2e-${{ matrix.test }}"
26+
27+
steps:
28+
- name: Check-out repository
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version-file: ts-tests/.nvmrc
35+
36+
- name: Setup pnpm
37+
uses: pnpm/action-setup@v4
38+
with:
39+
version: 10
40+
41+
- name: Install e2e dependencies
42+
working-directory: ts-tests
43+
run: pnpm install --frozen-lockfile
44+
45+
- name: Run smoke test
46+
working-directory: ts-tests
47+
run: pnpm moonwall test ${{ matrix.test }}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1-
name: E2E Tests
1+
name: Typescript E2E Tests
22

33
on:
44
pull_request:
55

6-
workflow_dispatch:
7-
inputs:
8-
verbose:
9-
description: "Output more information when triggered manually"
10-
required: false
11-
default: ""
12-
136
env:
147
CARGO_TERM_COLOR: always
158

169
permissions:
1710
contents: read
1811

1912
jobs:
13+
typescript-formatting:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check-out repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
version: 10
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version-file: ts-tests/.nvmrc
28+
29+
- name: Install system dependencies
30+
run: |
31+
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update
32+
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends \
33+
-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
34+
build-essential clang curl git make libssl-dev llvm libudev-dev protobuf-compiler pkg-config
35+
36+
- name: Install e2e dependencies
37+
working-directory: ts-tests
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Formatting check
41+
run: |
42+
cd ts-tests
43+
pnpm run fmt
44+
2045
# Build the node binary in both variants and share as artifacts.
2146
build:
2247
runs-on: [self-hosted, type-ccx33]
48+
needs: [typescript-formatting]
2349
timeout-minutes: 60
2450
strategy:
2551
matrix:
@@ -62,87 +88,52 @@ jobs:
6288
path: target/release/node-subtensor
6389
if-no-files-found: error
6490

65-
# Discover e2e packages that have a "test" script.
66-
discover:
67-
runs-on: ubuntu-latest
68-
outputs:
69-
packages: ${{ steps.find.outputs.packages }}
70-
steps:
71-
- name: Check-out repository
72-
uses: actions/checkout@v4
73-
with:
74-
sparse-checkout: e2e
75-
76-
- name: Find testable packages
77-
id: find
78-
working-directory: e2e
79-
run: |
80-
packages=$(
81-
find . -maxdepth 2 -name package.json -not -path './node_modules/*' \
82-
| while read -r pkg; do
83-
name=$(jq -r '.name // empty' "$pkg")
84-
has_test=$(jq -r '.scripts.test // empty' "$pkg")
85-
if [ -n "$has_test" ] && [ -n "$name" ]; then
86-
echo "$name"
87-
fi
88-
done \
89-
| jq -R -s -c 'split("\n") | map(select(. != ""))'
90-
)
91-
echo "packages=$packages" >> "$GITHUB_OUTPUT"
92-
echo "Discovered packages: $packages"
93-
94-
# Run each e2e package's tests in parallel.
95-
test:
96-
needs: [build, discover]
97-
if: ${{ needs.discover.outputs.packages != '[]' }}
91+
run-e2e-tests:
92+
needs: [build]
9893
runs-on: [self-hosted, type-ccx33]
9994
timeout-minutes: 30
95+
10096
strategy:
10197
fail-fast: false
10298
matrix:
103-
package: ${{ fromJson(needs.discover.outputs.packages) }}
104-
name: "e2e: ${{ matrix.package }}"
99+
include:
100+
- test: dev
101+
binary: release
102+
- test: zombienet_shield
103+
binary: release
104+
- test: zombienet_staking
105+
binary: fast
106+
107+
name: "typescript-e2e-${{ matrix.test }}"
108+
105109
steps:
106110
- name: Check-out repository
107111
uses: actions/checkout@v4
108112

109-
- name: Download release binary
113+
- name: Download binary
110114
uses: actions/download-artifact@v4
111115
with:
112-
name: node-subtensor-release
116+
name: node-subtensor-${{ matrix.binary }}
113117
path: target/release
114118

115-
- name: Download fast binary
116-
uses: actions/download-artifact@v4
117-
with:
118-
name: node-subtensor-fast
119-
path: target/fast
120-
121-
- name: Make binaries executable
122-
run: chmod +x target/release/node-subtensor target/fast/node-subtensor
119+
- name: Make binary executable
120+
run: chmod +x target/release/node-subtensor
123121

124122
- name: Setup Node.js
125123
uses: actions/setup-node@v4
126124
with:
127-
node-version-file: e2e/.nvmrc
125+
node-version-file: ts-tests/.nvmrc
128126

129127
- name: Setup pnpm
130128
uses: pnpm/action-setup@v4
131129
with:
132130
version: 10
133131

134-
- name: Bootstrap papi types
135-
working-directory: e2e
136-
run: ./bootstrap_types.sh --skip-build
137-
138132
- name: Install e2e dependencies
139-
working-directory: e2e
133+
working-directory: ts-tests
140134
run: pnpm install --frozen-lockfile
141135

142136
- name: Run tests
143-
working-directory: e2e
144-
env:
145-
# Use fast-runtime binary for staking package, release binary for others
146-
# Path is relative to package directory (e2e/<package>/)
147-
BINARY_PATH: ${{ matrix.package == 'e2e-staking' && '../../target/fast/node-subtensor' || '../../target/release/node-subtensor' }}
148-
run: pnpm --filter ${{ matrix.package }} test
137+
run: |
138+
cd ts-tests
139+
pnpm moonwall test ${{ matrix.test }}

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ by appending your own. A few useful ones are as follow.
337337
```
338338
-->
339339

340+
## Testing
341+
342+
Check [testing section](./docs/testing.md).
343+
340344
## License
341345
The MIT License (MIT)
342346
Copyright © 2021 Yuma Rao
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Drand precompile address: 0x80e = 2062
2+
export const IDRAND_ADDRESS = "0x000000000000000000000000000000000000080e";
3+
4+
export const IDrandABI = [
5+
{
6+
inputs: [
7+
{
8+
internalType: "uint64",
9+
name: "round",
10+
type: "uint64",
11+
},
12+
],
13+
name: "getRandomness",
14+
outputs: [
15+
{
16+
internalType: "bytes32",
17+
name: "",
18+
type: "bytes32",
19+
},
20+
],
21+
stateMutability: "view",
22+
type: "function",
23+
},
24+
{
25+
inputs: [],
26+
name: "getLastStoredRound",
27+
outputs: [
28+
{
29+
internalType: "uint64",
30+
name: "",
31+
type: "uint64",
32+
},
33+
],
34+
stateMutability: "view",
35+
type: "function",
36+
},
37+
] as const;

contract-tests/src/subtensor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,22 @@ export async function setNetworkLastLockCost(api: TypedApi<typeof devnet>, defau
419419

420420
const valueOnChain = await api.query.SubtensorModule.NetworkLastLockCost.getValue()
421421
assert.equal(defaultNetworkLastLockCost, valueOnChain)
422+
}
423+
424+
425+
export async function getStake(api: TypedApi<typeof devnet>, hotkey: string, coldkey: string, netuid: number): Promise<bigint> {
426+
const value = (await api.query.SubtensorModule.AlphaV2.getValue(hotkey, coldkey, netuid));
427+
428+
const mantissa = value.mantissa;
429+
const exponent = value.exponent;
430+
431+
let result: bigint;
432+
433+
if (exponent >= 0) {
434+
result = mantissa * BigInt(10) ** exponent;
435+
} else {
436+
result = mantissa / BigInt(10) ** -exponent;
437+
}
438+
439+
return result;
422440
}

contract-tests/test/alphaPool.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PublicClient } from "viem";
99
import { TypedApi } from "polkadot-api";
1010
import { ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE } from "../src/contracts/alphaPool";
1111
import { convertH160ToPublicKey, convertH160ToSS58, convertPublicKeyToSs58, toViemAddress } from "../src/address-utils";
12-
import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister } from "../src/subtensor";
12+
import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister, getStake } from "../src/subtensor";
1313
import { ethers } from "ethers"
1414
import { tao } from "../src/balance-math";
1515
import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking";
@@ -46,7 +46,7 @@ describe("bridge token contract deployment", () => {
4646
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
4747
// the unit in V2 is RAO, not ETH
4848
let stakeBalance = tao(20)
49-
const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
49+
const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
5050
const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet);
5151
const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid)
5252
await tx.wait()
@@ -56,7 +56,7 @@ describe("bridge token contract deployment", () => {
5656
);
5757

5858
assert.ok(stakeFromContract > stakeBefore)
59-
const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
59+
const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
6060
assert.ok(stakeAfter > stakeBefore)
6161
assert.ok(stakeFromContract > tao(20))
6262
})
@@ -66,7 +66,7 @@ describe("bridge token contract deployment", () => {
6666
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
6767
const stakingPrecompile = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet);
6868

69-
const stakeBeforeDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
69+
const stakeBeforeDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
7070

7171
const contractFactory = new ethers.ContractFactory(ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE, wallet)
7272
const contract = await contractFactory.deploy(hotkey.publicKey)
@@ -103,11 +103,11 @@ describe("bridge token contract deployment", () => {
103103
await depositAlphaTx.wait()
104104

105105
// compare wallet stake
106-
const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
106+
const stakeAftereDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
107107
assert.ok(stakeAftereDeposit < stakeBeforeDeposit)
108108

109109
// check the contract stake
110-
const ContractStake = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid)
110+
const ContractStake = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid)
111111
assert.ok(ContractStake > 0)
112112

113113
// check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call

0 commit comments

Comments
 (0)