Skip to content

Commit

Permalink
Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhaleking committed Sep 27, 2024
1 parent c0c6ef8 commit 6f82d44
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
83 changes: 47 additions & 36 deletions bittensor_cli/src/bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,8 @@ def fix_decoded_values(cls, decoded: dict) -> "DynamicInfo":
alpha_out = Balance.from_rao(decoded["alpha_out"]).set_unit(netuid)
alpha_in = Balance.from_rao(decoded["alpha_in"]).set_unit(netuid)
tao_in = Balance.from_rao(decoded["tao_in"]).set_unit(0)
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(
netuid
)
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(
netuid
)
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(netuid)
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(netuid)
price = (
Balance.from_tao(tao_in.tao / alpha_in.tao)
if alpha_in.tao > 0
Expand Down Expand Up @@ -766,6 +762,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> tuple[Balance, Balance]:
@dataclass
class DynamicPoolInfoV2:
"""Dataclass for dynamic pool info."""

netuid: int
alpha_issuance: int
alpha_outstanding: int
Expand Down Expand Up @@ -836,10 +833,12 @@ def __init__(
self.price = Balance.from_tao(1.0)

def __str__(self) -> str:
return (f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
f"alpha_outstanding={self.alpha_outstanding}, "
f"alpha_reserve={self.alpha_reserve}, "
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )")
return (
f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
f"alpha_outstanding={self.alpha_outstanding}, "
f"alpha_reserve={self.alpha_reserve}, "
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )"
)

def __repr__(self) -> str:
return self.__str__()
Expand Down Expand Up @@ -922,6 +921,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> Tuple[Balance, Balance]:
@dataclass
class ScheduledColdkeySwapInfo:
"""Dataclass for scheduled coldkey swap information."""

old_coldkey: str
new_coldkey: str
arbitration_block: int
Expand Down Expand Up @@ -966,9 +966,7 @@ def decode_account_id_list(cls, vec_u8: list[int]) -> Optional[list[str]]:
)
if decoded is None:
return None
return [
ss58_encode(account_id, SS58_FORMAT) for account_id in decoded
]
return [ss58_encode(account_id, SS58_FORMAT) for account_id in decoded]


@dataclass
Expand All @@ -994,42 +992,56 @@ class SubnetState:

@classmethod
def from_vec_u8(cls, vec_u8: list[int]) -> Optional["SubnetState"]:
if len(vec_u8) == 0: return None
if len(vec_u8) == 0:
return None
decoded = from_scale_encoding(vec_u8, ChainDataType.SubnetState, is_option=True)
if decoded is None: return None
if decoded is None:
return None
return SubnetState.fix_decoded_values(decoded)

@classmethod
def list_from_vec_u8(cls, vec_u8: list[int]) -> list["SubnetState"]:
decoded = from_scale_encoding( vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True )
if decoded is None:return []
decoded = from_scale_encoding(
vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True
)
if decoded is None:
return []
decoded = [SubnetState.fix_decoded_values(d) for d in decoded]
return decoded

@classmethod
def fix_decoded_values(cls, decoded: dict) -> "SubnetState":
netuid = decoded["netuid"]
return SubnetState(
netuid = netuid,
hotkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]],
coldkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]],
active = decoded["active"],
validator_permit = decoded["validator_permit"],
pruning_score = [u16_normalized_float(val) for val in decoded["pruning_score"]],
last_update = decoded["last_update"],
emission = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["emission"]],
dividends = [u16_normalized_float(val) for val in decoded["dividends"]],
incentives = [u16_normalized_float(val) for val in decoded["incentives"]],
consensus = [u16_normalized_float(val) for val in decoded["consensus"]],
trust = [u16_normalized_float(val) for val in decoded["trust"]],
rank = [u16_normalized_float(val) for val in decoded["rank"]],
block_at_registration = decoded["block_at_registration"],
local_stake = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["local_stake"]],
global_stake = [Balance.from_rao( val ).set_unit(0) for val in decoded["global_stake"]],
stake_weight = [u16_normalized_float(val) for val in decoded["stake_weight"]],
emission_history = decoded["emission_history"]
netuid=netuid,
hotkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]],
coldkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]],
active=decoded["active"],
validator_permit=decoded["validator_permit"],
pruning_score=[
u16_normalized_float(val) for val in decoded["pruning_score"]
],
last_update=decoded["last_update"],
emission=[
Balance.from_rao(val).set_unit(netuid) for val in decoded["emission"]
],
dividends=[u16_normalized_float(val) for val in decoded["dividends"]],
incentives=[u16_normalized_float(val) for val in decoded["incentives"]],
consensus=[u16_normalized_float(val) for val in decoded["consensus"]],
trust=[u16_normalized_float(val) for val in decoded["trust"]],
rank=[u16_normalized_float(val) for val in decoded["rank"]],
block_at_registration=decoded["block_at_registration"],
local_stake=[
Balance.from_rao(val).set_unit(netuid) for val in decoded["local_stake"]
],
global_stake=[
Balance.from_rao(val).set_unit(0) for val in decoded["global_stake"]
],
stake_weight=[u16_normalized_float(val) for val in decoded["stake_weight"]],
emission_history=decoded["emission_history"],
)


class SubstakeElements:
@staticmethod
def decode(result: list[int]) -> list[dict]:
Expand All @@ -1049,7 +1061,6 @@ def decode(result: list[int]) -> list[dict]:
return result



custom_rpc_type_registry = {
"types": {
"SubnetInfo": {
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def read_requirements(path):
long_description_content_type="text/markdown",
url="https://github.com/opentensor/btcli",
author="bittensor.com",
packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"]) + ['bittensor_cli.src.bittensor.templates'],
packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"])
+ ["bittensor_cli.src.bittensor.templates"],
include_package_data=True,
package_data={
"": ["templates/*"],
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e_tests/test_senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_senate(local_chain, wallet_setup):

# Assert Bob is now part of the senate
assert wallet_bob.hotkey.ss58_address in root_senate_after_reg.stdout

# Manually add a proposal on the chain & assert
success = asyncio.run(call_add_proposal(local_chain, wallet_bob))
assert success is True
Expand Down Expand Up @@ -154,10 +154,10 @@ def test_senate(local_chain, wallet_setup):
assert proposals_after_aye_output[5] == "Aye"

# Aye votes increased to 1
assert proposals_after_aye_output[2] == '1'
assert proposals_after_aye_output[2] == "1"

# Nay votes remain 0
assert proposals_after_aye_output[3] == '0'
assert proposals_after_aye_output[3] == "0"

# Register Alice to the root network (0)
# Registering to root automatically makes you a senator if eligible
Expand Down
12 changes: 9 additions & 3 deletions tests/e2e_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from bittensor_wallet import Wallet

if TYPE_CHECKING:
from bittensor_cli.src.bittensor.async_substrate_interface import AsyncSubstrateInterface
from bittensor_cli.src.bittensor.async_substrate_interface import (
AsyncSubstrateInterface,
)

template_path = os.getcwd() + "/neurons/"
templates_repo = "templates repository"
Expand Down Expand Up @@ -287,7 +289,9 @@ def uninstall_templates(install_dir):
shutil.rmtree(install_dir)


async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet) -> bool:
async def call_add_proposal(
substrate: "AsyncSubstrateInterface", wallet: Wallet
) -> bool:
async with substrate:
proposal_call = await substrate.compose_call(
call_module="System",
Expand All @@ -304,7 +308,9 @@ async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet
},
)

extrinsic = await substrate.create_signed_extrinsic(call=call, keypair=wallet.coldkey)
extrinsic = await substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
)
response = await substrate.submit_extrinsic(
extrinsic,
wait_for_inclusion=True,
Expand Down

0 comments on commit 6f82d44

Please sign in to comment.