mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 11:09:01 +00:00
Tests reworked to new TrezorClient API, all tests passes.
This commit is contained in:
parent
5128fa8442
commit
21b3b0ab91
@ -1,23 +1,22 @@
|
||||
import unittest
|
||||
import config
|
||||
|
||||
from trezorlib.client import TrezorClient
|
||||
from trezorlib.debuglink import DebugLink
|
||||
from trezorlib.client import TrezorDebugClient
|
||||
from trezorlib.api_blockchain import BlockchainApi
|
||||
|
||||
class TrezorTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.debug_transport = config.DEBUG_TRANSPORT(*config.DEBUG_TRANSPORT_ARGS, **config.DEBUG_TRANSPORT_KWARGS)
|
||||
self.transport = config.TRANSPORT(*config.TRANSPORT_ARGS, **config.TRANSPORT_KWARGS)
|
||||
self.client = TrezorClient(self.transport, DebugLink(self.debug_transport), debug=True)
|
||||
# self.client = TrezorClient(self.transport, debug=False)
|
||||
self.client = TrezorDebugClient(self.transport)
|
||||
self.client.set_debuglink(self.debug_transport)
|
||||
self.client.set_tx_func(BlockchainApi().get_tx)
|
||||
|
||||
self.mnemonic1 = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle'
|
||||
self.mnemonic2 = 'owner little vague addict embark decide pink prosper true fork panda embody mixture exchange choose canoe electric jewel'
|
||||
self.pin1 = '1234'
|
||||
self.pin2 = '43211'
|
||||
|
||||
self.client.setup_debuglink(button=True, pin_correct=True)
|
||||
|
||||
self.client.wipe_device()
|
||||
self.client.load_device_by_mnemonic(
|
||||
mnemonic=self.mnemonic1,
|
||||
|
@ -24,7 +24,7 @@ TODO:
|
||||
* VerifyMessage workflow
|
||||
|
||||
* otestovat session handling (tento test bude zrejme failovat na RPi)
|
||||
|
||||
* Failure_NotInitialized
|
||||
* Features reflects all variations of LoadDevice
|
||||
* Maxfee settings
|
||||
* Client requires OTP
|
||||
|
@ -10,15 +10,15 @@ from trezorlib.client import PinException
|
||||
class TestDebugLink(common.TrezorTest):
|
||||
|
||||
def test_layout(self):
|
||||
layout = self.client.debuglink.read_layout()
|
||||
layout = self.client.debug.read_layout()
|
||||
self.assertEqual(len(layout), 1024)
|
||||
|
||||
def test_mnemonic(self):
|
||||
mnemonic = self.client.debuglink.read_mnemonic()
|
||||
mnemonic = self.client.debug.read_mnemonic()
|
||||
self.assertEqual(mnemonic, self.mnemonic1)
|
||||
|
||||
def test_node(self):
|
||||
node = self.client.debuglink.read_node()
|
||||
node = self.client.debug.read_node()
|
||||
self.assertIsNotNone(node)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -9,20 +9,14 @@ from trezorlib.client import PinException
|
||||
# FIXME TODO Add passphrase tests
|
||||
|
||||
class TestProtectCall(common.TrezorTest):
|
||||
def _some_protected_call(self, expected_buttonrequests):
|
||||
def _some_protected_call(self, button, pin, passphrase):
|
||||
# This method perform any call which have protection in the device
|
||||
|
||||
res = self.client.ping('random data', pin_protection=True, passphrase_protection=True)
|
||||
res = self.client.ping('random data',
|
||||
button_protection=button,
|
||||
pin_protection=pin,
|
||||
passphrase_protection=passphrase)
|
||||
self.assertEqual(res, 'random data')
|
||||
|
||||
msg = proto.Ping(message='random data',
|
||||
button_protection=True,
|
||||
pin_protection=True,
|
||||
passphrase_protection=True)
|
||||
|
||||
return self.client.call(msg, expected=proto.Success,
|
||||
expected_buttonrequests=expected_buttonrequests).message
|
||||
|
||||
def test_no_protection(self):
|
||||
self.client.wipe_device()
|
||||
self.client.load_device_by_mnemonic(
|
||||
@ -33,28 +27,30 @@ class TestProtectCall(common.TrezorTest):
|
||||
language='english',
|
||||
)
|
||||
|
||||
self.assertEqual(self.client.debuglink.read_pin()[0], '')
|
||||
self._some_protected_call([])
|
||||
self.assertEqual(self.client.debug.read_pin()[0], '')
|
||||
self.client.set_expected_buttonrequests([])
|
||||
self._some_protected_call(False, True, True)
|
||||
|
||||
'''
|
||||
def test_pin(self):
|
||||
self.client.wipe_device()
|
||||
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
|
||||
pin=self.pin2,
|
||||
passphrase_protection=False,
|
||||
passphrase_protection=True,
|
||||
label='test',
|
||||
language='english')
|
||||
|
||||
self.assertEqual(self.client.debuglink.read_pin()[0], self.pin2)
|
||||
self._some_protected_call()
|
||||
|
||||
self.assertEqual(self.client.debug.read_pin()[0], self.pin2)
|
||||
self.client.setup_debuglink(button=True, pin_correct=True)
|
||||
self.client.set_expected_buttonrequests([types.ButtonRequest_Other])
|
||||
self._some_protected_call(True, True, False)
|
||||
|
||||
def test_incorrect_pin(self):
|
||||
self.client.setup_debuglink(button=True, pin_correct=False)
|
||||
self.assertRaises(PinException, self._some_protected_call)
|
||||
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
||||
|
||||
def test_cancelled_pin(self):
|
||||
self.client.setup_debuglink(button=True, pin_correct=-1) # PIN cancel
|
||||
self.assertRaises(PinException, self._some_protected_call)
|
||||
self.client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
|
||||
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
||||
|
||||
def test_exponential_backoff_with_reboot(self):
|
||||
self.client.setup_debuglink(button=True, pin_correct=False)
|
||||
@ -69,9 +65,9 @@ class TestProtectCall(common.TrezorTest):
|
||||
|
||||
for attempt in range(1, 4):
|
||||
start = time.time()
|
||||
self.assertRaises(PinException, self._some_protected_call)
|
||||
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
||||
test_backoff(attempt, start)
|
||||
'''
|
||||
|
||||
'''
|
||||
# Unplug Trezor now
|
||||
self.client.debuglink.stop()
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user