mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-04 11:51:50 +00:00
Implements 'with' + set_expected_responses
This commit is contained in:
parent
eae7d98b8a
commit
640d290129
@ -21,6 +21,8 @@ x SimpleSignTx
|
|||||||
FirmwareErase
|
FirmwareErase
|
||||||
FirmwareUpload
|
FirmwareUpload
|
||||||
|
|
||||||
|
protection levels
|
||||||
|
|
||||||
- zrejme v sucinnosti s inymi testami
|
- zrejme v sucinnosti s inymi testami
|
||||||
x ButtonRequest/ButtonAck workflow
|
x ButtonRequest/ButtonAck workflow
|
||||||
x PinMatrixRequest/PinMatrixAck workflow
|
x PinMatrixRequest/PinMatrixAck workflow
|
||||||
|
@ -3,7 +3,7 @@ import common
|
|||||||
import time
|
import time
|
||||||
from trezorlib import tools
|
from trezorlib import tools
|
||||||
|
|
||||||
class TestAddresses(common.TrezorTest):
|
class TestBip32Speed(common.TrezorTest):
|
||||||
def test_public_ckd(self):
|
def test_public_ckd(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ class TestAddresses(common.TrezorTest):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
self.client.get_address('Bitcoin', range(depth))
|
self.client.get_address('Bitcoin', range(depth))
|
||||||
delay = time.time() - start
|
delay = time.time() - start
|
||||||
expected = (depth + 1) * 0.25
|
expected = (depth + 1) * 0.26
|
||||||
print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay
|
print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay
|
||||||
self.assertLessEqual(delay, expected)
|
self.assertLessEqual(delay, expected)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ class TestAddresses(common.TrezorTest):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
self.client.get_address('Bitcoin', range(-depth, 0))
|
self.client.get_address('Bitcoin', range(-depth, 0))
|
||||||
delay = time.time() - start
|
delay = time.time() - start
|
||||||
expected = (depth + 1) * 0.25
|
expected = (depth + 1) * 0.26
|
||||||
print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay
|
print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay
|
||||||
self.assertLessEqual(delay, expected)
|
self.assertLessEqual(delay, expected)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import common
|
|||||||
import trezorlib.ckd_public as bip32
|
import trezorlib.ckd_public as bip32
|
||||||
from trezorlib import tools
|
from trezorlib import tools
|
||||||
|
|
||||||
class TestAddresses(common.TrezorTest):
|
class TestMsgGetaddress(common.TrezorTest):
|
||||||
|
|
||||||
def test_btc(self):
|
def test_btc(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
|
@ -18,14 +18,15 @@ def entropy(data):
|
|||||||
e -= p * math.log(p, 256)
|
e -= p * math.log(p, 256)
|
||||||
return e
|
return e
|
||||||
|
|
||||||
class TestEntropy(common.TrezorTest):
|
class TestMsgGetentropy(common.TrezorTest):
|
||||||
|
|
||||||
def test_entropy(self):
|
def test_entropy(self):
|
||||||
for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]:
|
for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]:
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Entropy()])
|
with self.client:
|
||||||
ent = self.client.get_entropy(l)
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Entropy()])
|
||||||
self.assertTrue(len(ent) >= l)
|
ent = self.client.get_entropy(l)
|
||||||
print 'entropy = ', entropy(ent)
|
self.assertTrue(len(ent) >= l)
|
||||||
|
print 'entropy = ', entropy(ent)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -10,33 +10,39 @@ class TestPing(common.TrezorTest):
|
|||||||
def test_ping(self):
|
def test_ping(self):
|
||||||
self.setup_mnemonic_pin_passphrase()
|
self.setup_mnemonic_pin_passphrase()
|
||||||
|
|
||||||
self.client.set_expected_responses([proto.Success()])
|
with self.client:
|
||||||
res = self.client.ping('random data')
|
self.client.set_expected_responses([proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data')
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other),proto.Success()])
|
with self.client:
|
||||||
res = self.client.ping('random data', button_protection=True)
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data', button_protection=True)
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
self.client.set_expected_responses([proto.PinMatrixRequest(),proto.Success()])
|
with self.client:
|
||||||
res = self.client.ping('random data', pin_protection=True)
|
self.client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data', pin_protection=True)
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
self.client.set_expected_responses([proto.PassphraseRequest(),proto.Success()])
|
with self.client:
|
||||||
res = self.client.ping('random data', passphrase_protection=True)
|
self.client.set_expected_responses([proto.PassphraseRequest(), proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data', passphrase_protection=True)
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
def test_ping_caching(self):
|
def test_ping_caching(self):
|
||||||
self.setup_mnemonic_pin_passphrase()
|
self.setup_mnemonic_pin_passphrase()
|
||||||
|
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other),proto.PinMatrixRequest(),proto.PassphraseRequest(),proto.Success()])
|
with self.client:
|
||||||
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
# pin and passphrase are cached
|
with self.client:
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other),proto.Success()])
|
# pin and passphrase are cached
|
||||||
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Success()])
|
||||||
self.assertEqual(res, 'random data')
|
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
|
||||||
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
File diff suppressed because one or more lines are too long
@ -23,49 +23,59 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
# This is low-level test of set_expected_responses()
|
# This is low-level test of set_expected_responses()
|
||||||
# feature of debugging client
|
# feature of debugging client
|
||||||
|
|
||||||
# Scenario 1 - Received unexpected message
|
with self.client:
|
||||||
self.client.set_expected_responses([])
|
# Scenario 1 - Received unexpected message
|
||||||
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
self.client.set_expected_responses([])
|
||||||
|
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
||||||
|
|
||||||
# Scenario 2 - Received other than expected message
|
with self.client:
|
||||||
self.client.set_expected_responses([proto.Success()])
|
# Scenario 2 - Received other than expected message
|
||||||
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
self.client.set_expected_responses([proto.Success()])
|
||||||
|
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
||||||
|
|
||||||
# Scenario 3 - Not received expected message
|
def scenario3():
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(),
|
with self.client:
|
||||||
proto.Success(),
|
# Scenario 3 - Not received expected message
|
||||||
proto.Success()]) # This is expected, but not received
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
self.assertRaises(Exception, self._some_protected_call, True, False, False)
|
proto.Success(),
|
||||||
|
proto.Success()]) # This is expected, but not received
|
||||||
|
self._some_protected_call(True, False, False)
|
||||||
|
self.assertRaises(Exception, scenario3)
|
||||||
|
|
||||||
# Scenario 4 - Received what expected
|
with self.client:
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(),
|
# Scenario 4 - Received what expected
|
||||||
proto.PinMatrixRequest(),
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
proto.PassphraseRequest(),
|
proto.PinMatrixRequest(),
|
||||||
proto.Success(message='random data')])
|
proto.PassphraseRequest(),
|
||||||
self._some_protected_call(True, True, True)
|
proto.Success(message='random data')])
|
||||||
|
self._some_protected_call(True, True, True)
|
||||||
|
|
||||||
# Scenario 5 - Failed message by field filter
|
def scenario5():
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(),
|
with self.client:
|
||||||
proto.PinMatrixRequest(),
|
# Scenario 5 - Failed message by field filter
|
||||||
proto.Success(message='wrong data')])
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
proto.Success(message='wrong data')])
|
||||||
|
self._some_protected_call(True, True, True)
|
||||||
|
self.assertRaises(CallException, scenario5)
|
||||||
|
|
||||||
def test_no_protection(self):
|
def test_no_protection(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
|
|
||||||
self.assertEqual(self.client.debug.read_pin()[0], '')
|
with self.client:
|
||||||
self.client.set_expected_responses([proto.Success()])
|
self.assertEqual(self.client.debug.read_pin()[0], '')
|
||||||
self._some_protected_call(False, True, True)
|
self.client.set_expected_responses([proto.Success()])
|
||||||
|
self._some_protected_call(False, True, True)
|
||||||
|
|
||||||
def test_pin(self):
|
def test_pin(self):
|
||||||
self.setup_mnemonic_pin_passphrase()
|
self.setup_mnemonic_pin_passphrase()
|
||||||
|
|
||||||
self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
|
with self.client:
|
||||||
self.client.setup_debuglink(button=True, pin_correct=True)
|
self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
|
||||||
self.client.set_expected_responses([proto.ButtonRequest(),
|
self.client.setup_debuglink(button=True, pin_correct=True)
|
||||||
proto.PinMatrixRequest(),
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
proto.Success()])
|
proto.PinMatrixRequest(),
|
||||||
self._some_protected_call(True, True, False)
|
proto.Success()])
|
||||||
|
self._some_protected_call(True, True, False)
|
||||||
|
|
||||||
def test_incorrect_pin(self):
|
def test_incorrect_pin(self):
|
||||||
self.setup_mnemonic_pin_passphrase()
|
self.setup_mnemonic_pin_passphrase()
|
||||||
@ -94,6 +104,7 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user