Skip to content

Commit d696695

Browse files
committed
fix test
1 parent 63d0436 commit d696695

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

pallets/subtensor/src/tests/children.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::mock::*;
55
use approx::assert_abs_diff_eq;
66
use frame_support::{assert_err, assert_noop, assert_ok};
7-
use substrate_fixed::types::I96F32;
7+
use substrate_fixed::types::{I64F64, I96F32};
88

99
use crate::{utils::rate_limiting::TransactionType, *};
1010
use sp_core::U256;
@@ -2852,13 +2852,23 @@ fn test_set_weights_no_parent() {
28522852
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
28532853
let version_key = SubtensorModule::get_weights_version_key(netuid);
28542854

2855-
// Set the min stake very high
2856-
SubtensorModule::set_stake_threshold(stake_to_give_child * 5);
2855+
// Check the stake weight
2856+
let curr_stake_weight =
2857+
SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0;
2858+
2859+
// Set the min stake very high, above the stake weight of the key
2860+
SubtensorModule::set_stake_threshold(
2861+
curr_stake_weight
2862+
.saturating_mul(I64F64::saturating_from_num(5))
2863+
.saturating_to_num::<u64>(),
2864+
);
28572865

2858-
// Check the key has less stake than required
2866+
let curr_stake_threshold = SubtensorModule::get_stake_threshold();
28592867
assert!(
2860-
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2861-
< SubtensorModule::get_stake_threshold()
2868+
curr_stake_weight < curr_stake_threshold,
2869+
"{:?} is not less than {:?} ",
2870+
curr_stake_weight,
2871+
curr_stake_threshold
28622872
);
28632873

28642874
// Check the hotkey cannot set weights
@@ -2876,12 +2886,21 @@ fn test_set_weights_no_parent() {
28762886
assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid));
28772887

28782888
// Set a minimum stake to set weights
2879-
SubtensorModule::set_stake_threshold(stake_to_give_child - 5);
2889+
SubtensorModule::set_stake_threshold(
2890+
curr_stake_weight
2891+
.saturating_sub(I64F64::saturating_from_num(5))
2892+
.saturating_to_num::<u64>(),
2893+
);
28802894

28812895
// Check if the stake for the hotkey is above
2896+
let new_stake_weight =
2897+
SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0;
2898+
let new_stake_threshold = SubtensorModule::get_stake_threshold();
28822899
assert!(
2883-
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
2884-
>= SubtensorModule::get_stake_threshold()
2900+
new_stake_weight >= new_stake_threshold,
2901+
"{:?} is not greater than or equal to {:?} ",
2902+
new_stake_weight,
2903+
new_stake_threshold
28852904
);
28862905

28872906
// Check the hotkey can set weights

0 commit comments

Comments
 (0)