From c496e9b56dcdfa433b0cc6a682e53eb4ef7f2465 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 18 Mar 2026 11:05:03 +0800 Subject: [PATCH 1/6] fix staking in e2e --- contract-tests/test/alphaPool.test.ts | 6 +++--- contract-tests/test/staking.precompile.add-remove.test.ts | 8 ++++---- contract-tests/test/staking.precompile.full-limit.test.ts | 8 ++++---- contract-tests/test/staking.precompile.limit.test.ts | 4 ++-- e2e/staking/test/add-stake-limit.test.ts | 4 ++-- e2e/staking/test/add-stake.test.ts | 2 +- e2e/staking/test/claim-root.test.ts | 2 +- e2e/staking/test/move-stake.test.ts | 4 ++-- e2e/staking/test/remove-stake-full-limit.test.ts | 8 ++++---- e2e/staking/test/swap-stake-limit.test.ts | 8 ++++---- e2e/staking/test/transfer-stake.test.ts | 2 +- e2e/staking/test/unstake-all-alpha.test.ts | 4 ++-- e2e/staking/test/unstake-all.test.ts | 6 +++--- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/contract-tests/test/alphaPool.test.ts b/contract-tests/test/alphaPool.test.ts index 361e1213bb..75be4071b5 100644 --- a/contract-tests/test/alphaPool.test.ts +++ b/contract-tests/test/alphaPool.test.ts @@ -57,7 +57,7 @@ describe("bridge token contract deployment", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) - assert.ok(stakeAfter > stakeBefore) + assert.ok(stakeAfter >= stakeBefore) assert.ok(stakeFromContract > tao(20)) }) @@ -104,11 +104,11 @@ describe("bridge token contract deployment", () => { // compare wallet stake const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) - assert.ok(stakeAftereDeposit < stakeBeforeDeposit) + assert.ok(stakeAftereDeposit <= stakeBeforeDeposit) // check the contract stake const ContractStake = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) - assert.ok(ContractStake > 0) + assert.ok(ContractStake >= 0) // check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call const alphaBalanceOnContract = await contractForCall.alphaBalance(wallet.address, netuid) diff --git a/contract-tests/test/staking.precompile.add-remove.test.ts b/contract-tests/test/staking.precompile.add-remove.test.ts index d7dfcb0d3d..9cf1334107 100644 --- a/contract-tests/test/staking.precompile.add-remove.test.ts +++ b/contract-tests/test/staking.precompile.add-remove.test.ts @@ -65,7 +65,7 @@ describe("Test neuron precompile add remove stake", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) - assert.ok(stakeAfter > stakeBefore) + assert.ok(stakeAfter >= stakeBefore) }) it("Can add stake V2", async () => { @@ -83,7 +83,7 @@ describe("Test neuron precompile add remove stake", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) - assert.ok(stakeAfter > stakeBefore) + assert.ok(stakeAfter >= stakeBefore) }) it("Can not add stake if subnet doesn't exist", async () => { @@ -267,7 +267,7 @@ describe("Test neuron precompile add remove stake", () => { netuid ) - assert.ok(stakeAfter > stakeBefore) + assert.ok(stakeAfter >= stakeBefore) // test "remove" tx = await contract.removeProxy(proxy.publicKey); await tx.wait(); @@ -326,7 +326,7 @@ describe("Test neuron precompile add remove stake", () => { netuid ) - assert.ok(stakeAfter > stakeBefore) + assert.ok(stakeAfter >= stakeBefore) // test "remove" tx = await contract.removeProxy(proxy.publicKey); await tx.wait(); diff --git a/contract-tests/test/staking.precompile.full-limit.test.ts b/contract-tests/test/staking.precompile.full-limit.test.ts index 156fd38f25..4141ac1a04 100644 --- a/contract-tests/test/staking.precompile.full-limit.test.ts +++ b/contract-tests/test/staking.precompile.full-limit.test.ts @@ -78,7 +78,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake > alpha); + assert.ok(alphaAfterAddStake >= alpha); }); it("Staker remove stake with limit price", async () => { @@ -110,7 +110,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake < alpha); + assert.ok(alphaAfterRemoveStake <= alpha); }); }); @@ -147,7 +147,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake > alpha); + assert.ok(alphaAfterAddStake >= alpha); }); it("Staker remove stake with full", async () => { @@ -178,7 +178,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake < alpha); + assert.ok(alphaAfterRemoveStake <= alpha); }); }); }); diff --git a/contract-tests/test/staking.precompile.limit.test.ts b/contract-tests/test/staking.precompile.limit.test.ts index 759aaecce2..2b0bd157be 100644 --- a/contract-tests/test/staking.precompile.limit.test.ts +++ b/contract-tests/test/staking.precompile.limit.test.ts @@ -74,7 +74,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake > alpha); + assert.ok(alphaAfterAddStake >= alpha); }); it("Staker remove limit", async () => { @@ -108,6 +108,6 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake < alpha); + assert.ok(alphaAfterRemoveStake <= alpha); }); }); diff --git a/e2e/staking/test/add-stake-limit.test.ts b/e2e/staking/test/add-stake-limit.test.ts index 63e1bb6ba0..2f90f232ee 100644 --- a/e2e/staking/test/add-stake-limit.test.ts +++ b/e2e/staking/test/add-stake-limit.test.ts @@ -40,7 +40,7 @@ describe("▶ add_stake_limit extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase").toBeGreaterThan(stakeBefore); + expect(stakeAfter, "Stake should increase").toBeGreaterThanOrEqual(stakeBefore); log.info("✅ Successfully added stake with limit (allow partial)."); }); @@ -58,7 +58,7 @@ describe("▶ add_stake_limit extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase").toBeGreaterThan(stakeBefore); + expect(stakeAfter, "Stake should increase").toBeGreaterThanOrEqual(stakeBefore); log.info("✅ Successfully added stake with limit (fill or kill)."); }); diff --git a/e2e/staking/test/add-stake.test.ts b/e2e/staking/test/add-stake.test.ts index fd3eecf052..57f6b3f89b 100644 --- a/e2e/staking/test/add-stake.test.ts +++ b/e2e/staking/test/add-stake.test.ts @@ -39,7 +39,7 @@ describe("▶ add_stake extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase after adding stake").toBeGreaterThan(stakeBefore); + expect(stakeAfter, "Stake should increase after adding stake").toBeGreaterThanOrEqual(stakeBefore); log.info("✅ Successfully added stake."); }); diff --git a/e2e/staking/test/claim-root.test.ts b/e2e/staking/test/claim-root.test.ts index e6ca55876c..e90049e47a 100644 --- a/e2e/staking/test/claim-root.test.ts +++ b/e2e/staking/test/claim-root.test.ts @@ -446,7 +446,7 @@ describe("▶ claim_root extrinsic", () => { log.info(`RootClaimed value: ${rootClaimed}`); // With Swap type, ROOT stake should increase (not dynamic subnet stake) - expect(rootStakeAfter, "ROOT stake should increase after claiming with Swap type").toBeGreaterThan(rootStakeBefore); + expect(rootStakeAfter, "ROOT stake should increase after claiming with Swap type").toBeGreaterThanOrEqual(rootStakeBefore); log.info(`✅ Root claim with Swap successful: ROOT stake increased from ${rootStakeBefore} to ${rootStakeAfter}`); }); diff --git a/e2e/staking/test/move-stake.test.ts b/e2e/staking/test/move-stake.test.ts index 292d8d8ded..e382a1ec8e 100644 --- a/e2e/staking/test/move-stake.test.ts +++ b/e2e/staking/test/move-stake.test.ts @@ -97,7 +97,7 @@ describe("▶ move_stake extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const originStakeBefore = await getStake(api, originHotkeyAddress, coldkeyAddress, netuid); const destStakeBefore = await getStake(api, destinationHotkeyAddress, coldkeyAddress, netuid); - expect(originStakeBefore, "Origin hotkey should have stake before move").toBeGreaterThan(0n); + expect(originStakeBefore, "Origin hotkey should have stake before move").toBeGreaterThanOrEqual(0n); log.info(`Origin stake before: ${originStakeBefore}, Destination stake before: ${destStakeBefore}`); @@ -114,7 +114,7 @@ describe("▶ move_stake extrinsic", () => { log.info(`Origin stake after: ${originStakeAfter}, Destination stake after: ${destStakeAfter}`); expect(originStakeAfter, "Origin stake should decrease").toBeLessThan(originStakeBefore); - expect(destStakeAfter, "Destination stake should increase").toBeGreaterThan(destStakeBefore); + expect(destStakeAfter, "Destination stake should increase").toBeGreaterThanOrEqual(destStakeBefore); log.info("✅ Successfully moved stake to another hotkey on the same subnet."); }); diff --git a/e2e/staking/test/remove-stake-full-limit.test.ts b/e2e/staking/test/remove-stake-full-limit.test.ts index 47af798512..815302fb26 100644 --- a/e2e/staking/test/remove-stake-full-limit.test.ts +++ b/e2e/staking/test/remove-stake-full-limit.test.ts @@ -49,7 +49,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { const stakeBefore = await getStake(api, stakerAddress, coldkeyAddress, netuid); const balanceBefore = await getBalance(api, coldkeyAddress); log.info(`Stake before: ${stakeBefore}, Balance before: ${balanceBefore}`); - expect(stakeBefore, "Should have stake before removal").toBeGreaterThan(0n); + expect(stakeBefore, "Should have stake before removal").toBeGreaterThanOrEqual(0n); // Remove all stake with a reasonable limit price (low limit to avoid slippage rejection) // Using a low limit price (0.09 TAO per alpha) allows the transaction to succeed @@ -62,7 +62,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { log.info(`Stake after: ${stakeAfter}, Balance after: ${balanceAfter}`); expect(stakeAfter, "Stake should be zero after full removal").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); log.info("✅ Successfully removed all stake with price limit."); }); @@ -77,7 +77,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { const stakeBefore = await getStake(api, stakerAddress, coldkeyAddress, netuid); const balanceBefore = await getBalance(api, coldkeyAddress); log.info(`Stake before: ${stakeBefore}, Balance before: ${balanceBefore}`); - expect(stakeBefore, "Should have stake before removal").toBeGreaterThan(0n); + expect(stakeBefore, "Should have stake before removal").toBeGreaterThanOrEqual(0n); // Remove all stake without limit price (undefined = no slippage protection) await removeStakeFullLimit(api, coldkey, stakerAddress, netuid, undefined); @@ -88,7 +88,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { log.info(`Stake after: ${stakeAfter}, Balance after: ${balanceAfter}`); expect(stakeAfter, "Stake should be zero after full removal").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); log.info("✅ Successfully removed all stake without price limit."); }); diff --git a/e2e/staking/test/swap-stake-limit.test.ts b/e2e/staking/test/swap-stake-limit.test.ts index 316ddff051..961dc60bc7 100644 --- a/e2e/staking/test/swap-stake-limit.test.ts +++ b/e2e/staking/test/swap-stake-limit.test.ts @@ -48,7 +48,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const stake1Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const stake2Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThan(0n); + expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThanOrEqual(0n); log.info(`Stake on netuid1 before: ${stake1Before}, Stake on netuid2 before: ${stake2Before}`); @@ -65,8 +65,8 @@ describe("▶ swap_stake_limit extrinsic", () => { log.info(`Stake on netuid1 after: ${stake1After}, Stake on netuid2 after: ${stake2After}`); - expect(stake1After, "Stake on subnet1 should decrease").toBeLessThan(stake1Before); - expect(stake2After, "Stake on subnet2 should increase").toBeGreaterThan(stake2Before); + expect(stake1After, "Stake on subnet1 should decrease").toBeLessThanOrEqual(stake1Before); + expect(stake2After, "Stake on subnet2 should increase").toBeGreaterThanOrEqual(stake2Before); log.info("✅ Successfully swapped stake with price limit (allow partial)."); }); @@ -103,7 +103,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const stake1Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const stake2Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThan(0n); + expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThanOrEqual(0n); log.info(`Stake on netuid1 before: ${stake1Before}, Stake on netuid2 before: ${stake2Before}`); diff --git a/e2e/staking/test/transfer-stake.test.ts b/e2e/staking/test/transfer-stake.test.ts index 330ca0b8d9..39916c96a5 100644 --- a/e2e/staking/test/transfer-stake.test.ts +++ b/e2e/staking/test/transfer-stake.test.ts @@ -47,7 +47,7 @@ describe("▶ transfer_stake extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const originStakeBefore = await getStake(api, hotkey1Address, originColdkeyAddress, netuid1); const destStakeBefore = await getStake(api, hotkey1Address, destinationColdkeyAddress, netuid2); - expect(originStakeBefore, "Origin should have stake before transfer").toBeGreaterThan(0n); + expect(originStakeBefore, "Origin should have stake before transfer").toBeGreaterThanOrEqual(0n); log.info( `Origin stake (netuid1) before: ${originStakeBefore}, Destination stake (netuid2) before: ${destStakeBefore}`, diff --git a/e2e/staking/test/unstake-all-alpha.test.ts b/e2e/staking/test/unstake-all-alpha.test.ts index dd71a27192..223fb5eebd 100644 --- a/e2e/staking/test/unstake-all-alpha.test.ts +++ b/e2e/staking/test/unstake-all-alpha.test.ts @@ -61,8 +61,8 @@ describe("▶ unstake_all_alpha extrinsic", () => { const stake1Before = await getStake(api, stakerAddress, coldkeyAddress, netuid1); const stake2Before = await getStake(api, stakerAddress, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake in subnet 1 before unstake_all_alpha").toBeGreaterThan(0n); - expect(stake2Before, "Should have stake in subnet 2 before unstake_all_alpha").toBeGreaterThan(0n); + expect(stake1Before, "Should have stake in subnet 1 before unstake_all_alpha").toBeGreaterThanOrEqual(0n); + expect(stake2Before, "Should have stake in subnet 2 before unstake_all_alpha").toBeGreaterThanOrEqual(0n); log.info(`Stake1 before: ${stake1Before}, Stake2 before: ${stake2Before}`); // Unstake all alpha - this removes stake from dynamic subnets and restakes to root diff --git a/e2e/staking/test/unstake-all.test.ts b/e2e/staking/test/unstake-all.test.ts index 146a2c3225..79001f222d 100644 --- a/e2e/staking/test/unstake-all.test.ts +++ b/e2e/staking/test/unstake-all.test.ts @@ -63,8 +63,8 @@ describe("▶ unstake_all extrinsic", () => { const stake2Before = await getStake(api, stakerAddress, coldkeyAddress, netuid2); const balanceBefore = await getBalance(api, coldkeyAddress); - expect(stake1Before, "Should have stake in subnet 1 before unstake_all").toBeGreaterThan(0n); - expect(stake2Before, "Should have stake in subnet 2 before unstake_all").toBeGreaterThan(0n); + expect(stake1Before, "Should have stake in subnet 1 before unstake_all").toBeGreaterThanOrEqual(0n); + expect(stake2Before, "Should have stake in subnet 2 before unstake_all").toBeGreaterThanOrEqual(0n); log.info(`Stake1 before: ${stake1Before}, Stake2 before: ${stake2Before}, Balance before: ${balanceBefore}`); // Unstake all @@ -80,7 +80,7 @@ describe("▶ unstake_all extrinsic", () => { // Since stakerHotkey is not the owner of either subnet, all stake should be removed expect(stake1After, "Stake1 should be zero after unstake_all").toBe(0n); expect(stake2After, "Stake2 should be zero after unstake_all").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); log.info("✅ Successfully unstaked all from multiple subnets."); }); From 511e6e06fa727f48be1e35235f2f4dde8646d034 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 18 Mar 2026 19:37:56 +0800 Subject: [PATCH 2/6] revert at first --- contract-tests/test/alphaPool.test.ts | 6 +++--- contract-tests/test/staking.precompile.add-remove.test.ts | 8 ++++---- contract-tests/test/staking.precompile.full-limit.test.ts | 8 ++++---- contract-tests/test/staking.precompile.limit.test.ts | 4 ++-- e2e/staking/test/add-stake-limit.test.ts | 4 ++-- e2e/staking/test/add-stake.test.ts | 2 +- e2e/staking/test/claim-root.test.ts | 2 +- e2e/staking/test/move-stake.test.ts | 4 ++-- e2e/staking/test/remove-stake-full-limit.test.ts | 8 ++++---- e2e/staking/test/swap-stake-limit.test.ts | 8 ++++---- e2e/staking/test/transfer-stake.test.ts | 2 +- e2e/staking/test/unstake-all-alpha.test.ts | 4 ++-- e2e/staking/test/unstake-all.test.ts | 6 +++--- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/contract-tests/test/alphaPool.test.ts b/contract-tests/test/alphaPool.test.ts index 75be4071b5..361e1213bb 100644 --- a/contract-tests/test/alphaPool.test.ts +++ b/contract-tests/test/alphaPool.test.ts @@ -57,7 +57,7 @@ describe("bridge token contract deployment", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) - assert.ok(stakeAfter >= stakeBefore) + assert.ok(stakeAfter > stakeBefore) assert.ok(stakeFromContract > tao(20)) }) @@ -104,11 +104,11 @@ describe("bridge token contract deployment", () => { // compare wallet stake const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) - assert.ok(stakeAftereDeposit <= stakeBeforeDeposit) + assert.ok(stakeAftereDeposit < stakeBeforeDeposit) // check the contract stake const ContractStake = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) - assert.ok(ContractStake >= 0) + assert.ok(ContractStake > 0) // check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call const alphaBalanceOnContract = await contractForCall.alphaBalance(wallet.address, netuid) diff --git a/contract-tests/test/staking.precompile.add-remove.test.ts b/contract-tests/test/staking.precompile.add-remove.test.ts index 9cf1334107..d7dfcb0d3d 100644 --- a/contract-tests/test/staking.precompile.add-remove.test.ts +++ b/contract-tests/test/staking.precompile.add-remove.test.ts @@ -65,7 +65,7 @@ describe("Test neuron precompile add remove stake", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) - assert.ok(stakeAfter >= stakeBefore) + assert.ok(stakeAfter > stakeBefore) }) it("Can add stake V2", async () => { @@ -83,7 +83,7 @@ describe("Test neuron precompile add remove stake", () => { assert.ok(stakeFromContract > stakeBefore) const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) - assert.ok(stakeAfter >= stakeBefore) + assert.ok(stakeAfter > stakeBefore) }) it("Can not add stake if subnet doesn't exist", async () => { @@ -267,7 +267,7 @@ describe("Test neuron precompile add remove stake", () => { netuid ) - assert.ok(stakeAfter >= stakeBefore) + assert.ok(stakeAfter > stakeBefore) // test "remove" tx = await contract.removeProxy(proxy.publicKey); await tx.wait(); @@ -326,7 +326,7 @@ describe("Test neuron precompile add remove stake", () => { netuid ) - assert.ok(stakeAfter >= stakeBefore) + assert.ok(stakeAfter > stakeBefore) // test "remove" tx = await contract.removeProxy(proxy.publicKey); await tx.wait(); diff --git a/contract-tests/test/staking.precompile.full-limit.test.ts b/contract-tests/test/staking.precompile.full-limit.test.ts index 4141ac1a04..156fd38f25 100644 --- a/contract-tests/test/staking.precompile.full-limit.test.ts +++ b/contract-tests/test/staking.precompile.full-limit.test.ts @@ -78,7 +78,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake >= alpha); + assert.ok(alphaAfterAddStake > alpha); }); it("Staker remove stake with limit price", async () => { @@ -110,7 +110,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake <= alpha); + assert.ok(alphaAfterRemoveStake < alpha); }); }); @@ -147,7 +147,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake >= alpha); + assert.ok(alphaAfterAddStake > alpha); }); it("Staker remove stake with full", async () => { @@ -178,7 +178,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake <= alpha); + assert.ok(alphaAfterRemoveStake < alpha); }); }); }); diff --git a/contract-tests/test/staking.precompile.limit.test.ts b/contract-tests/test/staking.precompile.limit.test.ts index 2b0bd157be..759aaecce2 100644 --- a/contract-tests/test/staking.precompile.limit.test.ts +++ b/contract-tests/test/staking.precompile.limit.test.ts @@ -74,7 +74,7 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterAddStake >= alpha); + assert.ok(alphaAfterAddStake > alpha); }); it("Staker remove limit", async () => { @@ -108,6 +108,6 @@ describe("Test staking precompile add remove limit methods", () => { netuid, ); - assert.ok(alphaAfterRemoveStake <= alpha); + assert.ok(alphaAfterRemoveStake < alpha); }); }); diff --git a/e2e/staking/test/add-stake-limit.test.ts b/e2e/staking/test/add-stake-limit.test.ts index 2f90f232ee..63e1bb6ba0 100644 --- a/e2e/staking/test/add-stake-limit.test.ts +++ b/e2e/staking/test/add-stake-limit.test.ts @@ -40,7 +40,7 @@ describe("▶ add_stake_limit extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase").toBeGreaterThanOrEqual(stakeBefore); + expect(stakeAfter, "Stake should increase").toBeGreaterThan(stakeBefore); log.info("✅ Successfully added stake with limit (allow partial)."); }); @@ -58,7 +58,7 @@ describe("▶ add_stake_limit extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase").toBeGreaterThanOrEqual(stakeBefore); + expect(stakeAfter, "Stake should increase").toBeGreaterThan(stakeBefore); log.info("✅ Successfully added stake with limit (fill or kill)."); }); diff --git a/e2e/staking/test/add-stake.test.ts b/e2e/staking/test/add-stake.test.ts index 57f6b3f89b..fd3eecf052 100644 --- a/e2e/staking/test/add-stake.test.ts +++ b/e2e/staking/test/add-stake.test.ts @@ -39,7 +39,7 @@ describe("▶ add_stake extrinsic", () => { // Verify stake increased const stakeAfter = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); - expect(stakeAfter, "Stake should increase after adding stake").toBeGreaterThanOrEqual(stakeBefore); + expect(stakeAfter, "Stake should increase after adding stake").toBeGreaterThan(stakeBefore); log.info("✅ Successfully added stake."); }); diff --git a/e2e/staking/test/claim-root.test.ts b/e2e/staking/test/claim-root.test.ts index e90049e47a..e6ca55876c 100644 --- a/e2e/staking/test/claim-root.test.ts +++ b/e2e/staking/test/claim-root.test.ts @@ -446,7 +446,7 @@ describe("▶ claim_root extrinsic", () => { log.info(`RootClaimed value: ${rootClaimed}`); // With Swap type, ROOT stake should increase (not dynamic subnet stake) - expect(rootStakeAfter, "ROOT stake should increase after claiming with Swap type").toBeGreaterThanOrEqual(rootStakeBefore); + expect(rootStakeAfter, "ROOT stake should increase after claiming with Swap type").toBeGreaterThan(rootStakeBefore); log.info(`✅ Root claim with Swap successful: ROOT stake increased from ${rootStakeBefore} to ${rootStakeAfter}`); }); diff --git a/e2e/staking/test/move-stake.test.ts b/e2e/staking/test/move-stake.test.ts index e382a1ec8e..292d8d8ded 100644 --- a/e2e/staking/test/move-stake.test.ts +++ b/e2e/staking/test/move-stake.test.ts @@ -97,7 +97,7 @@ describe("▶ move_stake extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const originStakeBefore = await getStake(api, originHotkeyAddress, coldkeyAddress, netuid); const destStakeBefore = await getStake(api, destinationHotkeyAddress, coldkeyAddress, netuid); - expect(originStakeBefore, "Origin hotkey should have stake before move").toBeGreaterThanOrEqual(0n); + expect(originStakeBefore, "Origin hotkey should have stake before move").toBeGreaterThan(0n); log.info(`Origin stake before: ${originStakeBefore}, Destination stake before: ${destStakeBefore}`); @@ -114,7 +114,7 @@ describe("▶ move_stake extrinsic", () => { log.info(`Origin stake after: ${originStakeAfter}, Destination stake after: ${destStakeAfter}`); expect(originStakeAfter, "Origin stake should decrease").toBeLessThan(originStakeBefore); - expect(destStakeAfter, "Destination stake should increase").toBeGreaterThanOrEqual(destStakeBefore); + expect(destStakeAfter, "Destination stake should increase").toBeGreaterThan(destStakeBefore); log.info("✅ Successfully moved stake to another hotkey on the same subnet."); }); diff --git a/e2e/staking/test/remove-stake-full-limit.test.ts b/e2e/staking/test/remove-stake-full-limit.test.ts index 815302fb26..47af798512 100644 --- a/e2e/staking/test/remove-stake-full-limit.test.ts +++ b/e2e/staking/test/remove-stake-full-limit.test.ts @@ -49,7 +49,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { const stakeBefore = await getStake(api, stakerAddress, coldkeyAddress, netuid); const balanceBefore = await getBalance(api, coldkeyAddress); log.info(`Stake before: ${stakeBefore}, Balance before: ${balanceBefore}`); - expect(stakeBefore, "Should have stake before removal").toBeGreaterThanOrEqual(0n); + expect(stakeBefore, "Should have stake before removal").toBeGreaterThan(0n); // Remove all stake with a reasonable limit price (low limit to avoid slippage rejection) // Using a low limit price (0.09 TAO per alpha) allows the transaction to succeed @@ -62,7 +62,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { log.info(`Stake after: ${stakeAfter}, Balance after: ${balanceAfter}`); expect(stakeAfter, "Stake should be zero after full removal").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); log.info("✅ Successfully removed all stake with price limit."); }); @@ -77,7 +77,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { const stakeBefore = await getStake(api, stakerAddress, coldkeyAddress, netuid); const balanceBefore = await getBalance(api, coldkeyAddress); log.info(`Stake before: ${stakeBefore}, Balance before: ${balanceBefore}`); - expect(stakeBefore, "Should have stake before removal").toBeGreaterThanOrEqual(0n); + expect(stakeBefore, "Should have stake before removal").toBeGreaterThan(0n); // Remove all stake without limit price (undefined = no slippage protection) await removeStakeFullLimit(api, coldkey, stakerAddress, netuid, undefined); @@ -88,7 +88,7 @@ describe("▶ remove_stake_full_limit extrinsic", () => { log.info(`Stake after: ${stakeAfter}, Balance after: ${balanceAfter}`); expect(stakeAfter, "Stake should be zero after full removal").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); log.info("✅ Successfully removed all stake without price limit."); }); diff --git a/e2e/staking/test/swap-stake-limit.test.ts b/e2e/staking/test/swap-stake-limit.test.ts index 961dc60bc7..316ddff051 100644 --- a/e2e/staking/test/swap-stake-limit.test.ts +++ b/e2e/staking/test/swap-stake-limit.test.ts @@ -48,7 +48,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const stake1Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const stake2Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThanOrEqual(0n); + expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThan(0n); log.info(`Stake on netuid1 before: ${stake1Before}, Stake on netuid2 before: ${stake2Before}`); @@ -65,8 +65,8 @@ describe("▶ swap_stake_limit extrinsic", () => { log.info(`Stake on netuid1 after: ${stake1After}, Stake on netuid2 after: ${stake2After}`); - expect(stake1After, "Stake on subnet1 should decrease").toBeLessThanOrEqual(stake1Before); - expect(stake2After, "Stake on subnet2 should increase").toBeGreaterThanOrEqual(stake2Before); + expect(stake1After, "Stake on subnet1 should decrease").toBeLessThan(stake1Before); + expect(stake2After, "Stake on subnet2 should increase").toBeGreaterThan(stake2Before); log.info("✅ Successfully swapped stake with price limit (allow partial)."); }); @@ -103,7 +103,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const stake1Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const stake2Before = await getStake(api, hotkey1Address, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThanOrEqual(0n); + expect(stake1Before, "Should have stake on subnet1 before swap").toBeGreaterThan(0n); log.info(`Stake on netuid1 before: ${stake1Before}, Stake on netuid2 before: ${stake2Before}`); diff --git a/e2e/staking/test/transfer-stake.test.ts b/e2e/staking/test/transfer-stake.test.ts index 39916c96a5..330ca0b8d9 100644 --- a/e2e/staking/test/transfer-stake.test.ts +++ b/e2e/staking/test/transfer-stake.test.ts @@ -47,7 +47,7 @@ describe("▶ transfer_stake extrinsic", () => { // Get initial stakes (converted from U64F64 for display) const originStakeBefore = await getStake(api, hotkey1Address, originColdkeyAddress, netuid1); const destStakeBefore = await getStake(api, hotkey1Address, destinationColdkeyAddress, netuid2); - expect(originStakeBefore, "Origin should have stake before transfer").toBeGreaterThanOrEqual(0n); + expect(originStakeBefore, "Origin should have stake before transfer").toBeGreaterThan(0n); log.info( `Origin stake (netuid1) before: ${originStakeBefore}, Destination stake (netuid2) before: ${destStakeBefore}`, diff --git a/e2e/staking/test/unstake-all-alpha.test.ts b/e2e/staking/test/unstake-all-alpha.test.ts index 223fb5eebd..dd71a27192 100644 --- a/e2e/staking/test/unstake-all-alpha.test.ts +++ b/e2e/staking/test/unstake-all-alpha.test.ts @@ -61,8 +61,8 @@ describe("▶ unstake_all_alpha extrinsic", () => { const stake1Before = await getStake(api, stakerAddress, coldkeyAddress, netuid1); const stake2Before = await getStake(api, stakerAddress, coldkeyAddress, netuid2); - expect(stake1Before, "Should have stake in subnet 1 before unstake_all_alpha").toBeGreaterThanOrEqual(0n); - expect(stake2Before, "Should have stake in subnet 2 before unstake_all_alpha").toBeGreaterThanOrEqual(0n); + expect(stake1Before, "Should have stake in subnet 1 before unstake_all_alpha").toBeGreaterThan(0n); + expect(stake2Before, "Should have stake in subnet 2 before unstake_all_alpha").toBeGreaterThan(0n); log.info(`Stake1 before: ${stake1Before}, Stake2 before: ${stake2Before}`); // Unstake all alpha - this removes stake from dynamic subnets and restakes to root diff --git a/e2e/staking/test/unstake-all.test.ts b/e2e/staking/test/unstake-all.test.ts index 79001f222d..146a2c3225 100644 --- a/e2e/staking/test/unstake-all.test.ts +++ b/e2e/staking/test/unstake-all.test.ts @@ -63,8 +63,8 @@ describe("▶ unstake_all extrinsic", () => { const stake2Before = await getStake(api, stakerAddress, coldkeyAddress, netuid2); const balanceBefore = await getBalance(api, coldkeyAddress); - expect(stake1Before, "Should have stake in subnet 1 before unstake_all").toBeGreaterThanOrEqual(0n); - expect(stake2Before, "Should have stake in subnet 2 before unstake_all").toBeGreaterThanOrEqual(0n); + expect(stake1Before, "Should have stake in subnet 1 before unstake_all").toBeGreaterThan(0n); + expect(stake2Before, "Should have stake in subnet 2 before unstake_all").toBeGreaterThan(0n); log.info(`Stake1 before: ${stake1Before}, Stake2 before: ${stake2Before}, Balance before: ${balanceBefore}`); // Unstake all @@ -80,7 +80,7 @@ describe("▶ unstake_all extrinsic", () => { // Since stakerHotkey is not the owner of either subnet, all stake should be removed expect(stake1After, "Stake1 should be zero after unstake_all").toBe(0n); expect(stake2After, "Stake2 should be zero after unstake_all").toBe(0n); - expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThanOrEqual(balanceBefore); + expect(balanceAfter, "Balance should increase after unstaking").toBeGreaterThan(balanceBefore); log.info("✅ Successfully unstaked all from multiple subnets."); }); From 0ee897e147e4c206bca6d2e1247b86a93025955f Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 18 Mar 2026 19:39:24 +0800 Subject: [PATCH 3/6] use alpha v2 as stake --- contract-tests/test/alphaPool.test.ts | 10 ++++---- .../precompileWrapper.direct-call.test.ts | 8 +++---- .../staking.precompile.add-remove.test.ts | 24 +++++++++---------- .../staking.precompile.burn-alpha.test.ts | 2 +- .../staking.precompile.full-limit.test.ts | 16 ++++++------- .../test/staking.precompile.limit.test.ts | 8 +++---- .../test/staking.precompile.reward.test.ts | 4 ++-- .../subnet.precompile.hyperparameter.test.ts | 2 +- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/contract-tests/test/alphaPool.test.ts b/contract-tests/test/alphaPool.test.ts index 361e1213bb..573721b855 100644 --- a/contract-tests/test/alphaPool.test.ts +++ b/contract-tests/test/alphaPool.test.ts @@ -46,7 +46,7 @@ describe("bridge token contract deployment", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet); const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid) await tx.wait() @@ -56,7 +56,7 @@ describe("bridge token contract deployment", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) assert.ok(stakeAfter > stakeBefore) assert.ok(stakeFromContract > tao(20)) }) @@ -66,7 +66,7 @@ describe("bridge token contract deployment", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 const stakingPrecompile = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet); - const stakeBeforeDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeBeforeDeposit = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) const contractFactory = new ethers.ContractFactory(ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE, wallet) const contract = await contractFactory.deploy(hotkey.publicKey) @@ -103,11 +103,11 @@ describe("bridge token contract deployment", () => { await depositAlphaTx.wait() // compare wallet stake - const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeAftereDeposit = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) assert.ok(stakeAftereDeposit < stakeBeforeDeposit) // check the contract stake - const ContractStake = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) + const ContractStake = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) assert.ok(ContractStake > 0) // check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call diff --git a/contract-tests/test/precompileWrapper.direct-call.test.ts b/contract-tests/test/precompileWrapper.direct-call.test.ts index 5d63dfbb44..afd79797a1 100644 --- a/contract-tests/test/precompileWrapper.direct-call.test.ts +++ b/contract-tests/test/precompileWrapper.direct-call.test.ts @@ -147,7 +147,7 @@ describe("PrecompileWrapper - Direct Call Tests", () => { it("Should add stake via wrapper", async () => { const stakeAmount = tao(2); - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue( + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -161,7 +161,7 @@ describe("PrecompileWrapper - Direct Call Tests", () => { ); await addStakeTx.wait(); - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue( + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -171,7 +171,7 @@ describe("PrecompileWrapper - Direct Call Tests", () => { it("Should remove stake via wrapper", async () => { const removeAmount = tao(1); - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue( + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -184,7 +184,7 @@ describe("PrecompileWrapper - Direct Call Tests", () => { ); await removeStakeTx.wait(); - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue( + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid diff --git a/contract-tests/test/staking.precompile.add-remove.test.ts b/contract-tests/test/staking.precompile.add-remove.test.ts index d7dfcb0d3d..9e90c0a60a 100644 --- a/contract-tests/test/staking.precompile.add-remove.test.ts +++ b/contract-tests/test/staking.precompile.add-remove.test.ts @@ -54,7 +54,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // ETH unit let stakeBalance = raoToEth(tao(20)) - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) const contract = new ethers.Contract(ISTAKING_ADDRESS, IStakingABI, wallet1); const tx = await contract.addStake(hotkey.publicKey, netuid, { value: stakeBalance.toString() }) await tx.wait() @@ -64,7 +64,7 @@ describe("Test neuron precompile add remove stake", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) assert.ok(stakeAfter > stakeBefore) }) @@ -72,7 +72,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2); const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid) await tx.wait() @@ -82,7 +82,7 @@ describe("Test neuron precompile add remove stake", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) assert.ok(stakeAfter > stakeBefore) }) @@ -90,7 +90,7 @@ describe("Test neuron precompile add remove stake", () => { // wrong netuid let netuid = 12345; let stakeBalance = raoToEth(tao(20)) - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) const contract = new ethers.Contract(ISTAKING_ADDRESS, IStakingABI, wallet1); try { const tx = await contract.addStake(hotkey.publicKey, netuid, { value: stakeBalance.toString() }) @@ -104,7 +104,7 @@ describe("Test neuron precompile add remove stake", () => { await contract.getStake(hotkey.publicKey, convertH160ToPublicKey(wallet1.address), netuid) ); assert.equal(stakeFromContract, stakeBefore) - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) assert.equal(stakeAfter, stakeBefore) }); @@ -113,7 +113,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = 12345; // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2); try { @@ -128,7 +128,7 @@ describe("Test neuron precompile add remove stake", () => { await contract.getStake(hotkey.publicKey, convertH160ToPublicKey(wallet2.address), netuid) ); assert.equal(stakeFromContract, stakeBefore) - const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) assert.equal(stakeAfter, stakeBefore) }) @@ -248,7 +248,7 @@ describe("Test neuron precompile add remove stake", () => { assert.equal(proxiesAfterAdd[0][0].delegate, convertPublicKeyToSs58(proxy.publicKey)) - let stakeBefore = await api.query.SubtensorModule.Alpha.getValue( + let stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -261,7 +261,7 @@ describe("Test neuron precompile add remove stake", () => { }) await sendProxyCall(api, call.decodedCall, ss58Address, proxy) - let stakeAfter = await api.query.SubtensorModule.Alpha.getValue( + let stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -306,7 +306,7 @@ describe("Test neuron precompile add remove stake", () => { assert.equal(proxiesAfterAdd[0][0].delegate, convertPublicKeyToSs58(proxy.publicKey)) - let stakeBefore = await api.query.SubtensorModule.Alpha.getValue( + let stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -320,7 +320,7 @@ describe("Test neuron precompile add remove stake", () => { await sendProxyCall(api, call.decodedCall, ss58Address, proxy) - let stakeAfter = await api.query.SubtensorModule.Alpha.getValue( + let stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid diff --git a/contract-tests/test/staking.precompile.burn-alpha.test.ts b/contract-tests/test/staking.precompile.burn-alpha.test.ts index 825587602e..400a6bc023 100644 --- a/contract-tests/test/staking.precompile.burn-alpha.test.ts +++ b/contract-tests/test/staking.precompile.burn-alpha.test.ts @@ -72,7 +72,7 @@ describe("Test staking precompile burn alpha", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // Get current stake - const currentStake = await api.query.SubtensorModule.Alpha.getValue( + const currentStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid diff --git a/contract-tests/test/staking.precompile.full-limit.test.ts b/contract-tests/test/staking.precompile.full-limit.test.ts index 156fd38f25..a4a4335190 100644 --- a/contract-tests/test/staking.precompile.full-limit.test.ts +++ b/contract-tests/test/staking.precompile.full-limit.test.ts @@ -51,7 +51,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -72,7 +72,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -85,7 +85,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -104,7 +104,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -120,7 +120,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet2.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -141,7 +141,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -154,7 +154,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet2.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -172,7 +172,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, diff --git a/contract-tests/test/staking.precompile.limit.test.ts b/contract-tests/test/staking.precompile.limit.test.ts index 759aaecce2..78568430a3 100644 --- a/contract-tests/test/staking.precompile.limit.test.ts +++ b/contract-tests/test/staking.precompile.limit.test.ts @@ -47,7 +47,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -68,7 +68,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -81,7 +81,7 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.Alpha.getValue( + const alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -102,7 +102,7 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.Alpha.getValue( + const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, diff --git a/contract-tests/test/staking.precompile.reward.test.ts b/contract-tests/test/staking.precompile.reward.test.ts index d04620c91b..f2ae6a5dae 100644 --- a/contract-tests/test/staking.precompile.reward.test.ts +++ b/contract-tests/test/staking.precompile.reward.test.ts @@ -63,7 +63,7 @@ describe("Test neuron precompile reward", () => { await addStake(api, netuid, convertPublicKeyToSs58(validator.publicKey), tao(100), coldkey) - const miner_alpha_before_emission = await api.query.SubtensorModule.Alpha.getValue( + const miner_alpha_before_emission = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(miner.publicKey), convertPublicKeyToSs58(coldkey.publicKey), netuid @@ -87,7 +87,7 @@ describe("Test neuron precompile reward", () => { index = 0; while (index < 60) { - let miner_current_alpha = await api.query.SubtensorModule.Alpha.getValue( + let miner_current_alpha = await api.query.SubtensorModule.AlphaV2.getValue( convertPublicKeyToSs58(miner.publicKey), convertPublicKeyToSs58(coldkey.publicKey), netuid diff --git a/contract-tests/test/subnet.precompile.hyperparameter.test.ts b/contract-tests/test/subnet.precompile.hyperparameter.test.ts index 75d361a77f..2c9355ec40 100644 --- a/contract-tests/test/subnet.precompile.hyperparameter.test.ts +++ b/contract-tests/test/subnet.precompile.hyperparameter.test.ts @@ -517,7 +517,7 @@ describe("Test the Subnet precompile contract", () => { // const tx = await contract.setAlphaValues(netuid, newValue[0], newValue[1]); // await tx.wait(); - // let onchainValue = await api.query.SubtensorModule.AlphaValues.getValue(netuid) + // let onchainValue = await api.query.SubtensorModule.AlphaV2Values.getValue(netuid) // let value = await contract.getAlphaValues(netuid) // let valueFromContract = [Number(value[0]), Number(value[1])] From 493c2aad879773ade7e97f189e6f6362817d8626 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 18 Mar 2026 21:08:12 +0800 Subject: [PATCH 4/6] use alplha v2 --- contract-tests/src/subtensor.ts | 18 ++++++++++++ contract-tests/test/alphaPool.test.ts | 12 ++++---- .../precompileWrapper.direct-call.test.ts | 13 ++++++--- .../staking.precompile.add-remove.test.ts | 29 +++++++++++-------- .../staking.precompile.burn-alpha.test.ts | 4 ++- .../staking.precompile.full-limit.test.ts | 25 +++++++++++----- .../test/staking.precompile.limit.test.ts | 13 ++++++--- .../test/staking.precompile.reward.test.ts | 9 ++++-- 8 files changed, 85 insertions(+), 38 deletions(-) diff --git a/contract-tests/src/subtensor.ts b/contract-tests/src/subtensor.ts index f5829c76aa..2b3b5d8be1 100644 --- a/contract-tests/src/subtensor.ts +++ b/contract-tests/src/subtensor.ts @@ -419,4 +419,22 @@ export async function setNetworkLastLockCost(api: TypedApi, defau const valueOnChain = await api.query.SubtensorModule.NetworkLastLockCost.getValue() assert.equal(defaultNetworkLastLockCost, valueOnChain) +} + + +export async function getStake(api: TypedApi, hotkey: string, coldkey: string, netuid: number): Promise { + const value = (await api.query.SubtensorModule.AlphaV2.getValue(hotkey, coldkey, netuid)); + + const mantissa = value.mantissa; + const exponent = value.exponent; + + let result: bigint; + + if (exponent >= 0) { + result = mantissa * BigInt(10) ** exponent; + } else { + result = mantissa / BigInt(10) ** -exponent; + } + + return result; } \ No newline at end of file diff --git a/contract-tests/test/alphaPool.test.ts b/contract-tests/test/alphaPool.test.ts index 573721b855..f3ec5dde66 100644 --- a/contract-tests/test/alphaPool.test.ts +++ b/contract-tests/test/alphaPool.test.ts @@ -9,7 +9,7 @@ import { PublicClient } from "viem"; import { TypedApi } from "polkadot-api"; import { ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE } from "../src/contracts/alphaPool"; import { convertH160ToPublicKey, convertH160ToSS58, convertPublicKeyToSs58, toViemAddress } from "../src/address-utils"; -import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister } from "../src/subtensor"; +import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister, getStake } from "../src/subtensor"; import { ethers } from "ethers" import { tao } from "../src/balance-math"; import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking"; @@ -46,7 +46,7 @@ describe("bridge token contract deployment", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet); const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid) await tx.wait() @@ -56,7 +56,7 @@ describe("bridge token contract deployment", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) assert.ok(stakeAfter > stakeBefore) assert.ok(stakeFromContract > tao(20)) }) @@ -66,7 +66,7 @@ describe("bridge token contract deployment", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 const stakingPrecompile = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet); - const stakeBeforeDeposit = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeBeforeDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) const contractFactory = new ethers.ContractFactory(ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE, wallet) const contract = await contractFactory.deploy(hotkey.publicKey) @@ -103,11 +103,11 @@ describe("bridge token contract deployment", () => { await depositAlphaTx.wait() // compare wallet stake - const stakeAftereDeposit = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) + const stakeAftereDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) assert.ok(stakeAftereDeposit < stakeBeforeDeposit) // check the contract stake - const ContractStake = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) + const ContractStake = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid) assert.ok(ContractStake > 0) // check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call diff --git a/contract-tests/test/precompileWrapper.direct-call.test.ts b/contract-tests/test/precompileWrapper.direct-call.test.ts index afd79797a1..fa1354f3ce 100644 --- a/contract-tests/test/precompileWrapper.direct-call.test.ts +++ b/contract-tests/test/precompileWrapper.direct-call.test.ts @@ -10,6 +10,7 @@ import { startCall, disableWhiteListCheck, forceSetBalanceToEthAddress, + getStake, } from "../src/subtensor"; import { ethers } from "ethers"; @@ -147,7 +148,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => { it("Should add stake via wrapper", async () => { const stakeAmount = tao(2); - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( + const stakeBefore = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -161,7 +163,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => { ); await addStakeTx.wait(); - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( + const stakeAfter = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -171,7 +174,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => { it("Should remove stake via wrapper", async () => { const removeAmount = tao(1); - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( + const stakeBefore = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid @@ -184,7 +188,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => { ); await removeStakeTx.wait(); - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( + const stakeAfter = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wrapperAddress), netuid diff --git a/contract-tests/test/staking.precompile.add-remove.test.ts b/contract-tests/test/staking.precompile.add-remove.test.ts index 9e90c0a60a..9eef7d4dbf 100644 --- a/contract-tests/test/staking.precompile.add-remove.test.ts +++ b/contract-tests/test/staking.precompile.add-remove.test.ts @@ -11,6 +11,7 @@ import { forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, burnedRegister, sendProxyCall, startCall, + getStake, } from "../src/subtensor" import { ETH_LOCAL_URL } from "../src/config"; import { ISTAKING_ADDRESS, ISTAKING_V2_ADDRESS, IStakingABI, IStakingV2ABI } from "../src/contracts/staking" @@ -54,7 +55,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // ETH unit let stakeBalance = raoToEth(tao(20)) - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) const contract = new ethers.Contract(ISTAKING_ADDRESS, IStakingABI, wallet1); const tx = await contract.addStake(hotkey.publicKey, netuid, { value: stakeBalance.toString() }) await tx.wait() @@ -64,7 +65,7 @@ describe("Test neuron precompile add remove stake", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) assert.ok(stakeAfter > stakeBefore) }) @@ -72,7 +73,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2); const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid) await tx.wait() @@ -82,7 +83,7 @@ describe("Test neuron precompile add remove stake", () => { ); assert.ok(stakeFromContract > stakeBefore) - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) assert.ok(stakeAfter > stakeBefore) }) @@ -90,7 +91,7 @@ describe("Test neuron precompile add remove stake", () => { // wrong netuid let netuid = 12345; let stakeBalance = raoToEth(tao(20)) - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) const contract = new ethers.Contract(ISTAKING_ADDRESS, IStakingABI, wallet1); try { const tx = await contract.addStake(hotkey.publicKey, netuid, { value: stakeBalance.toString() }) @@ -104,7 +105,7 @@ describe("Test neuron precompile add remove stake", () => { await contract.getStake(hotkey.publicKey, convertH160ToPublicKey(wallet1.address), netuid) ); assert.equal(stakeFromContract, stakeBefore) - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) + const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid) assert.equal(stakeAfter, stakeBefore) }); @@ -113,7 +114,7 @@ describe("Test neuron precompile add remove stake", () => { let netuid = 12345; // the unit in V2 is RAO, not ETH let stakeBalance = tao(20) - const stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2); try { @@ -128,7 +129,7 @@ describe("Test neuron precompile add remove stake", () => { await contract.getStake(hotkey.publicKey, convertH160ToPublicKey(wallet2.address), netuid) ); assert.equal(stakeFromContract, stakeBefore) - const stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) + const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet2.address), netuid) assert.equal(stakeAfter, stakeBefore) }) @@ -248,7 +249,8 @@ describe("Test neuron precompile add remove stake", () => { assert.equal(proxiesAfterAdd[0][0].delegate, convertPublicKeyToSs58(proxy.publicKey)) - let stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( + let stakeBefore = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -261,7 +263,8 @@ describe("Test neuron precompile add remove stake", () => { }) await sendProxyCall(api, call.decodedCall, ss58Address, proxy) - let stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( + let stakeAfter = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -306,7 +309,8 @@ describe("Test neuron precompile add remove stake", () => { assert.equal(proxiesAfterAdd[0][0].delegate, convertPublicKeyToSs58(proxy.publicKey)) - let stakeBefore = await api.query.SubtensorModule.AlphaV2.getValue( + let stakeBefore = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid @@ -320,7 +324,8 @@ describe("Test neuron precompile add remove stake", () => { await sendProxyCall(api, call.decodedCall, ss58Address, proxy) - let stakeAfter = await api.query.SubtensorModule.AlphaV2.getValue( + let stakeAfter = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid diff --git a/contract-tests/test/staking.precompile.burn-alpha.test.ts b/contract-tests/test/staking.precompile.burn-alpha.test.ts index 400a6bc023..f98c988b52 100644 --- a/contract-tests/test/staking.precompile.burn-alpha.test.ts +++ b/contract-tests/test/staking.precompile.burn-alpha.test.ts @@ -10,6 +10,7 @@ import { convertH160ToPublicKey } from "../src/address-utils" import { forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, burnedRegister, startCall, + getStake, } from "../src/subtensor" import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking" @@ -72,7 +73,8 @@ describe("Test staking precompile burn alpha", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1 // Get current stake - const currentStake = await api.query.SubtensorModule.AlphaV2.getValue( + const currentStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet1.address), netuid diff --git a/contract-tests/test/staking.precompile.full-limit.test.ts b/contract-tests/test/staking.precompile.full-limit.test.ts index a4a4335190..faf09d65fd 100644 --- a/contract-tests/test/staking.precompile.full-limit.test.ts +++ b/contract-tests/test/staking.precompile.full-limit.test.ts @@ -12,6 +12,7 @@ import { addStake, forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, + getStake, startCall, } from "../src/subtensor"; import { ethers } from "ethers"; @@ -51,7 +52,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -72,7 +74,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterAddStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -85,7 +88,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -104,7 +108,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterRemoveStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -120,7 +125,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet2.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -141,7 +147,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterAddStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -154,7 +161,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet2.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -172,7 +180,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterRemoveStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, diff --git a/contract-tests/test/staking.precompile.limit.test.ts b/contract-tests/test/staking.precompile.limit.test.ts index 78568430a3..eff1394911 100644 --- a/contract-tests/test/staking.precompile.limit.test.ts +++ b/contract-tests/test/staking.precompile.limit.test.ts @@ -12,6 +12,7 @@ import { addStake, forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, + getStake, startCall, } from "../src/subtensor"; import { ethers } from "ethers"; @@ -47,7 +48,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -68,7 +70,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterAddStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterAddStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -81,7 +84,8 @@ describe("Test staking precompile add remove limit methods", () => { let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1; let ss58Address = convertH160ToSS58(wallet1.address); - const alpha = await api.query.SubtensorModule.AlphaV2.getValue( + const alpha = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, @@ -102,7 +106,8 @@ describe("Test staking precompile add remove limit methods", () => { ); await tx.wait(); - const alphaAfterRemoveStake = await api.query.SubtensorModule.AlphaV2.getValue( + const alphaAfterRemoveStake = await getStake( + api, convertPublicKeyToSs58(hotkey.publicKey), ss58Address, netuid, diff --git a/contract-tests/test/staking.precompile.reward.test.ts b/contract-tests/test/staking.precompile.reward.test.ts index f2ae6a5dae..31e15c6225 100644 --- a/contract-tests/test/staking.precompile.reward.test.ts +++ b/contract-tests/test/staking.precompile.reward.test.ts @@ -9,7 +9,8 @@ import { setTxRateLimit, setTempo, setWeightsSetRateLimit, setSubnetOwnerCut, setMinDelegateTake, setActivityCutoff, addStake, setWeight, rootRegister, startCall, - disableAdminFreezeWindowAndOwnerHyperparamRateLimit + disableAdminFreezeWindowAndOwnerHyperparamRateLimit, + getStake } from "../src/subtensor" describe("Test neuron precompile reward", () => { @@ -63,7 +64,8 @@ describe("Test neuron precompile reward", () => { await addStake(api, netuid, convertPublicKeyToSs58(validator.publicKey), tao(100), coldkey) - const miner_alpha_before_emission = await api.query.SubtensorModule.AlphaV2.getValue( + const miner_alpha_before_emission = await getStake( + api, convertPublicKeyToSs58(miner.publicKey), convertPublicKeyToSs58(coldkey.publicKey), netuid @@ -87,7 +89,8 @@ describe("Test neuron precompile reward", () => { index = 0; while (index < 60) { - let miner_current_alpha = await api.query.SubtensorModule.AlphaV2.getValue( + let miner_current_alpha = await getStake( + api, convertPublicKeyToSs58(miner.publicKey), convertPublicKeyToSs58(coldkey.publicKey), netuid From d2fc3270c8a4200b4fba66528fe5c46131c791a1 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 19 Mar 2026 11:17:24 +0800 Subject: [PATCH 5/6] use alpha v2 --- e2e/shared/staking.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/e2e/shared/staking.ts b/e2e/shared/staking.ts index 96241f64e9..408d18a619 100644 --- a/e2e/shared/staking.ts +++ b/e2e/shared/staking.ts @@ -152,8 +152,20 @@ export async function getStake( coldkey: string, netuid: number, ): Promise { - const raw = await api.query.SubtensorModule.Alpha.getValue(hotkey, coldkey, netuid); - return u64f64ToInt(raw); + const value = (await api.query.SubtensorModule.AlphaV2.getValue(hotkey, coldkey, netuid)); + + const mantissa = value.mantissa; + const exponent = value.exponent; + + let result: bigint; + + if (exponent >= 0) { + result = mantissa * BigInt(10) ** exponent; + } else { + result = mantissa / BigInt(10) ** -exponent; + } + + return result; } /** From 1306126d261c7e8c8018e4ef59c37dc5e0c30022 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 19 Mar 2026 17:11:04 +0800 Subject: [PATCH 6/6] fix e2e staking --- e2e/staking/test/move-stake.test.ts | 5 ++--- e2e/staking/test/remove-stake.test.ts | 3 +-- e2e/staking/test/swap-stake-limit.test.ts | 5 ++--- e2e/staking/test/swap-stake.test.ts | 4 ++-- e2e/staking/test/transfer-stake.test.ts | 5 ++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/e2e/staking/test/move-stake.test.ts b/e2e/staking/test/move-stake.test.ts index 292d8d8ded..5c61002062 100644 --- a/e2e/staking/test/move-stake.test.ts +++ b/e2e/staking/test/move-stake.test.ts @@ -10,7 +10,6 @@ import { addStake, moveStake, getStake, - getStakeRaw, tao, log, } from "e2e-shared"; @@ -53,7 +52,7 @@ describe("▶ move_stake extrinsic", () => { // Move stake to destination hotkey on different subnet // Use raw U64F64 value for the extrinsic - const originStakeRaw = await getStakeRaw(api, originHotkeyAddress, coldkeyAddress, netuid1); + const originStakeRaw = await getStake(api, originHotkeyAddress, coldkeyAddress, netuid1); const moveAmount = originStakeRaw / 2n; await moveStake(api, coldkey, originHotkeyAddress, destinationHotkeyAddress, netuid1, netuid2, moveAmount); @@ -103,7 +102,7 @@ describe("▶ move_stake extrinsic", () => { // Move stake to destination hotkey on the same subnet // Use raw U64F64 value for the extrinsic - const originStakeRaw = await getStakeRaw(api, originHotkeyAddress, coldkeyAddress, netuid); + const originStakeRaw = await getStake(api, originHotkeyAddress, coldkeyAddress, netuid); const moveAmount = originStakeRaw / 2n; await moveStake(api, coldkey, originHotkeyAddress, destinationHotkeyAddress, netuid, netuid, moveAmount); diff --git a/e2e/staking/test/remove-stake.test.ts b/e2e/staking/test/remove-stake.test.ts index db9f5aa150..e7eb4c7437 100644 --- a/e2e/staking/test/remove-stake.test.ts +++ b/e2e/staking/test/remove-stake.test.ts @@ -10,7 +10,6 @@ import { addStake, removeStake, getStake, - getStakeRaw, tao, log, } from "e2e-shared"; @@ -42,7 +41,7 @@ describe("▶ remove_stake extrinsic", () => { expect(stakeBefore, "Should have stake before removal").toBeGreaterThan(0n); // Remove stake (amount is in alpha units - use raw U64F64 value) - const stakeRaw = await getStakeRaw(api, hotkeyAddress, coldkeyAddress, netuid); + const stakeRaw = await getStake(api, hotkeyAddress, coldkeyAddress, netuid); const unstakeAmount = stakeRaw / 2n; await removeStake(api, coldkey, hotkeyAddress, netuid, unstakeAmount); diff --git a/e2e/staking/test/swap-stake-limit.test.ts b/e2e/staking/test/swap-stake-limit.test.ts index 316ddff051..0b60ea113b 100644 --- a/e2e/staking/test/swap-stake-limit.test.ts +++ b/e2e/staking/test/swap-stake-limit.test.ts @@ -10,7 +10,6 @@ import { addStake, swapStakeLimit, getStake, - getStakeRaw, tao, log, } from "e2e-shared"; @@ -54,7 +53,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Swap stake with limit price (0.99 TAO relative price limit, allow partial fills) // Use raw U64F64 value for the extrinsic - const stake1Raw = await getStakeRaw(api, hotkey1Address, coldkeyAddress, netuid1); + const stake1Raw = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const swapAmount = stake1Raw / 2n; const limitPrice = (tao(1) * 99n) / 100n; // 0.99 TAO await swapStakeLimit(api, coldkey, hotkey1Address, netuid1, netuid2, swapAmount, limitPrice, true); @@ -109,7 +108,7 @@ describe("▶ swap_stake_limit extrinsic", () => { // Swap stake with limit price (fill or kill mode - allow_partial = false) // Use raw U64F64 value for the extrinsic - const stake1Raw = await getStakeRaw(api, hotkey1Address, coldkeyAddress, netuid1); + const stake1Raw = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const swapAmount = stake1Raw / 2n; const limitPrice = tao(1) / 10n; // 0.1 TAO - permissive limit to allow slippage await swapStakeLimit(api, coldkey, hotkey1Address, netuid1, netuid2, swapAmount, limitPrice, false); diff --git a/e2e/staking/test/swap-stake.test.ts b/e2e/staking/test/swap-stake.test.ts index 44a818dd81..aa284bd9a4 100644 --- a/e2e/staking/test/swap-stake.test.ts +++ b/e2e/staking/test/swap-stake.test.ts @@ -10,7 +10,7 @@ import { addStake, swapStake, getStake, - getStakeRaw, + getStake, tao, log, } from "e2e-shared"; @@ -54,7 +54,7 @@ describe("▶ swap_stake extrinsic", () => { // Swap half the stake from subnet1 to subnet2 // Use raw U64F64 value for the extrinsic - const stake1Raw = await getStakeRaw(api, hotkey1Address, coldkeyAddress, netuid1); + const stake1Raw = await getStake(api, hotkey1Address, coldkeyAddress, netuid1); const swapAmount = stake1Raw / 2n; await swapStake(api, coldkey, hotkey1Address, netuid1, netuid2, swapAmount); diff --git a/e2e/staking/test/transfer-stake.test.ts b/e2e/staking/test/transfer-stake.test.ts index 330ca0b8d9..b8daf665d7 100644 --- a/e2e/staking/test/transfer-stake.test.ts +++ b/e2e/staking/test/transfer-stake.test.ts @@ -9,7 +9,6 @@ import { addStake, transferStake, getStake, - getStakeRaw, tao, log, } from "e2e-shared"; @@ -55,7 +54,7 @@ describe("▶ transfer_stake extrinsic", () => { // Transfer stake to destination coldkey on a different subnet // Use raw U64F64 value for the extrinsic - const originStakeRaw = await getStakeRaw(api, hotkey1Address, originColdkeyAddress, netuid1); + const originStakeRaw = await getStake(api, hotkey1Address, originColdkeyAddress, netuid1); const transferAmount = originStakeRaw / 2n; await transferStake( api, @@ -110,7 +109,7 @@ describe("▶ transfer_stake extrinsic", () => { // Transfer stake to destination coldkey // Use raw U64F64 value for the extrinsic, transfer half to avoid AmountTooLow error - const originStakeRaw = await getStakeRaw(api, hotkeyAddress, originColdkeyAddress, netuid); + const originStakeRaw = await getStake(api, hotkeyAddress, originColdkeyAddress, netuid); const transferAmount = originStakeRaw / 2n; await transferStake(api, originColdkey, destinationColdkeyAddress, hotkeyAddress, netuid, netuid, transferAmount);