diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index b5c09ece0..781f9c5a0 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -28,6 +28,12 @@ pub struct NeuronInfo { pruning_score: Compact, } +impl NeuronInfo { + pub fn stake(&self) -> &[(T::AccountId, Compact)] { + &self.stake + } +} + #[freeze_struct("c21f0f4f22bcb2a1")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] pub struct NeuronInfoLite { @@ -52,6 +58,12 @@ pub struct NeuronInfoLite { pruning_score: Compact, } +impl NeuronInfoLite { + pub fn stake(&self) -> &[(T::AccountId, Compact)] { + &self.stake + } +} + impl Pallet { pub fn get_neurons(netuid: u16) -> Vec> { if !Self::if_subnet_exist(netuid) { diff --git a/pallets/subtensor/src/rpc_info/stake_info.rs b/pallets/subtensor/src/rpc_info/stake_info.rs index f5c87744d..32b47d15a 100644 --- a/pallets/subtensor/src/rpc_info/stake_info.rs +++ b/pallets/subtensor/src/rpc_info/stake_info.rs @@ -18,6 +18,12 @@ pub struct StakeInfo { is_registered: bool, } +impl StakeInfo { + pub fn stake(&self) -> Compact { + self.stake + } +} + impl Pallet { fn _get_stake_info_for_coldkeys( coldkeys: Vec, diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 4cd2af3b6..03cf79551 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1,6 +1,7 @@ #![allow(clippy::unwrap_used)] #![allow(clippy::arithmetic_side_effects)] +use codec::Encode; use frame_support::{assert_err, assert_noop, assert_ok, traits::Currency}; use frame_system::Config; mod mock; @@ -2490,3 +2491,27 @@ fn test_anneal_global_weight() { ); }); } + +// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test staking -- test_stake_value_is_alpha --exact --nocapture +#[test] +fn test_stake_value_is_alpha() { + new_test_ext(1).execute_with(|| { + let hotkey_id = U256::from(5445); + let coldkey_id = U256::from(5443433); + let amount: u64 = 10000; + let netuid: u16 = 1; + let tempo: u16 = 13; + let start_nonce: u64 = 0; + + add_network(netuid, tempo, 0); + + register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); + + SubtensorModule::stake_into_subnet(&hotkey_id, &coldkey_id, netuid, amount); + + let stake_info = SubtensorModule::get_stake_info_for_coldkey(Encode::encode(&coldkey_id)); + let neuron_info = SubtensorModule::get_neuron_lite(netuid, 0); + + assert_eq!(stake_info[0].stake(), neuron_info.unwrap().stake()[0].1); + }); +}