Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from typing import Union, Optional
from bittensor import Balance, NeuronInfo, axon_info, PrometheusInfo, Keypair, __ss58_format__
from scalecodec import ss58_encode
from typing import Union
from bittensor import Balance, NeuronInfo, axon_info, PrometheusInfo, __ss58_format__
from rich.console import Console
from rich.text import Text

from tests.mocks.wallet_mock import MockWallet

from Crypto.Hash import keccak
from bittensor_wallet.mock import MockWallet as MockWallet
from bittensor_wallet.mock.utils import get_mock_wallet as get_mock_wallet, get_mock_hotkey, get_mock_coldkey

class CLOSE_IN_VALUE():
value: Union[float, int, Balance]
Expand All @@ -40,24 +38,7 @@ def __eq__(self, __o: Union[float, int, Balance]) -> bool:
((__o - self.tolerance) <= self.value and self.value <= (__o + self.tolerance))


def get_mock_keypair( uid: int, test_name: Optional[str] = None ) -> Keypair:
"""
Returns a mock keypair from a uid and optional test_name.
If test_name is not provided, the uid is the only seed.
If test_name is provided, the uid is hashed with the test_name to create a unique seed for the test.
"""
if test_name is not None:
hashed_test_name: bytes = keccak.new(digest_bits=256, data=test_name.encode('utf-8')).digest()
hashed_test_name_as_int: int = int.from_bytes(hashed_test_name, byteorder='big', signed=False)
uid = uid + hashed_test_name_as_int

return Keypair.create_from_seed( seed_hex = int.to_bytes(uid, 32, 'big', signed=False), ss58_format = __ss58_format__)

def get_mock_hotkey( uid: int ) -> str:
return get_mock_keypair(uid).ss58_address

def get_mock_coldkey( uid: int ) -> str:
return get_mock_keypair(uid).ss58_address

def get_mock_neuron(**kwargs) -> NeuronInfo:
"""
Expand Down Expand Up @@ -129,24 +110,6 @@ def get_mock_neuron_by_uid( uid: int, **kwargs ) -> NeuronInfo:
**kwargs
)

def get_mock_wallet(coldkey: "Keypair" = None, hotkey: "Keypair" = None):
wallet = MockWallet(
name = 'mock_wallet',
hotkey = 'mock',
path = '/tmp/mock_wallet',
)

if not coldkey:
coldkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
if not hotkey:
hotkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())

wallet.set_coldkey(coldkey, encrypt=False, overwrite=True)
wallet.set_coldkeypub(coldkey, encrypt=False, overwrite=True)
wallet.set_hotkey(hotkey, encrypt=False, overwrite=True)

return wallet

class MockStatus:
def __enter__(self):
return self
Expand Down
19 changes: 0 additions & 19 deletions tests/mocks/__init__.py

This file was deleted.

82 changes: 0 additions & 82 deletions tests/mocks/keyfile_mock.py

This file was deleted.

79 changes: 0 additions & 79 deletions tests/mocks/wallet_mock.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/unit_tests/bittensor_tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
from bittensor.utils.registration import _CUDASolver, _SolverBase
from bittensor._subtensor.subtensor_mock import MockSubtensor

from tests.mocks.wallet_mock import MockWallet
from tests.helpers import get_mock_wallet as generate_wallet, get_mock_keypair
from tests.helpers import get_mock_wallet as generate_wallet, get_mock_keypair, MockWallet


@fixture(scope="function")
Expand Down