diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 0bc467a94d..157f2ad955 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -90,7 +90,7 @@ jobs: - name: Setup subtensor repo working-directory: ${{ github.workspace }}/subtensor - run: git checkout testnet + run: git checkout main - name: Run tests run: | diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index c2e85352e2..1a29694b99 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -16,6 +16,7 @@ from scalecodec.exceptions import RemainingScaleBytesNotEmptyException from scalecodec.type_registry import load_type_registry_preset from scalecodec.types import ScaleType +from substrateinterface import Keypair from substrateinterface.base import QueryMapResult, SubstrateInterface from websockets.exceptions import InvalidStatus from websockets.sync import client as ws_client @@ -1532,9 +1533,11 @@ def get_transfer_fee( call_params={"dest": dest, "value": value.rao}, ) + temp_keypair = Keypair(ss58_address=wallet.coldkeypub.ss58_address) + try: payment_info = self.substrate.get_payment_info( - call=call, keypair=wallet.coldkeypub + call=call, keypair=temp_keypair ) except Exception as e: logging.error(f"[red]Failed to get payment info.[/red] {e}") diff --git a/requirements/prod.txt b/requirements/prod.txt index 12525a2305..aa39bf6bc5 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -25,5 +25,5 @@ scalecodec==1.2.11 substrate-interface~=1.7.9 uvicorn websockets>=14.1 -bittensor-wallet>=2.1.3 +bittensor-wallet>=3.0.0 bittensor-commit-reveal>=0.1.0 diff --git a/tests/e2e_tests/test_transfer.py b/tests/e2e_tests/test_transfer.py index 5a18db386e..7b95ae75bd 100644 --- a/tests/e2e_tests/test_transfer.py +++ b/tests/e2e_tests/test_transfer.py @@ -1,6 +1,9 @@ from bittensor.core.subtensor import Subtensor from bittensor.utils.balance import Balance from tests.e2e_tests.utils.e2e_test_utils import setup_wallet +from bittensor import logging + +logging.set_trace() def test_transfer(local_chain): diff --git a/tests/integration_tests/utils/test_init.py b/tests/integration_tests/utils/test_init.py index 000e94b3d8..59d613ca89 100644 --- a/tests/integration_tests/utils/test_init.py +++ b/tests/integration_tests/utils/test_init.py @@ -7,33 +7,51 @@ from bittensor import utils -def test_unlock_key(monkeypatch): +def test_unlock_through_env(): # Ensure path is clean before we run the tests - if os.path.exists("/tmp/bittensor-tests-wallets"): + if os.path.exists("/tmp/bittensor-tests-wallets/"): shutil.rmtree("/tmp/bittensor-tests-wallets") wallet = Wallet(path="/tmp/bittensor-tests-wallets") + + # Set up the coldkey cold_kf = Keyfile("/tmp/bittensor-tests-wallets/default/coldkey", name="default") kp = Keypair.create_from_mnemonic( "stool feel open east woman high can denial forget screen trust salt" ) cold_kf.set_keypair(kp, False, False) cold_kf.encrypt("1234password1234") - hot_kf = Keyfile("/tmp/bittensor-tests-wallets/default/hotkey", name="default") + + # Set up the hotkey + hot_kf = Keyfile( + "/tmp/bittensor-tests-wallets/default/hotkeys/default", name="default" + ) hkp = Keypair.create_from_mnemonic( "stool feel open east woman high can denial forget screen trust salt" ) hot_kf.set_keypair(hkp, False, False) hot_kf.encrypt("1234hotkey1234") - monkeypatch.setattr("getpass.getpass", lambda _: "badpassword1234") + + # Save a wrong password to the environment for CK + cold_kf.save_password_to_env("badpassword") result = utils.unlock_key(wallet) assert result.success is False - monkeypatch.setattr("getpass.getpass", lambda _: "1234password1234") + + # Save correct password to the environment for CK + cold_kf.save_password_to_env("1234password1234") result = utils.unlock_key(wallet) assert result.success is True - monkeypatch.setattr("getpass.getpass", lambda _: "badpassword1234") + + # Save a wrong password to the environment for HK + hot_kf.save_password_to_env("badpassword") result = utils.unlock_key(wallet, "hotkey") assert result.success is False + + # Save correct password to the environment for HK + hot_kf.save_password_to_env("1234hotkey1234") + result = utils.unlock_key(wallet, "hotkey") + assert result.success is True + with pytest.raises(ValueError): utils.unlock_key(wallet, "mycoldkey") diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 53754764e1..fc0ad7c6f7 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -19,9 +19,14 @@ def test_py_config_parsed_successfully_rust_wallet(): config.wallet.hotkey = "new_hotkey" config.wallet.path = "/some/not_default/path" + # Pass in the whole bittensor config wallet = bittensor.wallet(config=config) - - # Asserts assert wallet.name == config.wallet.name assert wallet.hotkey_str == config.wallet.hotkey assert wallet.path == config.wallet.path + + # Pass in only the btwallet's config + wallet_two = bittensor.wallet(config=config.wallet) + assert wallet_two.name == config.wallet.name + assert wallet_two.hotkey_str == config.wallet.hotkey + assert wallet_two.path == config.wallet.path diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 5b9e15339d..7cd0ed19f5 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -1739,6 +1739,8 @@ def test_get_transfer_fee(subtensor, mocker): fake_payment_info = {"partialFee": int(2e10)} subtensor.substrate.get_payment_info.return_value = fake_payment_info + mocker.patch.object(subtensor_module, "Keypair", return_value=mocker.MagicMock()) + # Call result = subtensor.get_transfer_fee(wallet=fake_wallet, dest=fake_dest, value=value) @@ -1751,7 +1753,7 @@ def test_get_transfer_fee(subtensor, mocker): subtensor.substrate.get_payment_info.assert_called_once_with( call=subtensor.substrate.compose_call.return_value, - keypair=fake_wallet.coldkeypub, + keypair=subtensor_module.Keypair.return_value, ) assert result == 2e10