Skip to content

Commit

Permalink
fix mock return values
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Jul 4, 2023
1 parent d47e0c9 commit 2df31eb
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions bittensor/_subtensor/subtensor_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,23 +887,23 @@ def _do_delegation(
amount: 'bittensor.Balance',
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
) -> Tuple[bool, Optional[str]]:
# Check if delegate
if not self.is_hotkey_delegate(
hotkey_ss58 = delegate_ss58
):
raise Exception("Not a delegate")

# do stake
success = self._do_stake(
success, error_msg = self._do_stake(
wallet = wallet,
hotkey_ss58 = delegate_ss58,
amount = amount,
wait_for_inclusion = wait_for_inclusion,
wait_for_finalization = wait_for_finalization,
)

return success
return success, error_msg


def _do_undelegation(
Expand All @@ -913,42 +913,44 @@ def _do_undelegation(
amount: 'bittensor.Balance',
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
) -> Tuple[bool, Optional[str]]:
# Check if delegate
if not self.is_hotkey_delegate(
hotkey_ss58 = delegate_ss58
):
raise Exception("Not a delegate")

# do unstake
self._do_unstake(
response = self._do_unstake(
wallet = wallet,
hotkey_ss58 = delegate_ss58,
amount = amount,
wait_for_inclusion = wait_for_inclusion,
wait_for_finalization = wait_for_finalization,
)

return response

def _do_nominate(
self,
wallet: 'bittensor.Wallet',
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
) -> Tuple[bool, Optional[str]]:
hotkey_ss58 = wallet.hotkey.ss58_address
coldkey_ss58 = wallet.coldkeypub.ss58_address

subtensor_state = self.chain_state['SubtensorModule']
if self.is_hotkey_delegate(
hotkey_ss58=hotkey_ss58
):
return True
return True, None

else:
subtensor_state['Delegates'][hotkey_ss58] = {}
subtensor_state['Delegates'][hotkey_ss58][self.block_number] = 0.18 # Constant for now

return True
return True, None

def get_transfer_fee(
self,
Expand Down Expand Up @@ -1048,7 +1050,7 @@ def _do_stake(
amount: 'bittensor.Balance',
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
) -> Tuple[bool, Optional[str]]:
subtensor_state = self.chain_state['SubtensorModule']

bal = self.get_balance( wallet.coldkeypub.ss58_address )
Expand Down Expand Up @@ -1101,7 +1103,7 @@ def _do_stake(
# Remove from free balance
self.chain_state['System']['Account'][wallet.coldkeypub.ss58_address]['data']['free'][self.block_number] = (bal - amount).rao

return True
return True, None

def _do_unstake(
self,
Expand All @@ -1110,7 +1112,7 @@ def _do_unstake(
amount: 'bittensor.Balance',
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
) -> Tuple[bool, Optional[str]]:
subtensor_state = self.chain_state['SubtensorModule']

bal = self.get_balance( wallet.coldkeypub.ss58_address )
Expand All @@ -1127,7 +1129,7 @@ def _do_unstake(
stake_state = subtensor_state['Stake']

if curr_stake.rao == 0:
return True
return True, None

# Unstake the funds
# We know that the hotkey has stake, so we can just remove it
Expand Down Expand Up @@ -1158,7 +1160,7 @@ def _do_unstake(

self.chain_state['System']['Account'][wallet.coldkeypub.ss58_address]['data']['free'][self.block_number] = (bal + amount).rao

return True
return True, None


def get_delegate_by_hotkey( self, hotkey_ss58: str, block: Optional[int] = None ) -> Optional['bittensor.DelegateInfo']:
Expand Down

0 comments on commit 2df31eb

Please sign in to comment.