Skip to content

Commit 5df90b9

Browse files
committed
fix root claim tests
1 parent 0de5c96 commit 5df90b9

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

pallets/subtensor/src/tests/claim_root.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::tests::mock::{
66
use crate::{
77
DefaultMinRootClaimAmount, Error, MAX_NUM_ROOT_CLAIMS, MAX_ROOT_CLAIM_THRESHOLD, NetworksAdded,
88
NumRootClaim, NumStakingColdkeys, PendingRootAlphaDivs, RootClaimable, RootClaimableThreshold,
9-
StakingColdkeys, StakingColdkeysByIndex, SubnetAlphaIn, SubnetMechanism, SubnetTAO,
10-
SubtokenEnabled, Tempo, pallet,
9+
StakingColdkeys, StakingColdkeysByIndex, SubnetAlphaIn, SubnetMechanism, SubnetMovingPrice,
10+
SubnetTAO, SubtokenEnabled, Tempo, pallet,
1111
};
1212
use crate::{RootClaimType, RootClaimTypeEnum, RootClaimed};
1313
use approx::assert_abs_diff_eq;
@@ -18,7 +18,7 @@ use frame_support::{assert_err, assert_noop, assert_ok};
1818
use sp_core::{H256, U256};
1919
use sp_runtime::DispatchError;
2020
use std::collections::BTreeSet;
21-
use substrate_fixed::types::{I96F32, U96F32};
21+
use substrate_fixed::types::{I96F32, U64F64, U96F32};
2222
use subtensor_runtime_common::{AlphaCurrency, Currency, NetUid, TaoCurrency};
2323
use subtensor_swap_interface::SwapHandler;
2424

@@ -779,6 +779,18 @@ fn test_claim_root_with_run_coinbase() {
779779
initial_total_hotkey_alpha.into(),
780780
);
781781

782+
// Set moving price > 1.0 and price > 1.0
783+
// So we turn off subsidy
784+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(2));
785+
pallet_subtensor_swap::AlphaSqrtPrice::<Test>::insert(
786+
netuid,
787+
U64F64::saturating_from_num(10.0),
788+
);
789+
790+
// Make sure we are not subsidizing, so we have root alpha divs.
791+
let subsidy_mode = SubtensorModule::get_network_subsidy_mode(&[netuid]);
792+
assert!(!subsidy_mode, "Subsidy mode should be false");
793+
782794
// Distribute pending root alpha
783795

784796
let initial_stake: u64 =
@@ -878,6 +890,18 @@ fn test_claim_root_with_block_emissions() {
878890
);
879891
SubtensorModule::maybe_add_coldkey_index(&coldkey);
880892

893+
// Set moving price > 1.0 and price > 1.0
894+
// So we turn off subsidy
895+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(2));
896+
pallet_subtensor_swap::AlphaSqrtPrice::<Test>::insert(
897+
netuid,
898+
U64F64::saturating_from_num(10.0),
899+
);
900+
901+
// Make sure we are not subsidizing, so we have root alpha divs.
902+
let subsidy_mode = SubtensorModule::get_network_subsidy_mode(&[netuid]);
903+
assert!(!subsidy_mode, "Subsidy mode should be false");
904+
881905
let initial_total_hotkey_alpha = 10_000_000u64;
882906
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
883907
&hotkey,
@@ -991,12 +1015,27 @@ fn test_claim_root_coinbase_distribution() {
9911015
let initial_alpha_issuance = SubtensorModule::get_alpha_issuance(netuid);
9921016
let alpha_emissions: AlphaCurrency = 1_000_000_000u64.into();
9931017

994-
// Check total issuance (saved to pending alpha divs)
1018+
// Set moving price > 1.0 and price > 1.0
1019+
// So we turn off subsidy
1020+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(2));
1021+
pallet_subtensor_swap::AlphaSqrtPrice::<Test>::insert(
1022+
netuid,
1023+
U64F64::saturating_from_num(10.0),
1024+
);
1025+
1026+
// Make sure we are not subsidizing, so we have root alpha divs.
1027+
let subsidy_mode = SubtensorModule::get_network_subsidy_mode(&[netuid]);
1028+
assert!(!subsidy_mode, "Subsidy mode should be false");
9951029

1030+
// Check total issuance (saved to pending alpha divs)
9961031
run_to_block(2);
9971032

9981033
let alpha_issuance = SubtensorModule::get_alpha_issuance(netuid);
999-
assert_eq!(initial_alpha_issuance + alpha_emissions, alpha_issuance);
1034+
// We went two blocks so we should have 2x the alpha emissions
1035+
assert_eq!(
1036+
initial_alpha_issuance + alpha_emissions.saturating_mul(2.into()),
1037+
alpha_issuance
1038+
);
10001039

10011040
let root_prop = initial_tao as f64 / (u64::from(alpha_issuance) + initial_tao) as f64;
10021041
let root_validators_share = 0.5f64;

0 commit comments

Comments
 (0)