1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00

don't call load_device in tests setup

This commit is contained in:
Pavol Rusnak 2014-02-17 01:54:54 +01:00
parent 8e6e3bb7be
commit 74f3502637
10 changed files with 69 additions and 100 deletions

View File

@ -12,24 +12,24 @@ class TrezorTest(unittest.TestCase):
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.mnemonic12 = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle'
self.mnemonic18 = 'owner little vague addict embark decide pink prosper true fork panda embody mixture exchange choose canoe electric jewel'
self.mnemonic24 = 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic'
self.pin4 = '1234'
self.pin6 = '789456'
self.pin8 = '45678978'
self.client.wipe_device()
self.client.load_device_by_mnemonic(
mnemonic=self.mnemonic1,
pin=self.pin1,
passphrase_protection=False,
label='test',
language='english',
)
# self.client.apply_settings(label='unit testing', coin_shortcut='BTC', language='english')
print "Setup finished"
print "--------------"
def setup_mnemonic_nopin_nopassphrase(self):
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin='', passphrase_protection=False, label='test', language='english')
def setup_mnemonic_pin_passphrase(self):
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin=self.pin4, passphrase_protection=True, label='test', language='english')
def tearDown(self):
self.client.close()

View File

@ -4,14 +4,9 @@ import trezorlib.ckd_public as bip32
from trezorlib import tools
class TestAddresses(common.TrezorTest):
def test_btc(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
def test_btc(self):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Bitcoin', []), '1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK')
self.assertEqual(self.client.get_address('Bitcoin', [1]), '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
self.assertEqual(self.client.get_address('Bitcoin', [0, -1]), '1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs')
@ -19,13 +14,7 @@ class TestAddresses(common.TrezorTest):
self.assertEqual(self.client.get_address('Bitcoin', [0, 9999999]), '1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV')
def test_ltc(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Litecoin', []), 'LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK')
self.assertEqual(self.client.get_address('Litecoin', [1]), 'LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE')
self.assertEqual(self.client.get_address('Litecoin', [0, -1]), 'LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6')
@ -33,22 +22,11 @@ class TestAddresses(common.TrezorTest):
self.assertEqual(self.client.get_address('Litecoin', [0, 9999999]), 'Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S')
def test_tbtc(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Testnet', [111, 42]), 'moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa')
def test_public_ckd(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
self.setup_mnemonic_nopin_nopassphrase()
node = self.client.get_public_node([])
node_sub1 = self.client.get_public_node([1])
@ -64,4 +42,4 @@ class TestAddresses(common.TrezorTest):
self.assertEqual(address1, address2)
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@ -4,16 +4,13 @@ import common
from trezorlib import messages_pb2 as messages
class TestBasic(common.TrezorTest):
def test_features(self):
features = self.client.call(messages.Initialize())
# Result is the same as reported by BitkeyClient class
self.assertEqual(features, self.client.features)
def test_ping(self):
ping = self.client.call(messages.Ping(message='ahoj!'))
# Ping results in Success(message='Ahoj!')
self.assertEqual(ping, messages.Success(message='ahoj!'))
def test_device_id_same(self):

View File

@ -5,12 +5,7 @@ from trezorlib import tools
class TestAddresses(common.TrezorTest):
def test_public_ckd(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
self.setup_mnemonic_nopin_nopassphrase()
self.client.get_address('Bitcoin', []) # to compute root node via BIP39
@ -23,12 +18,7 @@ class TestAddresses(common.TrezorTest):
self.assertLessEqual(delay, expected)
def test_private_ckd(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
self.setup_mnemonic_nopin_nopassphrase()
self.client.get_address('Bitcoin', []) # to compute root node via BIP39

View File

@ -14,10 +14,12 @@ class TestDebugLink(common.TrezorTest):
self.assertEqual(len(layout), 1024)
def test_mnemonic(self):
self.setup_mnemonic_nopin_nopassphrase()
mnemonic = self.client.debug.read_mnemonic()
self.assertEqual(mnemonic, self.mnemonic1)
self.assertEqual(mnemonic, self.mnemonic12)
def test_node(self):
self.setup_mnemonic_nopin_nopassphrase()
node = self.client.debug.read_node()
self.assertIsNotNone(node)

View File

@ -8,14 +8,17 @@ from trezorlib.client import CallException
class TestMessages(common.TrezorTest):
def test_message_sign(self):
self.setup_mnemonic_nopin_nopassphrase()
sig = self.client.sign_message([0], "This is an example of a signed message.")
self.assertEqual(sig.address, '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e')
self.assertEqual(binascii.hexlify(sig.signature), '209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80')
def test_too_long(self):
self.setup_mnemonic_nopin_nopassphrase()
# Message cannot be longer than 255 bytes
self.assertRaises(CallException, self.client.sign_message, [0], '1' * 256)
ret = self.client.verify_message('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'),
'1' * 256
@ -27,10 +30,8 @@ class TestMessages(common.TrezorTest):
ret = self.client.verify_message('moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk', sig, 'Ahoj')
self.assertTrue(ret)
def test_message_verify(self):
def test_message_verify(self):
# uncompressed pubkey - OK
res = self.client.verify_message(
'1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
@ -80,4 +81,3 @@ class TestMessages(common.TrezorTest):
if __name__ == '__main__':
unittest.main()

View File

@ -8,14 +8,7 @@ from trezorlib import types_pb2 as proto_types
class TestPing(common.TrezorTest):
def test_ping(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(
mnemonic=self.mnemonic1,
pin=self.pin1,
passphrase_protection=True,
label='test',
language='english',
)
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.Success()])
res = self.client.ping('random data')
@ -34,14 +27,7 @@ class TestPing(common.TrezorTest):
self.assertEqual(res, 'random data')
def test_ping_caching(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(
mnemonic=self.mnemonic1,
pin=self.pin1,
passphrase_protection=True,
label='test',
language='english',
)
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other),proto.PinMatrixRequest(),proto.PassphraseRequest(),proto.Success()])
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)

View File

@ -18,6 +18,8 @@ class TestProtectCall(common.TrezorTest):
self.assertEqual(res, 'random data')
def test_expected_responses(self):
self.setup_mnemonic_pin_passphrase()
# This is low-level test of set_expected_responses()
# feature of debugging client
@ -49,28 +51,16 @@ class TestProtectCall(common.TrezorTest):
self.assertRaises(CallException, self._some_protected_call, True, True, True)
def test_no_protection(self):
self.client.wipe_device()
self.client.load_device_by_mnemonic(
mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english',
)
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.debug.read_pin()[0], '')
self.client.set_expected_responses([proto.Success()])
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=True,
label='test',
language='english')
self.setup_mnemonic_pin_passphrase()
self.assertEqual(self.client.debug.read_pin()[0], self.pin2)
self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
self.client.setup_debuglink(button=True, pin_correct=True)
self.client.set_expected_responses([proto.ButtonRequest(),
proto.PinMatrixRequest(),
@ -78,16 +68,20 @@ class TestProtectCall(common.TrezorTest):
self._some_protected_call(True, True, False)
def test_incorrect_pin(self):
self.setup_mnemonic_pin_passphrase()
self.client.setup_debuglink(button=True, pin_correct=False)
self.assertRaises(PinException, self._some_protected_call, False, True, False)
def test_cancelled_pin(self):
self.setup_mnemonic_pin_passphrase()
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.setup_mnemonic_pin_passphrase()
self.client.setup_debuglink(button=True, pin_correct=False)
def test_backoff(attempts, start):
expected = 1.8 ** attempts
got = time.time() - start

View File

@ -39,6 +39,8 @@ class FakeTestnetBlockchain(object):
class TestSignTx(common.TrezorTest):
def test_one_one_fee(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
@ -62,6 +64,8 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
def test_testnet_one_two_fee(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
# input 1: 10.00000000 BTC
inp1 = proto_types.TxInputType(address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
@ -90,6 +94,8 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006b4830450221009c2d30385519fdb13dce13d5ac038be07d7b2dad0b0f7b2c1c339d7255bcf553022056a2f5bceab3cd0ffed4d388387e631f419d67ff9ce7798e3d7dfe6a6d6ec4bd0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0280ce341d000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')
def test_testnet_fee_too_high(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
# input 1: 10.00000000 BTC
inp1 = proto_types.TxInputType(address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
@ -119,6 +125,8 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006b483045022100d74e9fa5c7ff5966d52bce8d1d772c1e3ef1376395fb85a0bbf910e723bd606d02204cb8df6debd7c4c076632011bb1e180495bcf3630d2471c354bed56c2e45a2180121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0200389c1c000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')
def test_one_two_fee(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
@ -147,6 +155,8 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100c1400d8485d3bdcae7413e123148f35ece84806fc387ab88c66b469df89aef1702201d481d04216b319dc549ffe2333143629ba18828a4e2d1783ab719a6aa263eb70121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff02e0930400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000')
def test_one_three_fee(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
@ -181,11 +191,13 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100e695e2c530c7c0fc32e6b79b7cff56a7f70a8c9da787534f46b4204070f914fc02207b0879a81408a11e23b11d4c7965c62b5fc6d5c2d92340f5ee2da7b40e99314a0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0300650400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ace02e0000000000001976a9141fe1d337fb81afca42818051e12fd18245d1b17288ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000')
def test_two_two(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c
# input 1: 0.0010 BTC
# tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e
# input 1: 0.0011 BTC
inp1 = proto_types.TxInputType(address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
# amount=100000,
prev_hash=binascii.unhexlify('c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c'),
@ -219,6 +231,8 @@ class TestSignTx(common.TrezorTest):
'''
def test_255_outputs(self):
self.setup_mnemonic_nopin_nopassphrase()
# Tests if device implements serialization of len(outputs) correctly
# tx: c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
@ -255,6 +269,8 @@ class TestSignTx(common.TrezorTest):
'''
def test_fee_too_high(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
@ -278,6 +294,8 @@ class TestSignTx(common.TrezorTest):
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006a4730440220361b8268718533055682f4532d30c553ce778f70b217457a9aa1956e457c5aac0220538ae285bb340484bb09a67635d29192a14e61d8a8385b8b090a92e3e97e1c010121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0120300500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
def test_not_enough_funds(self):
self.setup_mnemonic_nopin_nopassphrase()
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC

View File

@ -31,7 +31,7 @@ class TestZeroSig(common.TrezorTest):
msg.outputs.extend([out1, ])
tx = self.client.call(msg)
siglen = ord(tx.serialized_tx[44])
print siglen
if siglen < 67:
@ -41,6 +41,8 @@ class TestZeroSig(common.TrezorTest):
'''
def test_one_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
@ -61,6 +63,8 @@ class TestZeroSig(common.TrezorTest):
self.assertEqual(siglen, 67)
def test_two_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
@ -79,6 +83,6 @@ class TestZeroSig(common.TrezorTest):
# Trezor must strip leading zero from signature
self.assertEqual(siglen, 66)
if __name__ == '__main__':
unittest.main()