Skip to content

Commit 97e5a30

Browse files
Rapiiidoooclaude
andcommitted
test: add disassociate_hotkey test for AlphaV2 stake check
Ensures disassociation is blocked when stake exists in the new AlphaV2 storage map (SafeFloat format), not just the legacy Alpha map. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 796e053 commit 97e5a30

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

pallets/subtensor/src/tests/staking2.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use frame_support::{
55
dispatch::{GetDispatchInfo, Pays},
66
weights::Weight,
77
};
8+
use share_pool::SafeFloat;
89
use sp_core::U256;
910
use subtensor_runtime_common::{AlphaBalance, TaoBalance, Token};
1011
use subtensor_swap_interface::SwapHandler;
@@ -771,6 +772,34 @@ fn test_disassociate_hotkey_has_stake() {
771772
});
772773
}
773774

775+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::staking2::test_disassociate_hotkey_has_stake_alpha_v2 --exact --show-output --nocapture
776+
#[test]
777+
fn test_disassociate_hotkey_has_stake_alpha_v2() {
778+
new_test_ext(1).execute_with(|| {
779+
let hotkey1 = U256::from(1);
780+
let coldkey1 = U256::from(2);
781+
let netuid = NetUid::from(1);
782+
783+
// Associate hotkey1 with coldkey1
784+
assert_ok!(SubtensorModule::try_associate_hotkey(
785+
RuntimeOrigin::signed(coldkey1),
786+
hotkey1
787+
));
788+
789+
// Add some AlphaV2 (new format) stake for this hotkey
790+
AlphaV2::<Test>::insert((&hotkey1, &coldkey1, netuid), SafeFloat::from(1000_u64));
791+
792+
// Try to disassociate - should fail because has outstanding stake in AlphaV2
793+
assert_noop!(
794+
SubtensorModule::disassociate_hotkey(RuntimeOrigin::signed(coldkey1), hotkey1),
795+
Error::<Test>::HotkeyHasOutstandingStake
796+
);
797+
798+
// Verify hotkey is still associated
799+
assert!(SubtensorModule::hotkey_account_exists(&hotkey1));
800+
});
801+
}
802+
774803
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::staking2::test_disassociate_hotkey_reassociate --exact --show-output --nocapture
775804
#[test]
776805
fn test_disassociate_hotkey_reassociate() {

0 commit comments

Comments
 (0)