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