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

migrating to hwi 2.1.0 #1693

Merged
merged 19 commits into from
Jul 5, 2022
Merged
Changes from 1 commit
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
64 changes: 57 additions & 7 deletions tests/test_hwi_rpc.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,77 @@
""" This is just a manual test to understand how HWI works. All tests are marked skipped as hardware plugged in is necessary.
Don't take this as best practise. I doubt, this is just something to test difference in behaviour for migration from HWI 2.0.2 to 2.1.0
"""

import logging
import io
import pytest
from cryptoadvance.specter.hwi_rpc import HWIBridge
from cryptoadvance.specter.util.descriptor import Descriptor


def test_enumerate(caplog):
# @pytest.mark.skip()
def test_trezor(caplog, monkeypatch):
"""In order to get this test working, you have to run it with "-s":
pytest tests/test_hwi_rpc.py::test_enumerate_trezor -vv -s
"""
caplog.set_level(logging.DEBUG)

hwi = HWIBridge()
# bla = hwi.detect_device()

res = hwi.enumerate(passphrase="")[0]

print(res)
# seems to be normal
assert res["type"] == "trezor"
assert res["model"] == "trezor_1"
assert res["path"] == "webusb:003:1:1:1:2"
assert res["error"].startswith(
"Could not open client or get fingerprint information: Passphrase needs to be specified before the fingerprint information can be retrieved"
)
assert res["path"].startswith("webusb:003:1:1:")

if res["needs_pin_sent"]:
assert res["error"].startswith(
"Could not open client or get fingerprint information: Trezor is locked"
)

else:
assert res["error"].startswith(
"Could not open client or get fingerprint information: Passphrase needs to be specified before the fingerprint information can be retrieved"
)
assert len(res["fingerprint"]) == 8
assert res["code"] == -12
assert res["fingerprint"] == "1ef4e492"

res = hwi.prompt_pin(device_type="trezor", passphrase="")
assert res["success"] == True
# monkeypatch.setattr('sys.stdin', io.StringIO('my input'))
pin = input("Enter pin: ")

res = hwi.send_pin(pin, device_type="trezor", passphrase="")
assert res["success"] == True
results = hwi.extract_xpubs(chain="test", device_type="trezor").split("\n")
assert len(results) == 9
assert results[0].startswith("[")
assert results == None


def test_jade(caplog):
caplog.set_level(logging.DEBUG)

hwi = HWIBridge()
# bla = hwi.detect_device()

res = hwi.enumerate(passphrase="")[0]

# seems to be normal
assert res["type"] == "jade"
assert res["model"] == "jade"
assert res["path"] == "/dev/ttyUSB0"
k9ert marked this conversation as resolved.
Show resolved Hide resolved
assert res["error"].startswith(
"Could not open client or get fingerprint information: __init__() got an unexpected keyword argument 'timeout'"
)
assert res["code"] == -13
assert res["fingerprint"] == "4c6de3ce"

results = hwi.extract_xpubs(
chain="main", device_type="jade", path="/dev/ttyUSB0"
).split("\n")
assert len(results) == 9
assert results[0].startswith("[")
assert results == None