Skip to content

Commit f0067d8

Browse files
committed
add emission to test mod
1 parent 91ebe0e commit f0067d8

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

pallets/subtensor/src/tests/emission.rs

+33-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
mod mock;
1+
use super::mock::*;
2+
use crate::*;
23
use std::collections::BTreeMap;
3-
4-
use crate::mock::*;
5-
use pallet_subtensor::*;
64
use sp_core::U256;
75
use substrate_fixed::types::I96F32;
86

@@ -1051,7 +1049,7 @@ fn test_basic_emission_distribution_scenario() {
10511049

10521050
// Set up stakes and delegations
10531051
add_network(netuid, tempo, 0);
1054-
pallet_subtensor::ChildkeyTake::<Test>::insert(hotkey, netuid, 16384); // 25% childkey take
1052+
ChildkeyTake::<Test>::insert(hotkey, netuid, 16384); // 25% childkey take
10551053
SubtensorModule::stake_into_subnet(&parent1, &coldkey, netuid, 500);
10561054
SubtensorModule::stake_into_subnet(&parent2, &coldkey, netuid, 500);
10571055
ParentKeys::<Test>::insert(
@@ -1122,12 +1120,12 @@ fn test_hotkey_take_calculation_scenario() {
11221120
let mining_emission = 0;
11231121

11241122
step_block(1000); // should be past stake adding block by 2 tempos
1125-
LastAddStakeIncrease::<Test>::insert(hotkey, coldkey, 1);
1123+
//LastAddStakeIncrease::<Test>::insert(hotkey, coldkey, 1);
11261124
ParentKeys::<Test>::insert(hotkey, netuid, vec![(1000, parent)]);
11271125

11281126
// Test with different childkey take values
11291127
for &take in &[0, 16384, 32768, 49152, 65535] {
1130-
pallet_subtensor::ChildkeyTake::<Test>::insert(hotkey, netuid, take);
1128+
crate::ChildkeyTake::<Test>::insert(hotkey, netuid, take);
11311129
SubtensorModule::stake_into_subnet(&parent, &coldkey, netuid, u64::MAX);
11321130
ParentKeys::<Test>::insert(hotkey, netuid, vec![(u64::MAX, parent)]);
11331131

@@ -1896,43 +1894,43 @@ fn test_basic_emission() {
18961894

18971895
// Starting point
18981896
let validator_alpha_before: u64 =
1899-
pallet_subtensor::Alpha::<Test>::get((validator, netuid, coldkey_validator));
1897+
crate::Alpha::<Test>::get((validator, netuid, coldkey_validator));
19001898
let miner_alpha_before: u64 =
1901-
pallet_subtensor::Alpha::<Test>::get((miner, netuid, coldkey_miner));
1899+
crate::Alpha::<Test>::get((miner, netuid, coldkey_miner));
19021900

19031901
// Run run_coinbase until PendingHotkeyEmission are populated
1904-
while pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid) == 0 {
1902+
while crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid) == 0 {
19051903
step_block(1);
19061904
}
19071905

19081906
assert!(
1909-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid)
1907+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid)
19101908
> 1_000_000_000,
19111909
"Validator should have received pending emission"
19121910
);
19131911
assert_eq!(
1914-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(miner, netuid),
1912+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(miner, netuid),
19151913
0,
19161914
"Miner should not have received pending emission"
19171915
);
19181916

19191917
// Prevent further subnet epochs
1920-
pallet_subtensor::Tempo::<Test>::set(netuid, u16::MAX);
1918+
crate::Tempo::<Test>::set(netuid, u16::MAX);
19211919

19221920
// Run run_coinbase until PendingHotkeyEmission is drained
19231921
step_block((hotkey_tempo * 10) as u16);
19241922

19251923
// Check emission distribution
1926-
let owner_emission = pallet_subtensor::Alpha::<Test>::get((
1924+
let owner_emission = crate::Alpha::<Test>::get((
19271925
subnet_owner_hotkey,
19281926
netuid,
19291927
subnet_owner_coldkey,
19301928
));
19311929
let validator_emission: u64 =
1932-
pallet_subtensor::Alpha::<Test>::get((validator, netuid, coldkey_validator))
1930+
crate::Alpha::<Test>::get((validator, netuid, coldkey_validator))
19331931
- validator_alpha_before;
19341932
let miner_emission: u64 =
1935-
pallet_subtensor::Alpha::<Test>::get((miner, netuid, coldkey_miner))
1933+
crate::Alpha::<Test>::get((miner, netuid, coldkey_miner))
19361934
- miner_alpha_before;
19371935

19381936
assert!(
@@ -1981,43 +1979,43 @@ fn test_basic_emission_reverse_order() {
19811979

19821980
// Starting point
19831981
let validator_alpha_before: u64 =
1984-
pallet_subtensor::Alpha::<Test>::get((validator, netuid, coldkey_validator));
1982+
crate::Alpha::<Test>::get((validator, netuid, coldkey_validator));
19851983
let miner_alpha_before: u64 =
1986-
pallet_subtensor::Alpha::<Test>::get((miner, netuid, coldkey_miner));
1984+
crate::Alpha::<Test>::get((miner, netuid, coldkey_miner));
19871985

19881986
// Run run_coinbase until PendingHotkeyEmission are populated
1989-
while pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid) == 0 {
1987+
while crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid) == 0 {
19901988
step_block(1);
19911989
}
19921990

19931991
assert!(
1994-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid)
1992+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator, netuid)
19951993
> 1_000_000_000,
19961994
"Validator should have received pending emission"
19971995
);
19981996
assert_eq!(
1999-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(miner, netuid),
1997+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(miner, netuid),
20001998
0,
20011999
"Miner should not have received pending emission"
20022000
);
20032001

20042002
// Prevent further subnet epochs
2005-
pallet_subtensor::Tempo::<Test>::set(netuid, u16::MAX);
2003+
crate::Tempo::<Test>::set(netuid, u16::MAX);
20062004

20072005
// Run run_coinbase until PendingHotkeyEmission is drained
20082006
step_block((hotkey_tempo * 10) as u16);
20092007

20102008
// Check emission distribution
2011-
let owner_emission = pallet_subtensor::Alpha::<Test>::get((
2009+
let owner_emission = crate::Alpha::<Test>::get((
20122010
subnet_owner_hotkey,
20132011
netuid,
20142012
subnet_owner_coldkey,
20152013
));
20162014
let validator_emission: u64 =
2017-
pallet_subtensor::Alpha::<Test>::get((validator, netuid, coldkey_validator))
2015+
crate::Alpha::<Test>::get((validator, netuid, coldkey_validator))
20182016
- validator_alpha_before;
20192017
let miner_emission: u64 =
2020-
pallet_subtensor::Alpha::<Test>::get((miner, netuid, coldkey_miner))
2018+
crate::Alpha::<Test>::get((miner, netuid, coldkey_miner))
20212019
- miner_alpha_before;
20222020

20232021
assert!(
@@ -2068,14 +2066,14 @@ fn test_basic_emission_two_validators() {
20682066

20692067
// Starting point
20702068
let validator1_alpha_before: u64 =
2071-
pallet_subtensor::Alpha::<Test>::get((validator1_hotkey, netuid, validator1_coldkey));
2069+
crate::Alpha::<Test>::get((validator1_hotkey, netuid, validator1_coldkey));
20722070
let validator2_alpha_before: u64 =
2073-
pallet_subtensor::Alpha::<Test>::get((validator2_hotkey, netuid, validator2_coldkey));
2071+
crate::Alpha::<Test>::get((validator2_hotkey, netuid, validator2_coldkey));
20742072
let miner_alpha_before: u64 =
2075-
pallet_subtensor::Alpha::<Test>::get((miner_hotkey, netuid, miner_coldkey));
2073+
crate::Alpha::<Test>::get((miner_hotkey, netuid, miner_coldkey));
20762074

20772075
// Run run_coinbase until PendingHotkeyEmission are populated
2078-
while pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(
2076+
while crate::PendingHotkeyEmissionOnNetuid::<Test>::get(
20792077
validator1_hotkey,
20802078
netuid,
20812079
) == 0
@@ -2084,17 +2082,17 @@ fn test_basic_emission_two_validators() {
20842082
}
20852083

20862084
assert!(
2087-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator1_hotkey, netuid)
2085+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator1_hotkey, netuid)
20882086
> 1_000_000_000,
20892087
"Validator 1 should have received pending emission"
20902088
);
20912089
assert!(
2092-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(validator2_hotkey, netuid)
2090+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(validator2_hotkey, netuid)
20932091
> 1_000_000_000,
20942092
"validator 2 should have received pending emission"
20952093
);
20962094
assert!(
2097-
pallet_subtensor::PendingHotkeyEmissionOnNetuid::<Test>::get(miner_hotkey, netuid) == 0,
2095+
crate::PendingHotkeyEmissionOnNetuid::<Test>::get(miner_hotkey, netuid) == 0,
20982096
"Miner should NOT have received pending emission"
20992097
);
21002098

@@ -2103,13 +2101,13 @@ fn test_basic_emission_two_validators() {
21032101

21042102
// Check emission distribution
21052103
let validator1_emission: u64 =
2106-
pallet_subtensor::Alpha::<Test>::get((validator1_hotkey, validator1_coldkey, netuid))
2104+
crate::Alpha::<Test>::get((validator1_hotkey, netuid, validator1_coldkey))
21072105
- validator1_alpha_before;
21082106
let validator2_emission: u64 =
2109-
pallet_subtensor::Alpha::<Test>::get((validator2_hotkey, validator2_coldkey, netuid))
2107+
crate::Alpha::<Test>::get((validator2_hotkey, netuid, validator2_coldkey))
21102108
- validator2_alpha_before;
21112109
let miner_emission: u64 =
2112-
pallet_subtensor::Alpha::<Test>::get((miner_hotkey, netuid, miner_coldkey))
2110+
crate::Alpha::<Test>::get((miner_hotkey, netuid, miner_coldkey))
21132111
- miner_alpha_before;
21142112

21152113
assert!(

pallets/subtensor/src/tests/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod block_emission;
66
mod children;
77
mod coinbase;
88
mod difficulty;
9+
mod emission;
910
mod epoch;
1011
mod math;
1112
mod migration;

0 commit comments

Comments
 (0)