Skip to content

Commit a0b87da

Browse files
committed
add test for regular keys to prevent regression
1 parent eea8d1a commit a0b87da

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

pallets/subtensor/tests/children.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,3 +3345,86 @@ fn test_childkey_set_weights_single_parent() {
33453345
assert!(SubtensorModule::check_weights_min_stake(&child, netuid));
33463346
});
33473347
}
3348+
3349+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test children -- test_set_weights_no_parent --exact --nocapture
3350+
#[test]
3351+
fn test_set_weights_no_parent() {
3352+
// Verify that a regular key without a parent delegation is effected by the minimum stake requirements
3353+
new_test_ext(1).execute_with(|| {
3354+
let netuid: u16 = 1;
3355+
add_network(netuid, 1, 0);
3356+
3357+
let hotkey: U256 = U256::from(2);
3358+
let spare_hk: U256 = U256::from(3);
3359+
3360+
let coldkey: U256 = U256::from(101);
3361+
let spare_ck = U256::from(102);
3362+
3363+
let stake_to_give_child = 109_999;
3364+
3365+
SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_to_give_child + 10);
3366+
3367+
// Is registered
3368+
register_ok_neuron(netuid, hotkey, coldkey, 1);
3369+
// Register a spare key
3370+
register_ok_neuron(netuid, spare_hk, spare_ck, 1);
3371+
3372+
SubtensorModule::increase_stake_on_coldkey_hotkey_account(
3373+
&coldkey,
3374+
&hotkey,
3375+
stake_to_give_child,
3376+
);
3377+
3378+
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
3379+
3380+
// Has stake and no parent
3381+
step_block(7200 + 1);
3382+
3383+
let uids: Vec<u16> = vec![1]; // Set weights on the other hotkey
3384+
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
3385+
let version_key = SubtensorModule::get_weights_version_key(netuid);
3386+
3387+
// Set the min stake very high
3388+
SubtensorModule::set_weights_min_stake(stake_to_give_child * 5);
3389+
3390+
// Check the key has less stake than required
3391+
assert!(
3392+
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
3393+
< SubtensorModule::get_weights_min_stake()
3394+
);
3395+
3396+
// Check the hotkey cannot set weights
3397+
assert_noop!(
3398+
SubtensorModule::set_weights(
3399+
RuntimeOrigin::signed(hotkey),
3400+
netuid,
3401+
uids.clone(),
3402+
values.clone(),
3403+
version_key
3404+
),
3405+
Error::<Test>::NotEnoughStakeToSetWeights
3406+
);
3407+
3408+
assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid));
3409+
3410+
// Set a minimum stake to set weights
3411+
SubtensorModule::set_weights_min_stake(stake_to_give_child - 5);
3412+
3413+
// Check if the stake for the hotkey is above
3414+
assert!(
3415+
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
3416+
>= SubtensorModule::get_weights_min_stake()
3417+
);
3418+
3419+
// Check the hotkey can set weights
3420+
assert_ok!(SubtensorModule::set_weights(
3421+
RuntimeOrigin::signed(hotkey),
3422+
netuid,
3423+
uids,
3424+
values,
3425+
version_key
3426+
));
3427+
3428+
assert!(SubtensorModule::check_weights_min_stake(&hotkey, netuid));
3429+
});
3430+
}

0 commit comments

Comments
 (0)