@@ -57,8 +57,11 @@ fn test_add_stake_ok_no_emission() {
5757 0
5858 ) ;
5959
60- // Also total stake should be zero
61- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
60+ // Also total stake should be equal to the network initial lock
61+ assert_eq ! (
62+ SubtensorModule :: get_total_stake( ) ,
63+ SubtensorModule :: get_network_min_lock( )
64+ ) ;
6265
6366 // Transfer to hotkey account, and check if the result is ok
6467 assert_ok ! ( SubtensorModule :: add_stake(
@@ -79,7 +82,10 @@ fn test_add_stake_ok_no_emission() {
7982 assert_eq ! ( SubtensorModule :: get_coldkey_balance( & coldkey_account_id) , 1 ) ;
8083
8184 // Check if total stake has increased accordingly.
82- assert_eq ! ( SubtensorModule :: get_total_stake( ) , amount) ;
85+ assert_eq ! (
86+ SubtensorModule :: get_total_stake( ) ,
87+ amount + SubtensorModule :: get_network_min_lock( )
88+ ) ;
8389 } ) ;
8490}
8591
@@ -353,12 +359,14 @@ fn test_remove_stake_ok_no_emission() {
353359 let coldkey_account_id = U256 :: from ( 4343 ) ;
354360 let hotkey_account_id = U256 :: from ( 4968585 ) ;
355361 let amount = DefaultMinStake :: < Test > :: get ( ) * 10 ;
356- let fee = DefaultStakingFee :: < Test > :: get ( ) ;
357362 let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
358363 register_ok_neuron ( netuid, hotkey_account_id, coldkey_account_id, 192213123 ) ;
359364
360365 // Some basic assertions
361- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
366+ assert_eq ! (
367+ SubtensorModule :: get_total_stake( ) ,
368+ SubtensorModule :: get_network_min_lock( )
369+ ) ;
362370 assert_eq ! (
363371 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
364372 0
@@ -372,6 +380,16 @@ fn test_remove_stake_ok_no_emission() {
372380 netuid,
373381 amount,
374382 ) ;
383+ assert_eq ! (
384+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
385+ amount
386+ ) ;
387+
388+ // Add subnet TAO for the equivalent amount added at price
389+ let amount_tao =
390+ I96F32 :: saturating_from_num ( amount) * SubtensorModule :: get_alpha_price ( netuid) ;
391+ SubnetTAO :: < Test > :: mutate ( netuid, |v| * v += amount_tao. saturating_to_num :: < u64 > ( ) ) ;
392+ TotalStake :: < Test > :: mutate ( |v| * v += amount_tao. saturating_to_num :: < u64 > ( ) ) ;
375393
376394 // Do the magic
377395 assert_ok ! ( SubtensorModule :: remove_stake(
@@ -381,13 +399,24 @@ fn test_remove_stake_ok_no_emission() {
381399 amount
382400 ) ) ;
383401
402+ let fee = SubtensorModule :: calculate_staking_fee (
403+ Some ( ( & hotkey_account_id, netuid) ) ,
404+ & coldkey_account_id,
405+ None ,
406+ & coldkey_account_id,
407+ I96F32 :: saturating_from_num ( amount) ,
408+ ) ;
409+
384410 // we do not expect the exact amount due to slippage
385411 assert ! ( SubtensorModule :: get_coldkey_balance( & coldkey_account_id) > amount / 10 * 9 - fee) ;
386412 assert_eq ! (
387413 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
388414 0
389415 ) ;
390- assert_eq ! ( SubtensorModule :: get_total_stake( ) , fee) ;
416+ assert_eq ! (
417+ SubtensorModule :: get_total_stake( ) ,
418+ SubtensorModule :: get_network_min_lock( ) + fee
419+ ) ;
391420 } ) ;
392421}
393422
@@ -403,7 +432,10 @@ fn test_remove_stake_amount_too_low() {
403432 register_ok_neuron ( netuid, hotkey_account_id, coldkey_account_id, 192213123 ) ;
404433
405434 // Some basic assertions
406- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
435+ assert_eq ! (
436+ SubtensorModule :: get_total_stake( ) ,
437+ SubtensorModule :: get_network_min_lock( )
438+ ) ;
407439 assert_eq ! (
408440 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
409441 0
@@ -510,12 +542,14 @@ fn test_remove_stake_total_balance_no_change() {
510542 let hotkey_account_id = U256 :: from ( 571337 ) ;
511543 let coldkey_account_id = U256 :: from ( 71337 ) ;
512544 let amount = DefaultMinStake :: < Test > :: get ( ) * 10 ;
513- let fee = DefaultStakingFee :: < Test > :: get ( ) ;
514545 let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
515546 register_ok_neuron ( netuid, hotkey_account_id, coldkey_account_id, 192213123 ) ;
516547
517548 // Some basic assertions
518- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
549+ assert_eq ! (
550+ SubtensorModule :: get_total_stake( ) ,
551+ SubtensorModule :: get_network_min_lock( )
552+ ) ;
519553 assert_eq ! (
520554 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
521555 0
@@ -532,6 +566,12 @@ fn test_remove_stake_total_balance_no_change() {
532566 amount,
533567 ) ;
534568
569+ // Add subnet TAO for the equivalent amount added at price
570+ let amount_tao =
571+ I96F32 :: saturating_from_num ( amount) * SubtensorModule :: get_alpha_price ( netuid) ;
572+ SubnetTAO :: < Test > :: mutate ( netuid, |v| * v += amount_tao. saturating_to_num :: < u64 > ( ) ) ;
573+ TotalStake :: < Test > :: mutate ( |v| * v += amount_tao. saturating_to_num :: < u64 > ( ) ) ;
574+
535575 // Do the magic
536576 assert_ok ! ( SubtensorModule :: remove_stake(
537577 RuntimeOrigin :: signed( coldkey_account_id) ,
@@ -540,6 +580,13 @@ fn test_remove_stake_total_balance_no_change() {
540580 amount
541581 ) ) ;
542582
583+ let fee = SubtensorModule :: calculate_staking_fee (
584+ Some ( ( & hotkey_account_id, netuid) ) ,
585+ & coldkey_account_id,
586+ None ,
587+ & coldkey_account_id,
588+ I96F32 :: saturating_from_num ( amount) ,
589+ ) ;
543590 assert_abs_diff_eq ! (
544591 SubtensorModule :: get_coldkey_balance( & coldkey_account_id) ,
545592 amount - fee,
@@ -549,7 +596,10 @@ fn test_remove_stake_total_balance_no_change() {
549596 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
550597 0
551598 ) ;
552- assert_eq ! ( SubtensorModule :: get_total_stake( ) , fee) ;
599+ assert_eq ! (
600+ SubtensorModule :: get_total_stake( ) ,
601+ SubtensorModule :: get_network_min_lock( ) + fee
602+ ) ;
553603
554604 // Check total balance is equal to the added stake. Even after remove stake (no fee, includes reserved/locked balance)
555605 let total_balance = Balances :: total_balance ( & coldkey_account_id) ;
@@ -648,7 +698,10 @@ fn test_remove_stake_total_issuance_no_change() {
648698 SubtensorModule :: add_balance_to_coldkey_account ( & coldkey_account_id, amount) ;
649699
650700 // Some basic assertions
651- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
701+ assert_eq ! (
702+ SubtensorModule :: get_total_stake( ) ,
703+ SubtensorModule :: get_network_min_lock( )
704+ ) ;
652705 assert_eq ! (
653706 SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
654707 0
@@ -697,7 +750,7 @@ fn test_remove_stake_total_issuance_no_change() {
697750 ) ;
698751 assert_abs_diff_eq ! (
699752 SubtensorModule :: get_total_stake( ) ,
700- fee * 2 ,
753+ fee * 2 + SubtensorModule :: get_network_min_lock ( ) ,
701754 epsilon = fee / 1000
702755 ) ;
703756
@@ -762,8 +815,11 @@ fn test_add_stake_to_hotkey_account_ok() {
762815 let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
763816 register_ok_neuron ( netuid, hotkey_id, coldkey_id, 192213123 ) ;
764817
765- // There is not stake in the system at first, so result should be 0;
766- assert_eq ! ( SubtensorModule :: get_total_stake( ) , 0 ) ;
818+ // There is no stake in the system at first, other than the network initial lock so result;
819+ assert_eq ! (
820+ SubtensorModule :: get_total_stake( ) ,
821+ SubtensorModule :: get_network_min_lock( )
822+ ) ;
767823
768824 SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
769825 & hotkey_id,
@@ -2497,7 +2553,11 @@ fn test_stake_overflow() {
24972553 ) ;
24982554
24992555 // Check if total stake has increased accordingly.
2500- assert_abs_diff_eq ! ( SubtensorModule :: get_total_stake( ) , amount, epsilon = 10 ) ;
2556+ assert_abs_diff_eq ! (
2557+ SubtensorModule :: get_total_stake( ) ,
2558+ amount + SubtensorModule :: get_network_min_lock( ) ,
2559+ epsilon = 10
2560+ ) ;
25012561 } ) ;
25022562}
25032563
0 commit comments