Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contract-tests/test/alphaPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Collaborator

@evgeny-s evgeny-s Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't update the assertion logic, but instead we need to get the value from alphaV2. Check this PR for more details.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! will update it.

assert.ok(stakeFromContract > tao(20))
})

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions contract-tests/test/staking.precompile.add-remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions contract-tests/test/staking.precompile.full-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("Test staking precompile add remove limit methods", () => {
netuid,
);

assert.ok(alphaAfterRemoveStake < alpha);
assert.ok(alphaAfterRemoveStake <= alpha);
});
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("Test staking precompile add remove limit methods", () => {
netuid,
);

assert.ok(alphaAfterRemoveStake < alpha);
assert.ok(alphaAfterRemoveStake <= alpha);
});
});
});
4 changes: 2 additions & 2 deletions contract-tests/test/staking.precompile.limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -108,6 +108,6 @@ describe("Test staking precompile add remove limit methods", () => {
netuid,
);

assert.ok(alphaAfterRemoveStake < alpha);
assert.ok(alphaAfterRemoveStake <= alpha);
});
});
4 changes: 2 additions & 2 deletions e2e/staking/test/add-stake-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).");
});
Expand All @@ -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).");
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/staking/test/add-stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/staking/test/claim-root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/staking/test/move-stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand All @@ -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.");
});
Expand Down
8 changes: 4 additions & 4 deletions e2e/staking/test/remove-stake-full-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.");
});
Expand All @@ -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);
Expand All @@ -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.");
});
Expand Down
8 changes: 4 additions & 4 deletions e2e/staking/test/swap-stake-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand All @@ -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).");
});
Expand Down Expand Up @@ -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}`);

Expand Down
2 changes: 1 addition & 1 deletion e2e/staking/test/transfer-stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
4 changes: 2 additions & 2 deletions e2e/staking/test/unstake-all-alpha.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions e2e/staking/test/unstake-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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.");
});
Expand Down
Loading