Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates tests for btwallet 3.0.0 #2540

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,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
30 changes: 24 additions & 6 deletions tests/integration_tests/utils/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
9 changes: 7 additions & 2 deletions tests/unit_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading