Skip to content

Commit 7f375f9

Browse files
committed
remove stake with existing function
1 parent 610dbf7 commit 7f375f9

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

pallets/subtensor/src/coinbase/root.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ impl<T: Config> Pallet<T> {
11591159

11601160
for (staking_key, hotkey, coldkey, stake) in stake_entries {
11611161
Self::add_balance_to_coldkey_account(&staking_key, stake);
1162-
<Stake<T>>::remove(&hotkey, &coldkey);
1162+
Self::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, stake);
11631163
}
11641164

11651165
// --- 3. Remove network count.

pallets/subtensor/tests/root.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,7 @@ fn test_dissolve_network_unstake_nominators_ok() {
10131013

10141014
// Check that the balance was correctly updated and the stake was removed
10151015
assert_eq!(new_balance, initial_balance + stake);
1016-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1017-
hotkey, coldkey
1018-
));
1016+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey, coldkey), 0);
10191017
});
10201018
}
10211019

@@ -1061,9 +1059,7 @@ fn test_dissolve_network_unstake_delegate_ok() {
10611059

10621060
// Check that the delegate's balance was correctly updated and the stake was removed
10631061
assert_eq!(new_delegate_balance, initial_delegate_balance + stake);
1064-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1065-
hotkey, coldkey
1066-
));
1062+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey, coldkey), 0);
10671063
});
10681064
}
10691065

@@ -1107,12 +1103,11 @@ fn test_dissolve_network_unstake_nominators_and_delegates_partial_match() {
11071103
// Check that only the second network's stake was removed and balance updated
11081104
assert_eq!(new_balance1, initial_balance1);
11091105
assert_eq!(new_balance2, initial_balance2 + stake2); // Only change for hotkey2
1110-
assert!(<pallet_subtensor::Stake<Test>>::contains_key(
1111-
hotkey1, coldkey1
1112-
));
1113-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1114-
hotkey2, coldkey2
1115-
));
1106+
assert_eq!(
1107+
<pallet_subtensor::Stake<Test>>::get(hotkey1, coldkey1),
1108+
stake1
1109+
);
1110+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey2, coldkey2), 0);
11161111
});
11171112
}
11181113

@@ -1150,12 +1145,8 @@ fn test_dissolve_network_unstake_multiple_stakes_same_hotkey() {
11501145
// Check that both stakes were removed and the balances updated
11511146
assert_eq!(new_balance1, initial_balance1 + stake1);
11521147
assert_eq!(new_balance2, initial_balance2 + stake2);
1153-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1154-
hotkey, coldkey1
1155-
));
1156-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1157-
hotkey, coldkey2
1158-
));
1148+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey, coldkey1), 0);
1149+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey, coldkey2), 0);
11591150
});
11601151
}
11611152

@@ -1291,10 +1282,7 @@ fn test_dissolve_network_complex_state() {
12911282
);
12921283

12931284
assert_eq!(new_balance, stake + initial_balances[i]);
1294-
1295-
assert!(!<pallet_subtensor::Stake<Test>>::contains_key(
1296-
hotkey, coldkey
1297-
));
1285+
assert_eq!(<pallet_subtensor::Stake<Test>>::get(hotkey, coldkey), 0);
12981286
}
12991287
});
13001288
}

0 commit comments

Comments
 (0)