bittensor.utils.mock#
Submodules#
Classes#
A Mock Subtensor class for running tests. |
Package Contents#
- class bittensor.utils.mock.MockSubtensor(*args, **kwargs)#
Bases:
bittensor.core.subtensor.Subtensor
A Mock Subtensor class for running tests. This should mock only methods that make queries to the chain. e.g. We mock Subtensor.query_subtensor instead of all query methods.
This class will also store a local (mock) state of the chain.
Initializes a Subtensor interface for interacting with the Bittensor blockchain.
Note
Currently subtensor defaults to the
finney
network. This will change in a future release.We strongly encourage users to run their own local subtensor node whenever possible. This increases decentralization and resilience of the network. In a future release, local subtensor will become the default and the fallback to
finney
removed. Please plan ahead for this change. We will provide detailed instructions on how to run a local subtensor node in the documentation in a subsequent release.- Parameters:
network (Optional[str]) – The network name to connect to (e.g.,
finney
,local
). This can also be the chain endpoint (e.g.,wss://entrypoint-finney.opentensor.ai:443
) and will be correctly parsed into the network and chain endpoint. If not specified, defaults to the main Bittensor network.config (Optional[bittensor.core.config.Config]) – Configuration object for the subtensor. If not provided, a default configuration is used.
_mock (bool) – If set to
True
, uses a mocked connection for testing purposes. Default isFalse
.log_verbose (bool) – Whether to enable verbose logging. If set to
True
, detailed log information about the connection and network operations will be provided. Default isTrue
.connection_timeout (int) – The maximum time in seconds to keep the connection alive. Default is
600
.
This initialization sets up the connection to the specified Bittensor network, allowing for various blockchain operations such as neuron registration, stake management, and setting weights.
- __dict__#
- static _convert_to_balance(balance)#
- Parameters:
balance (Union[bittensor.utils.balance.Balance, float, int])
- Return type:
- _get_axon_info(netuid, hotkey, block=None)#
- Parameters:
- Return type:
- static _get_most_recent_storage(storage, block_number=None)#
- _get_prometheus_info(netuid, hotkey, block=None)#
- Parameters:
- Return type:
- _handle_type_default(name, params)#
- _neuron_subnet_exists(uid, netuid, block=None)#
- Parameters:
- Return type:
Optional[bittensor.core.chain_data.NeuronInfo]
- chain_state: MockChainState#
- commit(wallet, netuid, data)#
Commits arbitrary data to the Bittensor network by publishing metadata.
- do_block_step()#
- Return type:
None
- do_serve_axon(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)#
- do_serve_prometheus(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)#
- do_set_weights(wallet, netuid, uids, vals, version_key, wait_for_inclusion=False, wait_for_finalization=True)#
- do_transfer(wallet, dest, transfer_balance, wait_for_inclusion=True, wait_for_finalization=False)#
- force_set_balance(ss58_address, balance=Balance(0))#
- get_balance(address, block=None)#
Retrieves the token balance of a specific address within the Bittensor network. This function queries the blockchain to determine the amount of Tao held by a given account.
- Parameters:
- Returns:
The account balance at the specified block, represented as a Balance object.
- Return type:
This function is important for monitoring account holdings and managing financial transactions within the Bittensor ecosystem. It helps in assessing the economic status and capacity of network participants.
- get_block_hash(block_id)#
Retrieves the hash of a specific block on the Bittensor blockchain. The block hash is a unique identifier representing the cryptographic hash of the block’s content, ensuring its integrity and immutability.
- Parameters:
block_id (int) – The block number for which the hash is to be retrieved.
- Returns:
The cryptographic hash of the specified block.
- Return type:
The block hash is a fundamental aspect of blockchain technology, providing a secure reference to each block’s data. It is crucial for verifying transactions, ensuring data consistency, and maintaining the trustworthiness of the blockchain.
- get_commitment(netuid, uid, block=None)#
Retrieves the on-chain commitment for a specific neuron in the Bittensor network.
- Parameters:
- Returns:
The commitment data as a string.
- Return type:
- get_current_block()#
Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.
- Returns:
The current chain block number.
- Return type:
Knowing the current block number is essential for querying real-time data and performing time-sensitive operations on the blockchain. It serves as a reference point for network activities and data synchronization.
- get_transfer_fee(wallet, dest, value)#
Calculates the transaction fee for transferring tokens from a wallet to a specified destination address. This function simulates the transfer to estimate the associated cost, taking into account the current network conditions and transaction complexity.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet from which the transfer is initiated.
dest (str) – The
SS58
address of the destination account.value (Union[bittensor.utils.balance.Balance, float, int]) – The amount of tokens to be transferred, specified as a Balance object, or in Tao (float) or Rao (int) units.
- Returns:
The estimated transaction fee for the transfer, represented as a Balance object.
- Return type:
Estimating the transfer fee is essential for planning and executing token transactions, ensuring that the wallet has sufficient funds to cover both the transfer amount and the associated costs. This function provides a crucial tool for managing financial operations within the Bittensor network.
- static min_required_stake()#
As the minimum required stake may change, this method allows us to dynamically update the amount in the mock without updating the tests
- neuron_for_uid(uid, netuid, block=None)#
Retrieves detailed information about a specific neuron identified by its unique identifier (UID) within a specified subnet (netuid) of the Bittensor network. This function provides a comprehensive view of a neuron’s attributes, including its stake, rank, and operational status.
- Parameters:
- Returns:
Detailed information about the neuron if found,
None
otherwise.- Return type:
This function is crucial for analyzing individual neurons’ contributions and status within a specific subnet, offering insights into their roles in the network’s consensus and validation mechanisms.
- neurons(netuid, block=None)#
Retrieves a list of all neurons within a specified subnet of the Bittensor network. This function provides a snapshot of the subnet’s neuron population, including each neuron’s attributes and network interactions.
- Parameters:
- Returns:
A list of NeuronInfo objects detailing each neuron’s characteristics in the subnet.
- Return type:
Understanding the distribution and status of neurons within a subnet is key to comprehending the network’s decentralized structure and the dynamics of its consensus and governance processes.
- neurons_lite(netuid, block=None)#
Retrieves a list of neurons in a ‘lite’ format from a specific subnet of the Bittensor network. This function provides a streamlined view of the neurons, focusing on key attributes such as stake and network participation.
- Parameters:
- Returns:
A list of simplified neuron information for the subnet.
- Return type:
list[bittensor.core.chain_data.neuron_info_lite.NeuronInfoLite]
This function offers a quick overview of the neuron population within a subnet, facilitating efficient analysis of the network’s decentralized structure and neuron dynamics.
- query_constant(module_name, constant_name, block=None)#
Retrieves a constant from the specified module on the Bittensor blockchain. This function is used to access fixed parameters or values defined within the blockchain’s modules, which are essential for understanding the network’s configuration and rules.
- Parameters:
- Returns:
The value of the constant if found,
None
otherwise.- Return type:
Optional[scalecodec.ScaleType]
Constants queried through this function can include critical network parameters such as inflation rates, consensus rules, or validation thresholds, providing a deeper understanding of the Bittensor network’s operational parameters.
- query_map_subtensor(name, block=None, params=[])#
Note: Double map requires one param
- Parameters:
- Return type:
Optional[MockMapResult]
- query_subtensor(name, block=None, params=[])#
Queries named storage from the Subtensor module on the Bittensor blockchain. This function is used to retrieve specific data or parameters from the blockchain, such as stake, rank, or other neuron-specific attributes.
- Parameters:
- Returns:
An object containing the requested data.
- Return type:
query_response (scalecodec.ScaleType)
This query function is essential for accessing detailed information about the network and its neurons, providing valuable insights into the state and dynamics of the Bittensor ecosystem.
- classmethod reset()#
- Return type:
None
- setup()#
- Return type:
None
- sudo_force_set_balance#