|
7 | 7 | from bittensor import utils
|
8 | 8 |
|
9 | 9 |
|
10 |
| -def test_unlock_key(monkeypatch): |
| 10 | +def test_unlock_through_env(): |
11 | 11 | # Ensure path is clean before we run the tests
|
12 |
| - if os.path.exists("/tmp/bittensor-tests-wallets"): |
| 12 | + if os.path.exists("/tmp/bittensor-tests-wallets/"): |
13 | 13 | shutil.rmtree("/tmp/bittensor-tests-wallets")
|
14 | 14 |
|
15 | 15 | wallet = Wallet(path="/tmp/bittensor-tests-wallets")
|
| 16 | + |
| 17 | + # Set up the coldkey |
16 | 18 | cold_kf = Keyfile("/tmp/bittensor-tests-wallets/default/coldkey", name="default")
|
17 | 19 | kp = Keypair.create_from_mnemonic(
|
18 | 20 | "stool feel open east woman high can denial forget screen trust salt"
|
19 | 21 | )
|
20 | 22 | cold_kf.set_keypair(kp, False, False)
|
21 | 23 | cold_kf.encrypt("1234password1234")
|
22 |
| - hot_kf = Keyfile("/tmp/bittensor-tests-wallets/default/hotkey", name="default") |
| 24 | + |
| 25 | + # Set up the hotkey |
| 26 | + hot_kf = Keyfile( |
| 27 | + "/tmp/bittensor-tests-wallets/default/hotkeys/default", name="default" |
| 28 | + ) |
23 | 29 | hkp = Keypair.create_from_mnemonic(
|
24 | 30 | "stool feel open east woman high can denial forget screen trust salt"
|
25 | 31 | )
|
26 | 32 | hot_kf.set_keypair(hkp, False, False)
|
27 | 33 | hot_kf.encrypt("1234hotkey1234")
|
28 |
| - monkeypatch.setattr("getpass.getpass", lambda _: "badpassword1234") |
| 34 | + |
| 35 | + # Save a wrong password to the environment for CK |
| 36 | + cold_kf.save_password_to_env("badpassword") |
29 | 37 | result = utils.unlock_key(wallet)
|
30 | 38 | assert result.success is False
|
31 |
| - monkeypatch.setattr("getpass.getpass", lambda _: "1234password1234") |
| 39 | + |
| 40 | + # Save correct password to the environment for CK |
| 41 | + cold_kf.save_password_to_env("1234password1234") |
32 | 42 | result = utils.unlock_key(wallet)
|
33 | 43 | assert result.success is True
|
34 |
| - monkeypatch.setattr("getpass.getpass", lambda _: "badpassword1234") |
| 44 | + |
| 45 | + # Save a wrong password to the environment for HK |
| 46 | + hot_kf.save_password_to_env("badpassword") |
35 | 47 | result = utils.unlock_key(wallet, "hotkey")
|
36 | 48 | assert result.success is False
|
| 49 | + |
| 50 | + # Save correct password to the environment for HK |
| 51 | + hot_kf.save_password_to_env("1234hotkey1234") |
| 52 | + result = utils.unlock_key(wallet, "hotkey") |
| 53 | + assert result.success is True |
| 54 | + |
37 | 55 | with pytest.raises(ValueError):
|
38 | 56 | utils.unlock_key(wallet, "mycoldkey")
|
39 | 57 |
|
|
0 commit comments