Skip to content

Commit d9279fb

Browse files
committed
Update children::test_set_weights_no_parent
1 parent c9d0b6f commit d9279fb

File tree

1 file changed

+59
-60
lines changed

1 file changed

+59
-60
lines changed

pallets/subtensor/src/tests/children.rs

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,83 +2737,82 @@ fn test_childkey_set_weights_single_parent() {
27372737
fn test_set_weights_no_parent() {
27382738
// Verify that a regular key without a parent delegation is effected by the minimum stake requirements
27392739
new_test_ext(1).execute_with(|| {
2740-
assert!(false);
2740+
let netuid: u16 = 1;
2741+
add_network(netuid, 1, 0);
27412742

2742-
// let netuid: u16 = 1;
2743-
// add_network(netuid, 1, 0);
2743+
let hotkey: U256 = U256::from(2);
2744+
let spare_hk: U256 = U256::from(3);
27442745

2745-
// let hotkey: U256 = U256::from(2);
2746-
// let spare_hk: U256 = U256::from(3);
2746+
let coldkey: U256 = U256::from(101);
2747+
let spare_ck = U256::from(102);
27472748

2748-
// let coldkey: U256 = U256::from(101);
2749-
// let spare_ck = U256::from(102);
2749+
let stake_to_give_child = 109_999;
27502750

2751-
// let stake_to_give_child = 109_999;
2751+
SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_to_give_child + 10);
27522752

2753-
// SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_to_give_child + 10);
2753+
// Is registered
2754+
register_ok_neuron(netuid, hotkey, coldkey, 1);
2755+
// Register a spare key
2756+
register_ok_neuron(netuid, spare_hk, spare_ck, 1);
27542757

2755-
// // Is registered
2756-
// register_ok_neuron(netuid, hotkey, coldkey, 1);
2757-
// // Register a spare key
2758-
// register_ok_neuron(netuid, spare_hk, spare_ck, 1);
2758+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
2759+
&hotkey,
2760+
&coldkey,
2761+
netuid,
2762+
stake_to_give_child,
2763+
);
27592764

2760-
// SubtensorModule::increase_stake_on_coldkey_hotkey_account(
2761-
// &coldkey,
2762-
// &hotkey,
2763-
// stake_to_give_child,
2764-
// );
2765+
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
27652766

2766-
// SubtensorModule::set_weights_set_rate_limit(netuid, 0);
2767+
// Has stake and no parent
2768+
step_block(7200 + 1);
27672769

2768-
// // Has stake and no parent
2769-
// step_block(7200 + 1);
2770+
let uids: Vec<u16> = vec![1]; // Set weights on the other hotkey
2771+
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
2772+
let version_key = SubtensorModule::get_weights_version_key(netuid);
27702773

2771-
// let uids: Vec<u16> = vec![1]; // Set weights on the other hotkey
2772-
// let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
2773-
// let version_key = SubtensorModule::get_weights_version_key(netuid);
2774+
// Set the min stake very high
2775+
SubtensorModule::set_stake_threshold(stake_to_give_child * 5);
27742776

2775-
// // Set the min stake very high
2776-
// SubtensorModule::set_stake_threshold(stake_to_give_child * 5);
2777-
2778-
// // Check the key has less stake than required
2779-
// assert!(
2780-
// SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2781-
// < SubtensorModule::get_stake_threshold()
2782-
// );
2777+
// Check the key has less stake than required
2778+
assert!(
2779+
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2780+
< SubtensorModule::get_stake_threshold()
2781+
);
27832782

2784-
// // Check the hotkey cannot set weights
2785-
// assert_noop!(
2786-
// SubtensorModule::set_weights(
2787-
// RuntimeOrigin::signed(hotkey),
2788-
// netuid,
2789-
// uids.clone(),
2790-
// values.clone(),
2791-
// version_key
2792-
// ),
2793-
// Error::<Test>::NotEnoughStakeToSetWeights
2794-
// );
2783+
// Check the hotkey cannot set weights
2784+
assert_noop!(
2785+
SubtensorModule::set_weights(
2786+
RuntimeOrigin::signed(hotkey),
2787+
netuid,
2788+
uids.clone(),
2789+
values.clone(),
2790+
version_key
2791+
),
2792+
Error::<Test>::NotEnoughStakeToSetWeights
2793+
);
27952794

2796-
// assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid));
2795+
assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid));
27972796

2798-
// // Set a minimum stake to set weights
2799-
// SubtensorModule::set_stake_threshold(stake_to_give_child - 5);
2797+
// Set a minimum stake to set weights
2798+
SubtensorModule::set_stake_threshold(stake_to_give_child - 5);
28002799

2801-
// // Check if the stake for the hotkey is above
2802-
// assert!(
2803-
// SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2804-
// >= SubtensorModule::get_stake_threshold()
2805-
// );
2800+
// Check if the stake for the hotkey is above
2801+
assert!(
2802+
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2803+
>= SubtensorModule::get_stake_threshold()
2804+
);
28062805

2807-
// // Check the hotkey can set weights
2808-
// assert_ok!(SubtensorModule::set_weights(
2809-
// RuntimeOrigin::signed(hotkey),
2810-
// netuid,
2811-
// uids,
2812-
// values,
2813-
// version_key
2814-
// ));
2806+
// Check the hotkey can set weights
2807+
assert_ok!(SubtensorModule::set_weights(
2808+
RuntimeOrigin::signed(hotkey),
2809+
netuid,
2810+
uids,
2811+
values,
2812+
version_key
2813+
));
28152814

2816-
// assert!(SubtensorModule::check_weights_min_stake(&hotkey, netuid));
2815+
assert!(SubtensorModule::check_weights_min_stake(&hotkey, netuid));
28172816
});
28182817
}
28192818

0 commit comments

Comments
 (0)