Skip to content

Commit d24410e

Browse files
committed
change api test to test passthrough
1 parent a198d9d commit d24410e

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

pallets/subtensor/src/tests/staking2.rs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ fn test_try_associate_hotkey() {
626626

627627
#[test]
628628
fn test_stake_fee_api() {
629+
// The API should match the calculation
629630
new_test_ext(1).execute_with(|| {
630631
let hotkey1 = U256::from(1);
631632
let coldkey1 = U256::from(2);
@@ -642,8 +643,6 @@ fn test_stake_fee_api() {
642643
let reciprocal_price = 2; // 1 / price
643644
let stake_amount = 100_000_000_000;
644645

645-
let default_fee = DefaultStakingFee::<Test>::get();
646-
647646
// Setup alpha out
648647
SubnetAlphaOut::<Test>::insert(netuid0, 100_000_000_000);
649648
SubnetAlphaOut::<Test>::insert(netuid1, 100_000_000_000);
@@ -668,8 +667,15 @@ fn test_stake_fee_api() {
668667
Some((hotkey1, netuid0)),
669668
coldkey1,
670669
stake_amount,
671-
); // Default for adding stake
672-
assert_eq!(stake_fee_0, default_fee);
670+
);
671+
let dynamic_fee_0 = SubtensorModule::calculate_staking_fee(
672+
None,
673+
&coldkey1,
674+
Some((&hotkey1, netuid0)),
675+
&coldkey1,
676+
I96F32::saturating_from_num(stake_amount),
677+
);
678+
assert_eq!(stake_fee_0, dynamic_fee_0);
673679

674680
// Test stake fee for remove on root
675681
let stake_fee_1 = SubtensorModule::get_stake_fee(
@@ -678,8 +684,15 @@ fn test_stake_fee_api() {
678684
None,
679685
coldkey1,
680686
stake_amount,
681-
); // Default for removing stake from root
682-
assert_eq!(stake_fee_1, default_fee);
687+
);
688+
let dynamic_fee_1 = SubtensorModule::calculate_staking_fee(
689+
Some((&hotkey1, root_netuid)),
690+
&coldkey1,
691+
None,
692+
&coldkey1,
693+
I96F32::saturating_from_num(stake_amount),
694+
);
695+
assert_eq!(stake_fee_1, dynamic_fee_1);
683696

684697
// Test stake fee for move from root to non-root
685698
let stake_fee_2 = SubtensorModule::get_stake_fee(
@@ -688,8 +701,15 @@ fn test_stake_fee_api() {
688701
Some((hotkey1, netuid0)),
689702
coldkey1,
690703
stake_amount,
691-
); // Default for moving stake from root to non-root
692-
assert_eq!(stake_fee_2, default_fee);
704+
);
705+
let dynamic_fee_2 = SubtensorModule::calculate_staking_fee(
706+
Some((&hotkey1, root_netuid)),
707+
&coldkey1,
708+
Some((&hotkey1, netuid0)),
709+
&coldkey1,
710+
I96F32::saturating_from_num(stake_amount),
711+
);
712+
assert_eq!(stake_fee_2, dynamic_fee_2);
693713

694714
// Test stake fee for move between hotkeys on root
695715
let stake_fee_3 = SubtensorModule::get_stake_fee(
@@ -698,8 +718,15 @@ fn test_stake_fee_api() {
698718
Some((hotkey2, root_netuid)),
699719
coldkey1,
700720
stake_amount,
701-
); // Default for moving stake between hotkeys on root
702-
assert_eq!(stake_fee_3, default_fee);
721+
);
722+
let dynamic_fee_3 = SubtensorModule::calculate_staking_fee(
723+
Some((&hotkey1, root_netuid)),
724+
&coldkey1,
725+
Some((&hotkey2, root_netuid)),
726+
&coldkey1,
727+
I96F32::saturating_from_num(stake_amount),
728+
);
729+
assert_eq!(stake_fee_3, dynamic_fee_3);
703730

704731
// Test stake fee for move between coldkeys on root
705732
let stake_fee_4 = SubtensorModule::get_stake_fee(
@@ -708,8 +735,15 @@ fn test_stake_fee_api() {
708735
Some((hotkey1, root_netuid)),
709736
coldkey2,
710737
stake_amount,
711-
); // Default for moving stake between coldkeys on root
712-
assert_eq!(stake_fee_4, default_fee);
738+
);
739+
let dynamic_fee_4 = SubtensorModule::calculate_staking_fee(
740+
Some((&hotkey1, root_netuid)),
741+
&coldkey1,
742+
Some((&hotkey1, root_netuid)),
743+
&coldkey2,
744+
I96F32::saturating_from_num(stake_amount),
745+
);
746+
assert_eq!(stake_fee_4, dynamic_fee_4);
713747

714748
// Test stake fee for *swap* from non-root to root
715749
let stake_fee_5 = SubtensorModule::get_stake_fee(
@@ -718,7 +752,7 @@ fn test_stake_fee_api() {
718752
Some((hotkey1, root_netuid)),
719753
coldkey1,
720754
stake_amount,
721-
); // Charged a dynamic fee
755+
);
722756
let dynamic_fee_5 = SubtensorModule::calculate_staking_fee(
723757
Some((&hotkey1, netuid0)),
724758
&coldkey1,
@@ -735,7 +769,7 @@ fn test_stake_fee_api() {
735769
Some((hotkey2, netuid0)),
736770
coldkey1,
737771
stake_amount,
738-
); // Charged a dynamic fee
772+
);
739773
let dynamic_fee_6 = SubtensorModule::calculate_staking_fee(
740774
Some((&hotkey1, netuid0)),
741775
&coldkey1,
@@ -752,7 +786,7 @@ fn test_stake_fee_api() {
752786
Some((hotkey1, netuid0)),
753787
coldkey2,
754788
stake_amount,
755-
); // Charged a dynamic fee
789+
);
756790
let dynamic_fee_7 = SubtensorModule::calculate_staking_fee(
757791
Some((&hotkey1, netuid0)),
758792
&coldkey1,
@@ -769,7 +803,7 @@ fn test_stake_fee_api() {
769803
Some((hotkey1, netuid1)),
770804
coldkey1,
771805
stake_amount,
772-
); // Charged a dynamic fee
806+
);
773807
let dynamic_fee_8 = SubtensorModule::calculate_staking_fee(
774808
Some((&hotkey1, netuid0)),
775809
&coldkey1,

0 commit comments

Comments
 (0)