Skip to content

Commit de5d1cb

Browse files
committed
Add 1000 rao min stake - tests in progress
1 parent 966a1a9 commit de5d1cb

File tree

6 files changed

+98
-217
lines changed

6 files changed

+98
-217
lines changed

pallets/admin-utils/src/tests/mod.rs

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -931,136 +931,6 @@ mod sudo_set_nominator_min_required_stake {
931931
);
932932
});
933933
}
934-
935-
#[test]
936-
fn clears_staker_nominations_below_min() {
937-
new_test_ext().execute_with(|| {
938-
System::set_block_number(1);
939-
940-
// Create accounts.
941-
let netuid = 1;
942-
let hot1 = U256::from(1);
943-
let hot2 = U256::from(2);
944-
let cold1 = U256::from(3);
945-
let cold2 = U256::from(4);
946-
947-
// SubtensorModule::set_target_stakes_per_interval(10);
948-
// Register network.
949-
add_network(netuid, 0);
950-
951-
// Register hot1.
952-
register_ok_neuron(netuid, hot1, cold1, 0);
953-
assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1);
954-
955-
// Register hot2.
956-
register_ok_neuron(netuid, hot2, cold2, 0);
957-
assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2);
958-
959-
// Add stake cold1 --> hot1 (non delegation.)
960-
SubtensorModule::add_balance_to_coldkey_account(&cold1, 5);
961-
assert_ok!(SubtensorModule::add_stake(
962-
<<Test as Config>::RuntimeOrigin>::signed(cold1),
963-
hot1,
964-
netuid,
965-
1
966-
));
967-
assert_eq!(
968-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold1, netuid),
969-
1
970-
);
971-
assert_eq!(Balances::free_balance(cold1), 4);
972-
973-
// Add stake cold2 --> hot1 (is delegation.)
974-
SubtensorModule::add_balance_to_coldkey_account(&cold2, 5);
975-
assert_ok!(SubtensorModule::add_stake(
976-
<<Test as Config>::RuntimeOrigin>::signed(cold2),
977-
hot1,
978-
netuid,
979-
1
980-
));
981-
assert_eq!(
982-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold2, netuid),
983-
1
984-
);
985-
assert_eq!(Balances::free_balance(cold2), 4);
986-
987-
// Add stake cold1 --> hot2
988-
SubtensorModule::add_balance_to_coldkey_account(&cold1, 5);
989-
assert_ok!(SubtensorModule::add_stake(
990-
<<Test as Config>::RuntimeOrigin>::signed(cold1),
991-
hot2,
992-
netuid,
993-
1
994-
));
995-
assert_eq!(
996-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold1, netuid),
997-
1
998-
);
999-
assert_eq!(Balances::free_balance(cold1), 8);
1000-
1001-
// Add stake cold2 --> hot2
1002-
SubtensorModule::add_balance_to_coldkey_account(&cold2, 5);
1003-
assert_ok!(SubtensorModule::add_stake(
1004-
<<Test as Config>::RuntimeOrigin>::signed(cold2),
1005-
hot2,
1006-
netuid,
1007-
1
1008-
));
1009-
assert_eq!(
1010-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold2, netuid),
1011-
1
1012-
);
1013-
assert_eq!(Balances::free_balance(cold2), 8);
1014-
1015-
// Set min stake to 0 (noop)
1016-
assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake(
1017-
<<Test as Config>::RuntimeOrigin>::root(),
1018-
0u64
1019-
));
1020-
assert_eq!(
1021-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold1, netuid),
1022-
1
1023-
);
1024-
assert_eq!(
1025-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold1, netuid),
1026-
1
1027-
);
1028-
assert_eq!(
1029-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold2, netuid),
1030-
1
1031-
);
1032-
assert_eq!(
1033-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold2, netuid),
1034-
1
1035-
);
1036-
1037-
// Set min nomination to 10: should clear (cold2, hot1) and (cold1, hot2).
1038-
assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake(
1039-
<<Test as Config>::RuntimeOrigin>::root(),
1040-
10u64
1041-
));
1042-
assert_eq!(
1043-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold1, netuid),
1044-
1
1045-
);
1046-
assert_eq!(
1047-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold1, netuid),
1048-
0
1049-
);
1050-
assert_eq!(
1051-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot1, &cold2, netuid),
1052-
0
1053-
);
1054-
assert_eq!(
1055-
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hot2, &cold2, netuid),
1056-
1
1057-
);
1058-
1059-
// Balances have been added back into accounts.
1060-
assert_eq!(Balances::free_balance(cold1), 9);
1061-
assert_eq!(Balances::free_balance(cold2), 9);
1062-
});
1063-
}
1064934
}
1065935

1066936
#[test]

pallets/subtensor/src/staking/add_stake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<T: Config> Pallet<T> {
6262
Error::<T>::HotKeyAccountNotExists
6363
);
6464

65-
// Ensure stake_to_ve_added is at least DefaultMinStake
65+
// Ensure stake_to_be_added is at least DefaultMinStake
6666
ensure!(
6767
stake_to_be_added >= DefaultMinStake::<T>::get(),
6868
Error::<T>::AmountTooLow

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
// use substrate_fixed::types::I96F32;
2+
use sp_core::Get;
33

44
impl<T: Config> Pallet<T> {
55
/// Moves stake from one hotkey to another across subnets.
@@ -75,6 +75,12 @@ impl<T: Config> Pallet<T> {
7575
alpha_amount,
7676
);
7777

78+
// Ensure origin_tao is at least DefaultMinStake
79+
ensure!(
80+
origin_tao >= DefaultMinStake::<T>::get(),
81+
Error::<T>::AmountTooLow
82+
);
83+
7884
// --- 8. Stake the resulting TAO into the destination subnet for the destination hotkey
7985
Self::stake_into_subnet(
8086
&destination_hotkey.clone(),

0 commit comments

Comments
 (0)