Skip to content

Commit 8604e9b

Browse files
committed
add swap tests
1 parent 2f3c927 commit 8604e9b

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

pallets/subtensor/src/tests/swap_coldkey.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,3 +2619,37 @@ fn test_coldkey_in_swap_schedule_prevents_critical_calls() {
26192619
);
26202620
});
26212621
}
2622+
2623+
#[test]
2624+
fn test_swap_auto_stake_destination_coldkeys() {
2625+
new_test_ext(1).execute_with(|| {
2626+
let old_coldkey = U256::from(1);
2627+
let new_coldkey = U256::from(2);
2628+
let hotkey = U256::from(3);
2629+
let netuid = NetUid::from(1u16);
2630+
let coldkeys = vec![U256::from(4), U256::from(5), old_coldkey];
2631+
2632+
add_network(netuid, 1, 0);
2633+
AutoStakeDestinationColdkeys::<Test>::insert(hotkey, netuid, coldkeys.clone());
2634+
AutoStakeDestination::<Test>::insert(old_coldkey, netuid, hotkey);
2635+
2636+
let mut weight = Weight::zero();
2637+
assert_ok!(SubtensorModule::perform_swap_coldkey(
2638+
&old_coldkey,
2639+
&new_coldkey,
2640+
&mut weight
2641+
));
2642+
2643+
let new_coldkeys = AutoStakeDestinationColdkeys::<Test>::get(hotkey, netuid);
2644+
assert!(new_coldkeys.contains(&new_coldkey));
2645+
assert!(!new_coldkeys.contains(&old_coldkey));
2646+
assert_eq!(
2647+
AutoStakeDestination::<Test>::try_get(old_coldkey, netuid),
2648+
None
2649+
);
2650+
assert_eq!(
2651+
AutoStakeDestination::<Test>::try_get(new_coldkey, netuid),
2652+
Some(hotkey)
2653+
);
2654+
});
2655+
}

pallets/subtensor/src/tests/swap_hotkey.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,3 +1465,39 @@ fn test_swap_hotkey_swap_rate_limits() {
14651465
);
14661466
});
14671467
}
1468+
1469+
#[test]
1470+
fn test_swap_auto_stake_destination_coldkeys() {
1471+
new_test_ext(1).execute_with(|| {
1472+
let old_hotkey = U256::from(1);
1473+
let new_hotkey = U256::from(2);
1474+
let coldkey = U256::from(3);
1475+
let netuid = NetUid::from(0u16);
1476+
let coldkeys = vec![U256::from(4), U256::from(5)];
1477+
let mut weight = Weight::zero();
1478+
1479+
// Initialize ChildKeys for old_hotkey
1480+
add_network(netuid, 1, 0);
1481+
AutoStakeDestinationColdkeys::<Test>::insert(old_hotkey, netuid, coldkeys.clone());
1482+
AutoStakeDestination::<Test>::insert(coldkey, netuid, old_hotkey);
1483+
1484+
// Perform the swap
1485+
SubtensorModule::perform_hotkey_swap_on_all_subnets(
1486+
&old_hotkey,
1487+
&new_hotkey,
1488+
&coldkey,
1489+
&mut weight,
1490+
);
1491+
1492+
// Verify the swap
1493+
assert_eq!(
1494+
AutoStakeDestinationColdkeys::<Test>::get(new_hotkey, netuid),
1495+
coldkeys
1496+
);
1497+
assert!(AutoStakeDestinationColdkeys::<Test>::get(old_hotkey, netuid).is_empty());
1498+
assert_eq!(
1499+
AutoStakeDestination::<Test>::get(coldkey, netuid),
1500+
new_hotkey
1501+
);
1502+
});
1503+
}

0 commit comments

Comments
 (0)