bittensor.utils.mock.subtensor_mock#
Attributes#
Classes#
dict() -> new empty dictionary |
|
A Mock Subtensor class for running tests. |
|
dict() -> new empty dictionary |
|
dict() -> new empty dictionary |
|
Module Contents#
- bittensor.utils.mock.subtensor_mock.BlockNumber#
- class bittensor.utils.mock.subtensor_mock.InfoDict[source]#
Bases:
collections.abc.Mapping
- class bittensor.utils.mock.subtensor_mock.MockChainState[source]#
Bases:
TypedDict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.
- SubtensorModule: MockSubtensorState#
- System: MockSystemState#
- class bittensor.utils.mock.subtensor_mock.MockMapResult(records=None)[source]#
- Parameters:
records (Optional[list[tuple[Union[Any, MockSubtensorValue], Union[Any, MockSubtensorValue]]]])
- records: list[tuple[MockSubtensorValue, MockSubtensorValue]] | None#
- class bittensor.utils.mock.subtensor_mock.MockSubtensor(*args, **kwargs)[source]#
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 an instance of the Subtensor class.
- Parameters:
network – The network name or type to connect to.
config – Configuration object for the AsyncSubtensor instance.
log_verbose – Enables or disables verbose logging.
fallback_endpoints – List of fallback endpoints to use if default or provided network is not available. Defaults to None.
retry_forever – Whether to retry forever on connection errors. Defaults to False.
_mock – Whether this is a mock instance. Mainly just for use in testing.
- Raises:
Any exceptions raised during the setup, configuration, or connection process. –
- chain_state: MockChainState#
- commit(wallet, netuid, data)[source]#
Commits arbitrary data to the Bittensor network by publishing metadata.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron committing the data.
netuid (int) – The unique identifier of the subnetwork.
data (str) – The data to be committed to the network.
period (Optional[int]) – The number of blocks during which the transaction will remain valid after it’s submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction.
- Returns:
True if the commitment was successful, False otherwise.
- Return type:
- do_serve_prometheus(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)[source]#
- do_set_weights(wallet, netuid, uids, vals, version_key, wait_for_inclusion=False, wait_for_finalization=True)[source]#
- do_transfer(wallet, dest, transfer_balance, wait_for_inclusion=True, wait_for_finalization=False)[source]#
- force_register_neuron(netuid, hotkey, coldkey, stake=Balance(0), balance=Balance(0))#
Force register a neuron on the mock chain, returning the UID.
- Parameters:
netuid (int)
hotkey (str)
coldkey (str)
stake (Union[bittensor.utils.balance.Balance, float, int])
balance (Union[bittensor.utils.balance.Balance, float, int])
- Return type:
- get_balance(address, block=None)[source]#
Retrieves the balance for given coldkey.
- Parameters:
- Returns:
Balance object.
- Return type:
- get_block_hash(block=None)[source]#
- 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 (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)[source]#
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()[source]#
- 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)[source]#
- 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()[source]#
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)[source]#
- 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, a null neuron otherwise
- Return type:
Optional[bittensor.core.chain_data.NeuronInfo]
- 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)[source]#
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:
list[bittensor.core.chain_data.NeuronInfo]
- 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)[source]#
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.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)[source]#
- 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[async_substrate_interface.types.ScaleObj]
- 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=None)[source]#
Note: Double map requires one param
- Parameters:
- Return type:
Optional[MockMapResult]
- query_subtensor(name, block=None, params=None)[source]#
- 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
- 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.
- sudo_force_set_balance#
- class bittensor.utils.mock.subtensor_mock.MockSubtensorState[source]#
Bases:
TypedDict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.
- class bittensor.utils.mock.subtensor_mock.MockSystemState[source]#
Bases:
TypedDict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.