Skip to content

Commit 6b16ec3

Browse files
committed
Add dest hotkey check and test
1 parent b76d155 commit 6b16ec3

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,12 @@ impl<T: Config> Pallet<T> {
987987
Error::<T>::HotKeyAccountNotExists
988988
);
989989

990+
// Ensure that the destination hotkey account exists
991+
ensure!(
992+
Self::hotkey_account_exists(destination_hotkey),
993+
Error::<T>::HotKeyAccountNotExists
994+
);
995+
990996
// Ensure there is enough stake in the origin subnet.
991997
let origin_alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet(
992998
origin_hotkey,

pallets/subtensor/src/tests/move_stake.rs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,64 @@ fn test_do_move_nonexistent_origin_hotkey() {
231231
});
232232
}
233233

234+
// // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test move -- test_do_move_nonexistent_destination_hotkey --exact --nocapture
235+
// #[test]
236+
// fn test_do_move_nonexistent_destination_hotkey() {
237+
// new_test_ext(1).execute_with(|| {
238+
// let subnet_owner_coldkey = U256::from(1001);
239+
// let subnet_owner_hotkey = U256::from(1002);
240+
// let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
241+
// let coldkey = U256::from(1);
242+
// let origin_hotkey = U256::from(99); // Assuming this hotkey doesn't exist
243+
// let nonexistent_destination_hotkey = U256::from(3);
244+
245+
// // Set up initial stake
246+
// SubtensorModule::stake_into_subnet(
247+
// &origin_hotkey,
248+
// &coldkey,
249+
// origin_netuid,
250+
// stake_amount,
251+
// fee,
252+
// );
253+
// let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
254+
// &origin_hotkey,
255+
// &coldkey,
256+
// origin_netuid,
257+
// );
258+
259+
// // Attempt to move stake from a non-existent origin hotkey
260+
// assert_noop!(
261+
// SubtensorModule::do_move_stake(
262+
// RuntimeOrigin::signed(coldkey),
263+
// origin_hotkey,
264+
// nonexistent_destination_hotkey,
265+
// netuid,
266+
// netuid,
267+
// alpha
268+
// ),
269+
// Error::<Test>::HotKeyAccountNotExists
270+
// );
271+
272+
// // Check that no stake was moved
273+
// assert_eq!(
274+
// SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
275+
// &origin_hotkey,
276+
// &coldkey,
277+
// netuid
278+
// ),
279+
// alpha
280+
// );
281+
// assert_eq!(
282+
// SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
283+
// &nonexistent_destination_hotkey,
284+
// &coldkey,
285+
// netuid
286+
// ),
287+
// 0
288+
// );
289+
// });
290+
// }
291+
234292
// 6. test_do_move_nonexistent_destination_hotkey
235293
// Description: Attempt to move stake to a non-existent destination hotkey, which should fail
236294
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test move -- test_do_move_nonexistent_destination_hotkey --exact --nocapture
@@ -245,7 +303,9 @@ fn test_do_move_nonexistent_destination_hotkey() {
245303
let fee = 0;
246304

247305
// Set up initial stake
248-
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, netuid, stake_amount, fee);
306+
SubtensorModule::create_account_if_non_existent(&coldkey, &origin_hotkey);
307+
let alpha =
308+
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, netuid, stake_amount, fee);
249309

250310
// Attempt to move stake from a non-existent origin hotkey
251311
add_network(netuid, 1, 0);
@@ -256,12 +316,12 @@ fn test_do_move_nonexistent_destination_hotkey() {
256316
nonexistent_destination_hotkey,
257317
netuid,
258318
netuid,
259-
1234
319+
alpha
260320
),
261321
Error::<Test>::HotKeyAccountNotExists
262322
);
263323

264-
// Check that the stake was moved successfully
324+
// Check that the stake was not moved
265325
assert_eq!(
266326
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
267327
&origin_hotkey,

0 commit comments

Comments
 (0)