@@ -19,6 +19,23 @@ fn close(value: u64, target: u64, eps: u64) {
19
19
)
20
20
}
21
21
22
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_hotkey_take --exact --show-output --nocapture
23
+ #[ test]
24
+ fn test_hotkey_take ( ) {
25
+ new_test_ext ( 1 ) . execute_with ( || {
26
+ let hotkey = U256 :: from ( 1 ) ;
27
+ Delegates :: < Test > :: insert ( hotkey, u16:: MAX / 2 ) ;
28
+ log:: info!(
29
+ "expected: {:?}" ,
30
+ SubtensorModule :: get_hotkey_take_float( & hotkey)
31
+ ) ;
32
+ log:: info!(
33
+ "expected: {:?}" ,
34
+ SubtensorModule :: get_hotkey_take_float( & hotkey)
35
+ ) ;
36
+ } ) ;
37
+ }
38
+
22
39
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_dynamic_function_various_values --exact --show-output --nocapture
23
40
#[ test]
24
41
fn test_dynamic_function_various_values ( ) {
@@ -476,6 +493,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() {
476
493
let stake_before: u64 = 1_000_000_000 ;
477
494
// register_ok_neuron(root, hotkey, coldkey, 0);
478
495
register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
496
+ Delegates :: < Test > :: insert ( hotkey, 0 ) ;
479
497
SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
480
498
SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
481
499
& hotkey,
@@ -496,7 +514,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() {
496
514
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid) ;
497
515
let root_after =
498
516
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, root) ;
499
- close ( stake_before + pending_alpha, stake_after, 10 ) ; // Registered gets all alpha emission.
517
+ close ( stake_before + pending_alpha / 2 , stake_after, 10 ) ; // Registered gets all alpha emission.
500
518
close ( stake_before + pending_tao, root_after, 10 ) ; // Registered gets all tao emission
501
519
} ) ;
502
520
}
@@ -549,6 +567,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() {
549
567
let stake_before: u64 = 1_000_000_000 ;
550
568
register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
551
569
register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
570
+ Delegates :: < Test > :: insert ( hotkey1, 0 ) ;
571
+ Delegates :: < Test > :: insert ( hotkey2, 0 ) ;
552
572
SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
553
573
SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
554
574
& hotkey1,
@@ -585,8 +605,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() {
585
605
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey2, & coldkey, netuid) ;
586
606
let root_after2 =
587
607
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey2, & coldkey, root) ;
588
- close ( stake_before + pending_alpha / 2 , stake_after1, 10 ) ; // Registered gets 1/2 emission
589
- close ( stake_before + pending_alpha / 2 , stake_after2, 10 ) ; // Registered gets 1/2 emission.
608
+ close ( stake_before + pending_alpha / 4 , stake_after1, 10 ) ; // Registered gets 1/2 emission
609
+ close ( stake_before + pending_alpha / 4 , stake_after2, 10 ) ; // Registered gets 1/2 emission.
590
610
close ( stake_before + pending_tao / 2 , root_after1, 10 ) ; // Registered gets 1/2 tao emission
591
611
close ( stake_before + pending_tao / 2 , root_after2, 10 ) ; // Registered gets 1/2 tao emission
592
612
} ) ;
@@ -603,6 +623,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
603
623
let hotkey2 = U256 :: from ( 2 ) ;
604
624
let coldkey = U256 :: from ( 3 ) ;
605
625
let stake_before: u64 = 1_000_000_000 ;
626
+ Delegates :: < Test > :: insert ( hotkey1, 0 ) ;
627
+ Delegates :: < Test > :: insert ( hotkey2, 0 ) ;
606
628
register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
607
629
register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
608
630
SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
@@ -642,10 +664,14 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
642
664
let root_after2 =
643
665
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey2, & coldkey, root) ;
644
666
let expected_stake = I96F32 :: from_num ( stake_before)
645
- + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 3.0 / 5.0 ) ;
667
+ + ( I96F32 :: from_num ( pending_alpha)
668
+ * I96F32 :: from_num ( 3.0 / 5.0 )
669
+ * I96F32 :: from_num ( 1.0 / 3.0 ) ) ;
646
670
close ( expected_stake. to_num :: < u64 > ( ) , stake_after1, 10 ) ; // Registered gets 60% of emission
647
671
let expected_stake2 = I96F32 :: from_num ( stake_before)
648
- + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 2.0 / 5.0 ) ;
672
+ + I96F32 :: from_num ( pending_alpha)
673
+ * I96F32 :: from_num ( 2.0 / 5.0 )
674
+ * I96F32 :: from_num ( 1.0 / 2.0 ) ;
649
675
close ( expected_stake2. to_num :: < u64 > ( ) , stake_after2, 10 ) ; // Registered gets 40% emission
650
676
let expected_root1 = I96F32 :: from_num ( 2 * stake_before)
651
677
+ I96F32 :: from_num ( pending_tao) * I96F32 :: from_num ( 2.0 / 3.0 ) ;
@@ -668,6 +694,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
668
694
let hotkey2 = U256 :: from ( 2 ) ;
669
695
let coldkey = U256 :: from ( 3 ) ;
670
696
let stake_before: u64 = 1_000_000_000 ;
697
+ Delegates :: < Test > :: insert ( hotkey1, 0 ) ;
698
+ Delegates :: < Test > :: insert ( hotkey2, 0 ) ;
671
699
register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
672
700
register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
673
701
SubtensorModule :: set_tao_weight ( u64:: MAX / 2 ) ; // Set TAO weight to 0.5
@@ -708,11 +736,15 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
708
736
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey2, & coldkey, root) ;
709
737
// hotkey 1 has (1 + (2 * 0.5))/( 1 + 1*0.5 + 1 + (2 * 0.5)) = 0.5714285714 of the hotkey emission.
710
738
let expected_stake = I96F32 :: from_num ( stake_before)
711
- + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 0.5714285714 ) ;
739
+ + I96F32 :: from_num ( pending_alpha)
740
+ * I96F32 :: from_num ( 0.5714285714 )
741
+ * I96F32 :: from_num ( 1.0 / 2.0 ) ;
712
742
close ( expected_stake. to_num :: < u64 > ( ) , stake_after1, 10 ) ;
713
743
// hotkey 2 has (1 + 1*0.5)/( 1 + 1*0.5 + 1 + (2 * 0.5)) = 0.4285714286 of the hotkey emission.
714
744
let expected_stake2 = I96F32 :: from_num ( stake_before)
715
- + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 0.4285714286 ) ;
745
+ + I96F32 :: from_num ( pending_alpha)
746
+ * I96F32 :: from_num ( 0.4285714286 )
747
+ * I96F32 :: from_num ( 2.0 / 3.0 ) ;
716
748
close ( expected_stake2. to_num :: < u64 > ( ) , stake_after2, 10 ) ;
717
749
// hotkey 1 has 2 / 3 root tao
718
750
let expected_root1 = I96F32 :: from_num ( 2 * stake_before)
@@ -970,11 +1002,11 @@ fn test_get_root_children_drain() {
970
1002
// Alice and Bob both made half of the dividends.
971
1003
assert_eq ! (
972
1004
SubtensorModule :: get_stake_for_hotkey_on_subnet( & alice, alpha) ,
973
- alice_alpha_stake + pending_alpha / 2
1005
+ alice_alpha_stake + pending_alpha / 4
974
1006
) ;
975
1007
assert_eq ! (
976
1008
SubtensorModule :: get_stake_for_hotkey_on_subnet( & bob, alpha) ,
977
- bob_alpha_stake + pending_alpha / 2
1009
+ bob_alpha_stake + pending_alpha / 4
978
1010
) ;
979
1011
980
1012
// Lets drain
@@ -1006,7 +1038,7 @@ fn test_get_root_children_drain() {
1006
1038
// Bob makes it all.
1007
1039
assert_eq ! (
1008
1040
AlphaDividendsPerSubnet :: <Test >:: get( alpha, bob) ,
1009
- pending_alpha
1041
+ ( I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 1.0 - 0.495412844 ) ) . to_num :: < u64 > ( )
1010
1042
) ;
1011
1043
assert_eq ! ( TaoDividendsPerSubnet :: <Test >:: get( alpha, bob) , pending_root) ;
1012
1044
} ) ;
@@ -1083,12 +1115,12 @@ fn test_get_root_children_drain_half_proportion() {
1083
1115
// Alice and Bob make the same amount.
1084
1116
close (
1085
1117
AlphaDividendsPerSubnet :: < Test > :: get ( alpha, alice) ,
1086
- pending_alpha / 2 ,
1118
+ pending_alpha / 4 ,
1087
1119
10 ,
1088
1120
) ;
1089
1121
close (
1090
1122
AlphaDividendsPerSubnet :: < Test > :: get ( alpha, bob) ,
1091
- pending_alpha / 2 ,
1123
+ pending_alpha / 4 ,
1092
1124
10 ,
1093
1125
) ;
1094
1126
} ) ;
@@ -1165,7 +1197,7 @@ fn test_get_root_children_drain_with_take() {
1165
1197
close ( AlphaDividendsPerSubnet :: < Test > :: get ( alpha, alice) , 0 , 10 ) ;
1166
1198
close (
1167
1199
AlphaDividendsPerSubnet :: < Test > :: get ( alpha, bob) ,
1168
- pending_alpha,
1200
+ pending_alpha / 2 ,
1169
1201
10 ,
1170
1202
) ;
1171
1203
} ) ;
@@ -1241,12 +1273,12 @@ fn test_get_root_children_drain_with_half_take() {
1241
1273
// Alice and Bob make the same amount.
1242
1274
close (
1243
1275
AlphaDividendsPerSubnet :: < Test > :: get ( alpha, alice) ,
1244
- pending_alpha / 4 ,
1276
+ pending_alpha / 8 ,
1245
1277
10000 ,
1246
1278
) ;
1247
1279
close (
1248
1280
AlphaDividendsPerSubnet :: < Test > :: get ( alpha, bob) ,
1249
- 3 * ( pending_alpha / 4 ) ,
1281
+ 3 * ( pending_alpha / 8 ) ,
1250
1282
10000 ,
1251
1283
) ;
1252
1284
} ) ;
0 commit comments