Skip to content

Commit

Permalink
Improve MockSubtensor (#2469)
Browse files Browse the repository at this point in the history
Improve MockSubtensor including missing method and mutable default args.
  • Loading branch information
thewhaleking authored Nov 25, 2024
1 parent e147653 commit 7576dac
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions bittensor/utils/mock/subtensor_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,10 @@ def query_subtensor(
self,
name: str,
block: Optional[int] = None,
params: Optional[list[object]] = [],
params: Optional[list[object]] = None,
) -> MockSubtensorValue:
if params is None:
params = []
if block:
if self.block_number < block:
raise Exception("Cannot query block in the future")
Expand Down Expand Up @@ -477,11 +479,13 @@ def query_map_subtensor(
self,
name: str,
block: Optional[int] = None,
params: Optional[list[object]] = [],
params: Optional[list[object]] = None,
) -> Optional[MockMapResult]:
"""
Note: Double map requires one param
"""
if params is None:
params = []
if block:
if self.block_number < block:
raise Exception("Cannot query block in the future")
Expand Down Expand Up @@ -535,7 +539,7 @@ def query_constant(
else:
block = self.block_number

state = self.chain_state.get(module_name, None)
state: Optional[dict] = self.chain_state.get(module_name, None)
if state is not None:
if constant_name in state:
state = state[constant_name]
Expand Down Expand Up @@ -812,6 +816,52 @@ def neurons_lite(

return neurons

def neuron_for_uid_lite(
self, uid: int, netuid: int, block: Optional[int] = None
) -> Optional[NeuronInfoLite]:
if uid is None:
return NeuronInfoLite.get_null_neuron()

if block:
if self.block_number < block:
raise Exception("Cannot query block in the future")

else:
block = self.block_number

if netuid not in self.chain_state["SubtensorModule"]["NetworksAdded"]:
return None

neuron_info = self._neuron_subnet_exists(uid, netuid, block)
if neuron_info is None:
# TODO Why does this return None here but a null neuron earlier?
return None

else:
return NeuronInfoLite(
hotkey=neuron_info.hotkey,
coldkey=neuron_info.coldkey,
uid=neuron_info.uid,
netuid=neuron_info.netuid,
active=neuron_info.active,
stake=neuron_info.stake,
stake_dict=neuron_info.stake_dict,
total_stake=neuron_info.total_stake,
rank=neuron_info.rank,
emission=neuron_info.emission,
incentive=neuron_info.incentive,
consensus=neuron_info.consensus,
trust=neuron_info.trust,
validator_trust=neuron_info.validator_trust,
dividends=neuron_info.dividends,
last_update=neuron_info.last_update,
validator_permit=neuron_info.validator_permit,
prometheus_info=neuron_info.prometheus_info,
axon_info=neuron_info.axon_info,
pruning_score=neuron_info.pruning_score,
is_null=neuron_info.is_null,
)

def get_transfer_fee(
self, wallet: "Wallet", dest: str, value: Union["Balance", float, int]
) -> "Balance":
Expand Down

0 comments on commit 7576dac

Please sign in to comment.