Skip to content

Commit 8957f3d

Browse files
committed
Fix tests after raising min stake to 2_000_000 rao
1 parent 77f0375 commit 8957f3d

File tree

9 files changed

+237
-200
lines changed

9 files changed

+237
-200
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,9 @@ pub mod pallet {
703703

704704
#[pallet::type_value]
705705
/// Default minimum stake.
706+
/// 2M rao matches $1 at $500/TAO
706707
pub fn DefaultMinStake<T: Config>() -> u64 {
707-
1_000
708+
2_000_000
708709
}
709710

710711
#[pallet::type_value]

pallets/subtensor/src/tests/children.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,28 +3058,36 @@ fn test_childkey_multiple_parents_emission() {
30583058

30593059
// Register neurons and add initial stakes
30603060
let initial_stakes: Vec<(bool, U256, U256, u64)> = vec![
3061-
(false, coldkey_parent1, parent1, 200_000),
3062-
(true, coldkey_parent2, parent2, 150_000),
3063-
(true, coldkey_child, child, 20_000),
3064-
(true, coldkey_weight_setter, weight_setter, 100_000),
3061+
(false, coldkey_parent1, parent1, 200_000_000),
3062+
(true, coldkey_parent2, parent2, 150_000_000),
3063+
(true, coldkey_child, child, 20_000_000),
3064+
(true, coldkey_weight_setter, weight_setter, 100_000_000),
30653065
];
30663066

3067-
for (register, coldkey, hotkey, stake) in initial_stakes.iter() {
3068-
SubtensorModule::add_balance_to_coldkey_account(coldkey, *stake);
3069-
if *register {
3070-
// Register a neuron
3071-
register_ok_neuron(netuid, *hotkey, *coldkey, 0);
3072-
} else {
3073-
// Just create hotkey account
3074-
SubtensorModule::create_account_if_non_existent(coldkey, hotkey);
3075-
}
3076-
assert_ok!(SubtensorModule::add_stake(
3077-
RuntimeOrigin::signed(*coldkey),
3078-
*hotkey,
3079-
netuid,
3080-
*stake
3081-
));
3082-
}
3067+
let initial_actual_stakes: Vec<u64> = initial_stakes
3068+
.iter()
3069+
.map(|(register, coldkey, hotkey, stake)| {
3070+
SubtensorModule::add_balance_to_coldkey_account(coldkey, *stake);
3071+
if *register {
3072+
// Register a neuron
3073+
register_ok_neuron(netuid, *hotkey, *coldkey, 0);
3074+
} else {
3075+
// Just create hotkey account
3076+
SubtensorModule::create_account_if_non_existent(coldkey, hotkey);
3077+
}
3078+
assert_ok!(SubtensorModule::add_stake(
3079+
RuntimeOrigin::signed(*coldkey),
3080+
*hotkey,
3081+
netuid,
3082+
*stake
3083+
));
3084+
3085+
// Return actual stake
3086+
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
3087+
&hotkey, &coldkey, netuid,
3088+
)
3089+
})
3090+
.collect();
30833091

30843092
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
30853093
step_block(2);
@@ -3152,23 +3160,26 @@ fn test_childkey_multiple_parents_emission() {
31523160
);
31533161

31543162
assert!(
3155-
parent1_stake > 200_000,
3163+
parent1_stake > initial_actual_stakes[0],
31563164
"Parent1 should have received emission"
31573165
);
31583166
assert!(
3159-
parent2_stake > 150_000,
3167+
parent2_stake > initial_actual_stakes[1],
31603168
"Parent2 should have received emission"
31613169
);
3162-
assert!(child_stake > 20_000, "Child should have received emission");
31633170
assert!(
3164-
weight_setter_stake > 100_000,
3171+
child_stake > initial_actual_stakes[2],
3172+
"Child should have received emission"
3173+
);
3174+
assert!(
3175+
weight_setter_stake > initial_actual_stakes[3],
31653176
"Weight setter should have received emission"
31663177
);
31673178

31683179
// Check individual stake increases
3169-
let parent1_stake_increase = parent1_stake - 200_000;
3170-
let parent2_stake_increase = parent2_stake - 150_000;
3171-
let child_stake_increase = child_stake - 20_000;
3180+
let parent1_stake_increase = parent1_stake - initial_actual_stakes[0];
3181+
let parent2_stake_increase = parent2_stake - initial_actual_stakes[1];
3182+
let child_stake_increase = child_stake - initial_actual_stakes[2];
31723183

31733184
log::debug!(
31743185
"Stake increases - Parent1: {}, Parent2: {}, Child: {}",
@@ -3192,12 +3203,13 @@ fn test_childkey_multiple_parents_emission() {
31923203
);
31933204

31943205
// Check that the total stake has increased by the emission amount
3206+
// Allow 1% slippage
31953207
let total_stake = parent1_stake + parent2_stake + child_stake + weight_setter_stake;
3196-
let initial_total_stake: u64 = initial_stakes.iter().map(|(_, _, _, stake)| stake).sum();
3208+
let initial_total_stake: u64 = initial_actual_stakes.iter().sum::<u64>();
31973209
assert_abs_diff_eq!(
31983210
total_stake,
3199-
initial_total_stake + total_emission - 2,
3200-
epsilon = total_emission / 10_000
3211+
initial_total_stake + total_emission,
3212+
epsilon = total_emission / 100
32013213
);
32023214
});
32033215
}

pallets/subtensor/src/tests/epoch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use frame_support::{assert_err, assert_ok};
1212

1313
// use frame_system::Config;
1414
use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng};
15-
use sp_core::U256;
15+
use sp_core::{Get, U256};
1616
// use sp_runtime::DispatchError;
1717
use std::time::Instant;
1818
use substrate_fixed::types::I32F32;
@@ -1505,7 +1505,7 @@ fn test_set_alpha_disabled() {
15051505
signer.clone(),
15061506
hotkey,
15071507
netuid,
1508-
1000
1508+
DefaultMinStake::<Test>::get()
15091509
));
15101510
// Only owner can set alpha values
15111511
assert_ok!(SubtensorModule::register_network(signer.clone(), hotkey));
@@ -2600,7 +2600,7 @@ fn test_get_set_alpha() {
26002600
signer.clone(),
26012601
hotkey,
26022602
netuid,
2603-
1000
2603+
DefaultMinStake::<Test>::get()
26042604
));
26052605

26062606
assert_ok!(SubtensorModule::do_set_alpha_values(

pallets/subtensor/src/tests/move_stake.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::mock::*;
22
use crate::*;
33
use approx::assert_abs_diff_eq;
44
use frame_support::{assert_err, assert_noop, assert_ok};
5-
use sp_core::U256;
5+
use sp_core::{Get, U256};
66

77
// 1. test_do_move_success
88
// Description: Test a successful move of stake between two hotkeys in the same subnet
@@ -16,7 +16,7 @@ fn test_do_move_success() {
1616
let coldkey = U256::from(1);
1717
let origin_hotkey = U256::from(2);
1818
let destination_hotkey = U256::from(3);
19-
let stake_amount = 1_000_000;
19+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
2020

2121
// Set up initial stake
2222
SubtensorModule::create_account_if_non_existent(&coldkey, &origin_hotkey);
@@ -54,7 +54,7 @@ fn test_do_move_success() {
5454
netuid
5555
),
5656
stake_amount,
57-
epsilon = 100
57+
epsilon = stake_amount / 1000
5858
);
5959
});
6060
}
@@ -72,7 +72,7 @@ fn test_do_move_different_subnets() {
7272
let coldkey = U256::from(1);
7373
let origin_hotkey = U256::from(2);
7474
let destination_hotkey = U256::from(3);
75-
let stake_amount = 1_000_000;
75+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
7676

7777
// Set up initial stake and subnets
7878
SubtensorModule::create_account_if_non_existent(&coldkey, &origin_hotkey);
@@ -110,7 +110,7 @@ fn test_do_move_different_subnets() {
110110
destination_netuid
111111
),
112112
stake_amount,
113-
epsilon = 100
113+
epsilon = stake_amount / 1000
114114
);
115115
});
116116
}
@@ -271,7 +271,7 @@ fn test_do_move_all_stake() {
271271
let coldkey = U256::from(1);
272272
let origin_hotkey = U256::from(2);
273273
let destination_hotkey = U256::from(3);
274-
let stake_amount = 1_000_000;
274+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
275275

276276
// Set up initial stake
277277
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, netuid, stake_amount);
@@ -309,7 +309,7 @@ fn test_do_move_all_stake() {
309309
netuid
310310
),
311311
stake_amount,
312-
epsilon = 100
312+
epsilon = stake_amount / 1000
313313
);
314314
});
315315
}
@@ -323,7 +323,7 @@ fn test_do_move_half_stake() {
323323
let coldkey = U256::from(1);
324324
let origin_hotkey = U256::from(2);
325325
let destination_hotkey = U256::from(3);
326-
let stake_amount = 1_000_000;
326+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
327327

328328
// Set up initial stake
329329
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, netuid, stake_amount);
@@ -353,7 +353,7 @@ fn test_do_move_half_stake() {
353353
netuid
354354
),
355355
stake_amount / 2,
356-
epsilon = 100
356+
epsilon = stake_amount / 1000
357357
);
358358
assert_abs_diff_eq!(
359359
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -362,7 +362,7 @@ fn test_do_move_half_stake() {
362362
netuid
363363
),
364364
stake_amount / 2,
365-
epsilon = 100
365+
epsilon = stake_amount / 1000
366366
);
367367
});
368368
}
@@ -379,7 +379,7 @@ fn test_do_move_partial_stake() {
379379
let coldkey = U256::from(1);
380380
let origin_hotkey = U256::from(2);
381381
let destination_hotkey = U256::from(3);
382-
let total_stake = 1_000_000;
382+
let total_stake = DefaultMinStake::<Test>::get() * 10;
383383

384384
// Set up initial stake
385385
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, netuid, total_stake);
@@ -417,7 +417,7 @@ fn test_do_move_partial_stake() {
417417
netuid
418418
),
419419
total_stake,
420-
epsilon = 100
420+
epsilon = total_stake / 1000
421421
);
422422
});
423423
}
@@ -434,7 +434,7 @@ fn test_do_move_multiple_times() {
434434
let coldkey = U256::from(1);
435435
let hotkey1 = U256::from(2);
436436
let hotkey2 = U256::from(3);
437-
let initial_stake = 1_000_000;
437+
let initial_stake = DefaultMinStake::<Test>::get() * 10;
438438

439439
// Set up initial stake
440440
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey1);
@@ -471,7 +471,7 @@ fn test_do_move_multiple_times() {
471471
assert_abs_diff_eq!(
472472
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, netuid),
473473
initial_stake,
474-
epsilon = 100
474+
epsilon = initial_stake / 1000
475475
);
476476
assert_eq!(
477477
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, netuid),
@@ -548,7 +548,7 @@ fn test_do_move_same_hotkey() {
548548
let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
549549
let coldkey = U256::from(1);
550550
let hotkey = U256::from(2);
551-
let stake_amount = 1_000_000;
551+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
552552

553553
// Set up initial stake
554554
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
@@ -587,7 +587,7 @@ fn test_do_move_event_emission() {
587587
let coldkey = U256::from(1);
588588
let origin_hotkey = U256::from(2);
589589
let destination_hotkey = U256::from(3);
590-
let stake_amount = 10_000;
590+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
591591

592592
// Set up initial stake
593593
SubtensorModule::create_account_if_non_existent(&coldkey, &origin_hotkey);
@@ -618,7 +618,7 @@ fn test_do_move_event_emission() {
618618
netuid,
619619
destination_hotkey,
620620
netuid,
621-
alpha,
621+
19999999, // Should be TAO equivalent
622622
)
623623
.into(),
624624
);
@@ -638,7 +638,7 @@ fn test_do_move_storage_updates() {
638638
let coldkey = U256::from(1);
639639
let origin_hotkey = U256::from(2);
640640
let destination_hotkey = U256::from(3);
641-
let stake_amount = 1_000_000;
641+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
642642

643643
// Set up initial stake
644644
SubtensorModule::stake_into_subnet(&origin_hotkey, &coldkey, origin_netuid, stake_amount);
@@ -743,7 +743,7 @@ fn test_moving_too_little_fails() {
743743
new_test_ext(1).execute_with(|| {
744744
let hotkey_account_id = U256::from(533453);
745745
let coldkey_account_id = U256::from(55453);
746-
let amount = 10_000;
746+
let amount = DefaultMinStake::<Test>::get();
747747

748748
//add network
749749
let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id);

0 commit comments

Comments
 (0)