From 20f4b3b51a1825aa7115dd488e5fe4074c2bc2c6 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 08:55:34 +0800 Subject: [PATCH 01/22] try single node test --- contract-tests/run-ci.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/contract-tests/run-ci.sh b/contract-tests/run-ci.sh index 0ea0e72297..ac8aade21b 100755 --- a/contract-tests/run-ci.sh +++ b/contract-tests/run-ci.sh @@ -2,6 +2,8 @@ echo "start run-ci.sh" +cargo build --release -p node-subtensor --features fast-runtime + cd contract-tests cd bittensor @@ -12,10 +14,12 @@ cargo contract build --release cd ../.. -scripts/localnet.sh &>/dev/null & +# scripts/localnet.sh &>/dev/null & + +target/release/node-subtensor --dev --tmp &>/dev/null & i=1 -while [ $i -le 2000 ]; do +while [ $i -le 100 ]; do if nc -z localhost 9944; then echo "node subtensor is running after $i seconds" break @@ -25,7 +29,7 @@ while [ $i -le 2000 ]; do done # port not available exit with error -if [ "$i" -eq 2000 ]; then +if [ "$i" -eq 100 ]; then exit 1 fi From a0b3ed2e918b8eade135e46eccba568b10fe4b66 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 09:15:25 +0800 Subject: [PATCH 02/22] run node with one account --- contract-tests/run-ci.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contract-tests/run-ci.sh b/contract-tests/run-ci.sh index ac8aade21b..662ab21cb5 100755 --- a/contract-tests/run-ci.sh +++ b/contract-tests/run-ci.sh @@ -16,7 +16,7 @@ cd ../.. # scripts/localnet.sh &>/dev/null & -target/release/node-subtensor --dev --tmp &>/dev/null & +target/release/node-subtensor --dev --tmp --one &>/dev/null & i=1 while [ $i -le 100 ]; do @@ -33,7 +33,7 @@ if [ "$i" -eq 100 ]; then exit 1 fi -sleep 10 +sleep 2 if ! nc -z localhost 9944; then echo "node subtensor exit, port not available" From 9b1d8286760ca4b75c8e86c91196c3c51f99648c Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 10:30:04 +0800 Subject: [PATCH 03/22] print log --- contract-tests/run-ci.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/contract-tests/run-ci.sh b/contract-tests/run-ci.sh index 662ab21cb5..cdd43e2c29 100755 --- a/contract-tests/run-ci.sh +++ b/contract-tests/run-ci.sh @@ -2,8 +2,6 @@ echo "start run-ci.sh" -cargo build --release -p node-subtensor --features fast-runtime - cd contract-tests cd bittensor @@ -14,12 +12,10 @@ cargo contract build --release cd ../.. -# scripts/localnet.sh &>/dev/null & - -target/release/node-subtensor --dev --tmp --one &>/dev/null & +scripts/localnet.sh & i=1 -while [ $i -le 100 ]; do +while [ $i -le 2000 ]; do if nc -z localhost 9944; then echo "node subtensor is running after $i seconds" break @@ -29,11 +25,11 @@ while [ $i -le 100 ]; do done # port not available exit with error -if [ "$i" -eq 100 ]; then +if [ "$i" -eq 2000 ]; then exit 1 fi -sleep 2 +sleep 10 if ! nc -z localhost 9944; then echo "node subtensor exit, port not available" From 9734e482087952636bac9a092aaacc973432058b Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 17:25:28 +0800 Subject: [PATCH 04/22] send output to null --- contract-tests/run-ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract-tests/run-ci.sh b/contract-tests/run-ci.sh index cdd43e2c29..0ea0e72297 100755 --- a/contract-tests/run-ci.sh +++ b/contract-tests/run-ci.sh @@ -12,7 +12,7 @@ cargo contract build --release cd ../.. -scripts/localnet.sh & +scripts/localnet.sh &>/dev/null & i=1 while [ $i -le 2000 ]; do From 9ea69a29e791401451455ebed48f5dc7c7eb76e5 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 19:37:40 +0800 Subject: [PATCH 05/22] use single node for testing --- .github/workflows/contract-tests.yml | 5 ++++- contract-tests/run-ci.sh | 20 +++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index 2e74e408b3..d1a82f0caf 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -48,7 +48,10 @@ jobs: run: | sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" build-essential clang curl libssl-dev llvm libudev-dev protobuf-compiler nodejs pkg-config - + sudo rustup component add rust-src + sudo cargo install cargo-contract + sudo cargo build --release -p node-subtensor --features fast-runtime + sudo cd contract-tests/bittensor - name: Run tests uses: nick-fields/retry@v3 with: diff --git a/contract-tests/run-ci.sh b/contract-tests/run-ci.sh index 0ea0e72297..935f39ff23 100755 --- a/contract-tests/run-ci.sh +++ b/contract-tests/run-ci.sh @@ -2,20 +2,10 @@ echo "start run-ci.sh" -cd contract-tests - -cd bittensor - -rustup component add rust-src -cargo install cargo-contract -cargo contract build --release - -cd ../.. - -scripts/localnet.sh &>/dev/null & +target/release/node-subtensor --dev --tmp --one &>/dev/null & i=1 -while [ $i -le 2000 ]; do +while [ $i -le 60 ]; do if nc -z localhost 9944; then echo "node subtensor is running after $i seconds" break @@ -25,11 +15,11 @@ while [ $i -le 2000 ]; do done # port not available exit with error -if [ "$i" -eq 2000 ]; then +if [ "$i" -eq 60 ]; then exit 1 fi -sleep 10 +sleep 2 if ! nc -z localhost 9944; then echo "node subtensor exit, port not available" @@ -43,7 +33,7 @@ npm i -g polkadot-api bash get-metadata.sh -sleep 5 +sleep 2 yarn install --frozen-lockfile From d7b81826315c9535b740e55e1f6553855bb35e4c Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 19:44:02 +0800 Subject: [PATCH 06/22] try rustup --- .github/workflows/contract-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index d1a82f0caf..ae26ef32ee 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -48,7 +48,7 @@ jobs: run: | sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" build-essential clang curl libssl-dev llvm libudev-dev protobuf-compiler nodejs pkg-config - sudo rustup component add rust-src + rustup component add rust-src sudo cargo install cargo-contract sudo cargo build --release -p node-subtensor --features fast-runtime sudo cd contract-tests/bittensor From c6c5cc5da9c94122d9323d6e122879bf98218ddd Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 19:46:30 +0800 Subject: [PATCH 07/22] try rustup --- .github/workflows/contract-tests.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index ae26ef32ee..4edba6a4db 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -48,10 +48,12 @@ jobs: run: | sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" build-essential clang curl libssl-dev llvm libudev-dev protobuf-compiler nodejs pkg-config + cd ${{ github.workspace }} rustup component add rust-src - sudo cargo install cargo-contract - sudo cargo build --release -p node-subtensor --features fast-runtime - sudo cd contract-tests/bittensor + cargo install cargo-contract + cargo build --release -p node-subtensor --features fast-runtime + cd contract-tests/bittensor + cargo contract build --release - name: Run tests uses: nick-fields/retry@v3 with: From e03ab9bd08975ba33d9c39c5482dee628cd71d6f Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Dec 2025 22:53:44 +0800 Subject: [PATCH 08/22] fix one failed test --- contract-tests/test/staking.precompile.wrap.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contract-tests/test/staking.precompile.wrap.test.ts b/contract-tests/test/staking.precompile.wrap.test.ts index e4d666adf1..7e4b21ed16 100644 --- a/contract-tests/test/staking.precompile.wrap.test.ts +++ b/contract-tests/test/staking.precompile.wrap.test.ts @@ -20,6 +20,7 @@ import { ethers } from "ethers"; import { generateRandomEthersWallet } from "../src/utils"; import { abi, bytecode } from "../src/contracts/stakeWrap"; +import { setMaxIdleHTTPParsers } from "http"; describe("Test staking precompile add from deployed contract", () => { const hotkey = getRandomSubstrateKeypair(); @@ -62,6 +63,8 @@ describe("Test staking precompile add from deployed contract", () => { const txResponse = await wallet1.sendTransaction(ethTransfer) await txResponse.wait(); + console.log("stakeWrap contract deployed, target: ", contract.target.toString()); + const deployedContract = new ethers.Contract( contract.target.toString(), abi, @@ -75,6 +78,8 @@ describe("Test staking precompile add from deployed contract", () => { ); await tx.wait(); + await new Promise(resolve => setTimeout(resolve, 1000)); + const tx2 = await deployedContract.removeStake( hotkey.publicKey, netuid, From ab6cedd26cb8cccbea4addeeb6eb86ff40b05aa9 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sat, 13 Dec 2025 19:03:00 +0800 Subject: [PATCH 09/22] name binary build --- .github/workflows/contract-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index 4edba6a4db..ecc0a70b20 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -48,12 +48,16 @@ jobs: run: | sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" build-essential clang curl libssl-dev llvm libudev-dev protobuf-compiler nodejs pkg-config + + - name: Build node-subtensor and Ink contracts + run: | cd ${{ github.workspace }} rustup component add rust-src cargo install cargo-contract cargo build --release -p node-subtensor --features fast-runtime cd contract-tests/bittensor cargo contract build --release + - name: Run tests uses: nick-fields/retry@v3 with: From d93eac94ec9efbb228602e1f57bff411aec22f31 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sat, 13 Dec 2025 21:40:48 +0800 Subject: [PATCH 10/22] try more times --- .github/workflows/contract-tests.yml | 2 +- contract-tests/src/substrate.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index ecc0a70b20..827d735419 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -62,7 +62,7 @@ jobs: uses: nick-fields/retry@v3 with: timeout_minutes: 90 - max_attempts: 3 + max_attempts: 5 retry_wait_seconds: 60 command: | cd ${{ github.workspace }} diff --git a/contract-tests/src/substrate.ts b/contract-tests/src/substrate.ts index c7c9efe3d9..3e4d9698fb 100644 --- a/contract-tests/src/substrate.ts +++ b/contract-tests/src/substrate.ts @@ -180,7 +180,6 @@ export async function getTransactionWatchPromise(tx: Transaction<{}, string, str // TODO investigate why finalized not for each extrinsic if (value.type === "finalized") { - console.log("Transaction is finalized in block:", value.txHash); subscription.unsubscribe(); clearTimeout(timeoutId); if (!value.ok) { From 4a042be82bfe7cdacce37910497caf22e909f9d8 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 18:35:17 +0800 Subject: [PATCH 11/22] avoid register network failure --- contract-tests/src/subtensor.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/contract-tests/src/subtensor.ts b/contract-tests/src/subtensor.ts index 12d652a9a3..58e29c2fdf 100644 --- a/contract-tests/src/subtensor.ts +++ b/contract-tests/src/subtensor.ts @@ -1,14 +1,15 @@ import * as assert from "assert"; import { devnet, MultiAddress } from '@polkadot-api/descriptors'; -import { TypedApi, TxCallData, Binary, Enum } from 'polkadot-api'; +import { TypedApi, TxCallData, Binary, Enum, getTypedCodecs } from 'polkadot-api'; import { KeyPair } from "@polkadot-labs/hdkd-helpers" import { getAliceSigner, waitForTransactionCompletion, getSignerFromKeypair, waitForTransactionWithRetry } from './substrate' import { convertH160ToSS58, convertPublicKeyToSs58, ethAddressToH160 } from './address-utils' import { tao } from './balance-math' -import internal from "stream"; // create a new subnet and return netuid export async function addNewSubnetwork(api: TypedApi, hotkey: KeyPair, coldkey: KeyPair) { + + const alice = getAliceSigner() const totalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue() @@ -26,6 +27,9 @@ export async function addNewSubnetwork(api: TypedApi, hotkey: Key const newTotalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue() // could create multiple subnetworks during retry, just return the first created one assert.ok(newTotalNetworks > totalNetworks) + + await resetNetworkLastLock(api) + return totalNetworks } @@ -398,4 +402,21 @@ export async function sendWasmContractExtrinsic(api: TypedApi, co storage_deposit_limit: BigInt(1000000000) }) await waitForTransactionWithRetry(api, tx, signer) -} \ No newline at end of file +} + +export async function resetNetworkLastLock(api: TypedApi) { + const alice = getAliceSigner() + const key = await api.query.SubtensorModule.NetworkLastLockCost.getKey() + + // Get the codec for NetworkLastLockCost value (TaoCurrency/u128) + const codec = await getTypedCodecs(devnet) + const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value + + // Encode the value (0) as SCALE-encoded bytes + const encodedValue = valueCodec.enc(BigInt(0)) + + const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]]; + const internalCall = api.tx.System.set_storage({ items: changes }) + const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall }) + await waitForTransactionWithRetry(api, tx, alice) +} \ No newline at end of file From e542f1520af6d02e2efc98cacfbef774cfc6ce2f Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 18:36:06 +0800 Subject: [PATCH 12/22] update test description --- contract-tests/test/alphaPool.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract-tests/test/alphaPool.test.ts b/contract-tests/test/alphaPool.test.ts index 361e1213bb..d6aefc4bcc 100644 --- a/contract-tests/test/alphaPool.test.ts +++ b/contract-tests/test/alphaPool.test.ts @@ -14,7 +14,7 @@ import { ethers } from "ethers" import { tao } from "../src/balance-math"; import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking"; // import { KeyPair } from "@polkadot-labs/hdkd-helpers"; -describe("bridge token contract deployment", () => { +describe("Alpha Pool Test", () => { // init eth part const wallet = generateRandomEthersWallet(); let publicClient: PublicClient; From 0f06072a387d9fc1ff062556d22e4a1d9ead8811 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 19:25:34 +0800 Subject: [PATCH 13/22] set network register cose as 1 TAO --- contract-tests/src/subtensor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contract-tests/src/subtensor.ts b/contract-tests/src/subtensor.ts index 58e29c2fdf..cb0d318357 100644 --- a/contract-tests/src/subtensor.ts +++ b/contract-tests/src/subtensor.ts @@ -412,8 +412,8 @@ export async function resetNetworkLastLock(api: TypedApi) { const codec = await getTypedCodecs(devnet) const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value - // Encode the value (0) as SCALE-encoded bytes - const encodedValue = valueCodec.enc(BigInt(0)) + // Encode the value 1 TAO as SCALE-encoded bytes + const encodedValue = valueCodec.enc(BigInt(10000000000)) const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]]; const internalCall = api.tx.System.set_storage({ items: changes }) From d9809d651216f5e550cb34feb410201ec8ee81d8 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 20:50:18 +0800 Subject: [PATCH 14/22] update crowdloanCap --- contract-tests/test/leasing.precompile.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract-tests/test/leasing.precompile.test.ts b/contract-tests/test/leasing.precompile.test.ts index 7ea45c0509..64476e8695 100644 --- a/contract-tests/test/leasing.precompile.test.ts +++ b/contract-tests/test/leasing.precompile.test.ts @@ -45,7 +45,7 @@ describe("Test Leasing precompile", () => { it("gets an existing lease created on substrate side, its subnet id and its contributor shares", async () => { const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(2); + const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leaseEmissionsShare = 15; const leaseEnd = await api.query.System.Number.getValue() + 300; From 87beaec8447b94b928e24463e3430707ff97e9fd Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 20:50:56 +0800 Subject: [PATCH 15/22] update crowdloanCap --- contract-tests/test/leasing.precompile.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contract-tests/test/leasing.precompile.test.ts b/contract-tests/test/leasing.precompile.test.ts index 64476e8695..4641e270f8 100644 --- a/contract-tests/test/leasing.precompile.test.ts +++ b/contract-tests/test/leasing.precompile.test.ts @@ -100,7 +100,7 @@ describe("Test Leasing precompile", () => { const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(2); + const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leasingEmissionsShare = 15; const leasingEndBlock = await api.query.System.Number.getValue() + 300; @@ -161,7 +161,7 @@ describe("Test Leasing precompile", () => { const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(2); + const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leasingEmissionsShare = 15; const leasingEndBlock = await api.query.System.Number.getValue() + 200; From c38746cbccb4efc87a0b211ee95cc8bb089152b1 Mon Sep 17 00:00:00 2001 From: open-junius Date: Sun, 14 Dec 2025 20:52:08 +0800 Subject: [PATCH 16/22] update crowdloanCap --- contract-tests/test/leasing.precompile.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contract-tests/test/leasing.precompile.test.ts b/contract-tests/test/leasing.precompile.test.ts index 4641e270f8..bd766c1873 100644 --- a/contract-tests/test/leasing.precompile.test.ts +++ b/contract-tests/test/leasing.precompile.test.ts @@ -7,7 +7,7 @@ import { ethers } from "ethers"; import { TypedApi } from "polkadot-api"; import { devnet } from "@polkadot-api/descriptors"; import { getAliceSigner, getBobSigner, getDevnetApi, waitForFinalizedBlock } from "../src/substrate"; -import { forceSetBalanceToEthAddress } from "../src/subtensor"; +import { forceSetBalanceToEthAddress, resetNetworkLastLock } from "../src/subtensor"; import { decodeAddress } from "@polkadot/util-crypto"; import { u8aToHex } from "@polkadot/util"; import { ILEASING_ADDRESS, ILeasingABI } from "../src/contracts/leasing"; @@ -40,6 +40,8 @@ describe("Test Leasing precompile", () => { await forceSetBalanceToEthAddress(api, wallet1.address); await forceSetBalanceToEthAddress(api, wallet2.address); + + await resetNetworkLastLock(api); }); it("gets an existing lease created on substrate side, its subnet id and its contributor shares", async () => { From 6e915dd640ee50e6e0d0194db25f901801caf9aa Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 15 Dec 2025 11:22:14 +0800 Subject: [PATCH 17/22] fix test --- contract-tests/src/subtensor.ts | 2 +- contract-tests/test/leasing.precompile.test.ts | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/contract-tests/src/subtensor.ts b/contract-tests/src/subtensor.ts index cb0d318357..42825501a6 100644 --- a/contract-tests/src/subtensor.ts +++ b/contract-tests/src/subtensor.ts @@ -413,7 +413,7 @@ export async function resetNetworkLastLock(api: TypedApi) { const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value // Encode the value 1 TAO as SCALE-encoded bytes - const encodedValue = valueCodec.enc(BigInt(10000000000)) + const encodedValue = valueCodec.enc(BigInt(0)) const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]]; const internalCall = api.tx.System.set_storage({ items: changes }) diff --git a/contract-tests/test/leasing.precompile.test.ts b/contract-tests/test/leasing.precompile.test.ts index bd766c1873..895a7ef84a 100644 --- a/contract-tests/test/leasing.precompile.test.ts +++ b/contract-tests/test/leasing.precompile.test.ts @@ -24,6 +24,8 @@ describe("Test Leasing precompile", () => { let leaseContract: ethers.Contract; let crowdloanContract: ethers.Contract; let neuronContract: ethers.Contract; + const crowdloanDeposit = BigInt(100_000_000_000); + let crowdloanCap: bigint; const alice = getAliceSigner(); const bob = getBobSigner(); @@ -42,12 +44,17 @@ describe("Test Leasing precompile", () => { await forceSetBalanceToEthAddress(api, wallet2.address); await resetNetworkLastLock(api); + const minLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue(); + // guarantee that the crowdloan cap is larger than the deposit + if (minLockCost > crowdloanDeposit) { + crowdloanCap = minLockCost * BigInt(2); + } else { + crowdloanCap = crowdloanDeposit * BigInt(2); + } }); it("gets an existing lease created on substrate side, its subnet id and its contributor shares", async () => { const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); - const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leaseEmissionsShare = 15; const leaseEnd = await api.query.System.Number.getValue() + 300; @@ -69,8 +76,8 @@ describe("Test Leasing precompile", () => { amount: crowdloanCap - crowdloanDeposit, }).signAndSubmit(bob); - await waitForFinalizedBlock(api, crowdloanEnd); + await waitForFinalizedBlock(api, crowdloanEnd); const nextLeaseId = await api.query.SubtensorModule.NextSubnetLeaseId.getValue(); await api.tx.Crowdloan.finalize({ crowdloan_id: nextCrowdloanId }).signAndSubmit(alice); @@ -100,9 +107,7 @@ describe("Test Leasing precompile", () => { it("registers a new leased network through a crowdloan and retrieves the lease", async () => { const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); - const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leasingEmissionsShare = 15; const leasingEndBlock = await api.query.System.Number.getValue() + 300; @@ -161,9 +166,7 @@ describe("Test Leasing precompile", () => { await tx.wait(); const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue(); - const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO - const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10); const crowdloanEnd = await api.query.System.Number.getValue() + 100; const leasingEmissionsShare = 15; const leasingEndBlock = await api.query.System.Number.getValue() + 200; From ef17253d57a5eef9f378462696828dbd0731d713 Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 15 Dec 2025 18:56:32 +0800 Subject: [PATCH 18/22] avoid too fast transaction submit --- contract-tests/test/staking.precompile.full-limit.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contract-tests/test/staking.precompile.full-limit.test.ts b/contract-tests/test/staking.precompile.full-limit.test.ts index 156fd38f25..24c5507a88 100644 --- a/contract-tests/test/staking.precompile.full-limit.test.ts +++ b/contract-tests/test/staking.precompile.full-limit.test.ts @@ -62,7 +62,7 @@ describe("Test staking precompile add remove limit methods", () => { IStakingV2ABI, wallet1, ); - + await new Promise(resolve => setTimeout(resolve, 1000)); const tx = await contract.addStakeLimit( hotkey.publicKey, tao(2000), @@ -131,7 +131,7 @@ describe("Test staking precompile add remove limit methods", () => { IStakingV2ABI, wallet2, ); - + await new Promise(resolve => setTimeout(resolve, 1000)); const tx = await contract.addStakeLimit( hotkey.publicKey, tao(2000), @@ -165,7 +165,7 @@ describe("Test staking precompile add remove limit methods", () => { IStakingV2ABI, wallet2, ); - + await new Promise(resolve => setTimeout(resolve, 1000)); const tx = await contract.removeStakeFull( hotkey.publicKey, netuid, From 26c9ba042ffc9d43ca4ce65644e55df4de795801 Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 15 Dec 2025 19:44:34 +0800 Subject: [PATCH 19/22] add sleep for tx finalized --- contract-tests/test/staking.precompile.wrap.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/contract-tests/test/staking.precompile.wrap.test.ts b/contract-tests/test/staking.precompile.wrap.test.ts index 7e4b21ed16..07eb7e6e6d 100644 --- a/contract-tests/test/staking.precompile.wrap.test.ts +++ b/contract-tests/test/staking.precompile.wrap.test.ts @@ -71,6 +71,7 @@ describe("Test staking precompile add from deployed contract", () => { wallet1, ); + await new Promise(resolve => setTimeout(resolve, 1000)); const tx = await deployedContract.stake( hotkey.publicKey, netuid, From ec9bb13ea5c35affafd93d4aca6b6abb55799e4f Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 15 Dec 2025 22:16:07 +0800 Subject: [PATCH 20/22] update docs for code change --- contract-tests/src/subtensor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/contract-tests/src/subtensor.ts b/contract-tests/src/subtensor.ts index 42825501a6..29a17a79fb 100644 --- a/contract-tests/src/subtensor.ts +++ b/contract-tests/src/subtensor.ts @@ -8,8 +8,6 @@ import { tao } from './balance-math' // create a new subnet and return netuid export async function addNewSubnetwork(api: TypedApi, hotkey: KeyPair, coldkey: KeyPair) { - - const alice = getAliceSigner() const totalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue() @@ -27,9 +25,8 @@ export async function addNewSubnetwork(api: TypedApi, hotkey: Key const newTotalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue() // could create multiple subnetworks during retry, just return the first created one assert.ok(newTotalNetworks > totalNetworks) - + // reset network last lock to 0 for tests await resetNetworkLastLock(api) - return totalNetworks } @@ -404,6 +401,8 @@ export async function sendWasmContractExtrinsic(api: TypedApi, co await waitForTransactionWithRetry(api, tx, signer) } +// Reset network last lock to 0 for tests, then the cose for network registration will be the default minimum +// We can make the const cost for each network registration for tests. avoid the cost spike export async function resetNetworkLastLock(api: TypedApi) { const alice = getAliceSigner() const key = await api.query.SubtensorModule.NetworkLastLockCost.getKey() @@ -412,7 +411,7 @@ export async function resetNetworkLastLock(api: TypedApi) { const codec = await getTypedCodecs(devnet) const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value - // Encode the value 1 TAO as SCALE-encoded bytes + // Encode the value 0 as SCALE-encoded bytes const encodedValue = valueCodec.enc(BigInt(0)) const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]]; From b9c779ce5cece49ce04e75af090884823fe3616f Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 15 Dec 2025 22:42:17 +0800 Subject: [PATCH 21/22] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c738e34c9b..9f54a46b54 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -237,7 +237,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 363, + spec_version: 364, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 0759aeca4729c7c87ba126c3ed7031ab36f69571 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 16 Dec 2025 22:00:03 +0800 Subject: [PATCH 22/22] avoid send evm transaction continuously --- contract-tests/test/subnet.precompile.hyperparameter.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contract-tests/test/subnet.precompile.hyperparameter.test.ts b/contract-tests/test/subnet.precompile.hyperparameter.test.ts index 87968b6e9f..40b0a77987 100644 --- a/contract-tests/test/subnet.precompile.hyperparameter.test.ts +++ b/contract-tests/test/subnet.precompile.hyperparameter.test.ts @@ -29,6 +29,10 @@ describe("Test the Subnet precompile contract", () => { await disableAdminFreezeWindowAndOwnerHyperparamRateLimit(api) }) + beforeEach(async () => { + await new Promise(resolve => setTimeout(resolve, 500)) + }) + it("Can register network without identity info", async () => { const totalNetwork = await api.query.SubtensorModule.TotalNetworks.getValue()