From 965bf84cdbb777b451ec9cc2be962bfc4288aa1f Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 16 Dec 2017 02:11:26 +0100 Subject: [PATCH] tests: cleanup flake8 warnings --- Makefile | 6 ++-- src/apps/common/storage.py | 2 +- tests/common.py | 2 +- tests/test_apps.common.coins.py | 1 + ...apps.wallet.segwit.bip143.native_p2wpkh.py | 1 - ...pps.wallet.segwit.bip143.p2wpkh_in_p2sh.py | 1 - ...pps.wallet.segwit.signtx.p2wpkh_in_p2sh.py | 12 +++---- tests/test_apps.wallet.signtx.py | 1 + tests/test_trezor.config.py | 1 + tests/test_trezor.crypto.aes.py | 2 ++ tests/test_trezor.crypto.base58.py | 6 +++- tests/test_trezor.crypto.bech32.py | 5 ++- tests/test_trezor.crypto.bip32.py | 2 ++ tests/test_trezor.crypto.bip39.py | 2 ++ tests/test_trezor.crypto.curve.curve25519.py | 2 ++ tests/test_trezor.crypto.curve.ed25519.py | 5 ++- .../test_trezor.crypto.curve.ed25519_cosi.py | 2 ++ tests/test_trezor.crypto.curve.nist256p1.py | 13 +++---- tests/test_trezor.crypto.curve.secp256k1.py | 13 +++---- tests/test_trezor.crypto.der.py | 12 ++++--- tests/test_trezor.crypto.hashlib.blake2b.py | 3 +- tests/test_trezor.crypto.hashlib.blake2s.py | 2 ++ tests/test_trezor.crypto.hashlib.ripemd160.py | 2 ++ tests/test_trezor.crypto.hashlib.sha1.py | 3 +- tests/test_trezor.crypto.hashlib.sha256.py | 2 ++ tests/test_trezor.crypto.hashlib.sha3_256.py | 4 ++- tests/test_trezor.crypto.hashlib.sha3_512.py | 4 ++- tests/test_trezor.crypto.hashlib.sha512.py | 2 ++ tests/test_trezor.crypto.hmac.py | 6 ++-- tests/test_trezor.crypto.pbkdf2.py | 4 +++ tests/test_trezor.crypto.random.py | 2 ++ tests/test_trezor.crypto.rfc6979.py | 2 ++ tests/test_trezor.crypto.rlp.py | 8 +++-- tests/test_trezor.io.py | 20 +++++------ tests/test_trezor.ui.display.py | 2 ++ tests/test_trezor.utils.py | 2 ++ tests/test_trezor.wire.codec_v1.py | 36 +++++++++---------- tests/test_trezor.wire.codec_v2.py | 36 +++++++++---------- 38 files changed, 144 insertions(+), 87 deletions(-) diff --git a/Makefile b/Makefile index 912f9ed2a..fa45c00c9 100644 --- a/Makefile +++ b/Makefile @@ -71,11 +71,13 @@ test: ## run unit tests test_emu: ## run selected device tests from python-trezor cd tests ; ./run_tests_device_emu.sh -pylint: ## run pylint on application sources +pylint: ## run pylint on application sources and tests pylint -E $(shell find src -name *.py) + pylint -E $(shell find tests -name *.py) -style: ## run code style check on application sources +style: ## run code style check on application sources and tests flake8 $(shell find src -name *.py) + flake8 $(shell find tests -name *.py) ## build commands: diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index 2dafb4327..49fc7762d 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -70,4 +70,4 @@ def wipe(): def new_device_id() -> str: from ubinascii import hexlify from trezor.crypto import random - return hexlify(random.bytes(12)).decode('ascii').upper() + return hexlify(random.bytes(12)).decode().upper() diff --git a/tests/common.py b/tests/common.py index de4e146ad..a2f084a16 100644 --- a/tests/common.py +++ b/tests/common.py @@ -3,4 +3,4 @@ sys.path.append('../src') from ubinascii import hexlify, unhexlify -import unittest \ No newline at end of file +import unittest diff --git a/tests/test_apps.common.coins.py b/tests/test_apps.common.coins.py index fa2cf7a8b..98f4df9c6 100644 --- a/tests/test_apps.common.coins.py +++ b/tests/test_apps.common.coins.py @@ -2,6 +2,7 @@ from common import * from apps.common import coins + class TestCoins(unittest.TestCase): def test_coins(self): diff --git a/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py b/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py index 1a390f4cf..a44de48fb 100644 --- a/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py +++ b/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py @@ -91,6 +91,5 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): self.assertEqual(hexlify(result), b'c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670') - if __name__ == '__main__': unittest.main() diff --git a/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py b/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py index 22f2413c1..5b9016764 100644 --- a/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py +++ b/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py @@ -78,6 +78,5 @@ class TestSegwitBip143(unittest.TestCase): self.assertEqual(hexlify(result), b'64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6') - if __name__ == '__main__': unittest.main() diff --git a/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh.py b/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh.py index f61bd39db..855ad4680 100644 --- a/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh.py +++ b/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh.py @@ -176,7 +176,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): # returned serialized inp1 serialized_tx=unhexlify( '0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff'), - )), + )), # the out has to be cloned not to send the same object which was modified TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), @@ -187,7 +187,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): '02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac'), signature_index=None, signature=None, - )), + )), TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), # segwit @@ -198,7 +198,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): '3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), signature_index=None, signature=None, - )), + )), TxAck(tx=TransactionType(inputs=[inp1])), TxRequest(request_type=TXFINISHED, details=None, serialized=TxRequestSerializedType( @@ -288,7 +288,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): # returned serialized inpattack serialized_tx=unhexlify( '0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff'), - )), + )), # the out has to be cloned not to send the same object which was modified TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), @@ -299,7 +299,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): '0208000000000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac'), signature_index=None, signature=None, - )), + )), TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), # segwit @@ -310,7 +310,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): '010000000000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), signature_index=None, signature=None, - )), + )), TxAck(tx=TransactionType(inputs=[inp1])), TxRequest(request_type=TXFINISHED, details=None) diff --git a/tests/test_apps.wallet.signtx.py b/tests/test_apps.wallet.signtx.py index e79201833..15dd326b1 100644 --- a/tests/test_apps.wallet.signtx.py +++ b/tests/test_apps.wallet.signtx.py @@ -17,6 +17,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.wallet.sign_tx import signing + class TestSignTx(unittest.TestCase): # pylint: disable=C0301 diff --git a/tests/test_trezor.config.py b/tests/test_trezor.config.py index 84acbd8e6..cb9137e88 100644 --- a/tests/test_trezor.config.py +++ b/tests/test_trezor.config.py @@ -105,5 +105,6 @@ class TestConfig(unittest.TestCase): value = config.get(appid, key) self.assertEqual(value, bytes()) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.aes.py b/tests/test_trezor.crypto.aes.py index c220a36c4..dc0cfe3b2 100644 --- a/tests/test_trezor.crypto.aes.py +++ b/tests/test_trezor.crypto.aes.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto.aes import * + class TestCryptoAes(unittest.TestCase): # vectors from https://github.com/ricmoo/pyaes @@ -53,5 +54,6 @@ class TestCryptoAes(unittest.TestCase): d = a.update(e) self.assertEqual(d, plain) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.base58.py b/tests/test_trezor.crypto.base58.py index e1538459a..bc4f7d672 100644 --- a/tests/test_trezor.crypto.base58.py +++ b/tests/test_trezor.crypto.base58.py @@ -4,7 +4,10 @@ from trezor.crypto.hashlib import ripemd160 from trezor.crypto import base58 -digestfunc_graphene = lambda x: ripemd160(x).digest()[:4] + +def digestfunc_graphene(x): + return ripemd160(x).digest()[:4] + class TestCryptoBase58(unittest.TestCase): @@ -81,5 +84,6 @@ class TestCryptoBase58(unittest.TestCase): for a, b in self.vectors_graphene: self.assertEqual(base58.encode_check(unhexlify(a), digestfunc=digestfunc_graphene), b) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.bech32.py b/tests/test_trezor.crypto.bech32.py index 946de0fe3..531d34534 100644 --- a/tests/test_trezor.crypto.bech32.py +++ b/tests/test_trezor.crypto.bech32.py @@ -24,10 +24,12 @@ from common import * from trezor.crypto import bech32 + def segwit_scriptpubkey(witver, witprog): """Construct a Segwit scriptPubKey for a given witness program.""" return bytes([witver + 0x50 if witver else 0, len(witprog)] + witprog) + VALID_CHECKSUM = [ "A12UEL5L", "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs", @@ -91,7 +93,7 @@ class TestCryptoBech32(unittest.TestCase): hrp, _ = bech32.bech32_decode(test) self.assertIsNotNone(hrp) pos = test.rfind('1') - test = test[:pos+1] + chr(ord(test[pos + 1]) ^ 1) + test[pos+2:] + test = test[:pos + 1] + chr(ord(test[pos + 1]) ^ 1) + test[pos + 2:] hrp, _ = bech32.bech32_decode(test) self.assertIsNone(hrp) @@ -129,5 +131,6 @@ class TestCryptoBech32(unittest.TestCase): code = bech32.encode(hrp, version, [0] * length) self.assertIsNone(code) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_trezor.crypto.bip32.py b/tests/test_trezor.crypto.bip32.py index 2c0bb64c7..d7d883b75 100644 --- a/tests/test_trezor.crypto.bip32.py +++ b/tests/test_trezor.crypto.bip32.py @@ -7,6 +7,7 @@ HARDENED = 0x80000000 VERSION_PUBLIC = 0x0488b21e VERSION_PRIVATE = 0x0488ade4 + class TestCryptoBip32(unittest.TestCase): def test_from_seed_invalid(self): @@ -473,5 +474,6 @@ class TestCryptoBip32(unittest.TestCase): ns2 = n2.serialize_public(VERSION_PUBLIC) self.assertEqual(ns2, ns) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.bip39.py b/tests/test_trezor.crypto.bip39.py index b1ce08a15..f36cfa9b4 100644 --- a/tests/test_trezor.crypto.bip39.py +++ b/tests/test_trezor.crypto.bip39.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import bip39 + class TestCryptoBip39(unittest.TestCase): def test_mnemonic(self): @@ -119,5 +120,6 @@ class TestCryptoBip39(unittest.TestCase): for m in v: self.assertEqual(bip39.check(m), False) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.curve.curve25519.py b/tests/test_trezor.crypto.curve.curve25519.py index 0fd4dab6f..b6c6f5499 100644 --- a/tests/test_trezor.crypto.curve.curve25519.py +++ b/tests/test_trezor.crypto.curve.curve25519.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto.curve import curve25519 + class TestCryptoCurve25519(unittest.TestCase): vectors = [ @@ -29,5 +30,6 @@ class TestCryptoCurve25519(unittest.TestCase): session2 = curve25519.multiply(sk2, pk1) self.assertEqual(session1, session2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.curve.ed25519.py b/tests/test_trezor.crypto.curve.ed25519.py index 4d468fc5e..4183f241c 100644 --- a/tests/test_trezor.crypto.curve.ed25519.py +++ b/tests/test_trezor.crypto.curve.ed25519.py @@ -4,6 +4,7 @@ from trezor.crypto import random from trezor.crypto.curve import ed25519 + class TestCryptoEd25519(unittest.TestCase): # vectors from https://github.com/torproject/tor/blob/master/src/test/ed25519_vectors.inc @@ -15,7 +16,8 @@ class TestCryptoEd25519(unittest.TestCase): ('5c8eac469bb3f1b85bc7cd893f52dc42a9ab66f1b02b5ce6a68e9b175d3bb433', '66c1a77104d86461b6f98f73acf3cd229c80624495d2d74d6fda1e940080a96b', '2385a472f599ca965bbe4d610e391cdeabeba9c336694b0d6249e551458280be122c2441dd9746a81bbfb9cd619364bab0df37ff4ceb7aefd24469c39d3bc508'), ('eda433d483059b6d1ff8b7cfbd0fe406bfb23722c8f3c8252629284573b61b86', 'd21c294db0e64cb2d8976625786ede1d9754186ae8197a64d72f68c792eecc19', 'e500cd0b8cfff35442f88008d894f3a2fa26ef7d3a0ca5714ae0d3e2d40caae58ba7cdf69dd126994dad6be536fcda846d89dd8138d1683cc144c8853dce7607'), ('4377c40431c30883c5fbd9bc92ae48d1ed8a47b81d13806beac5351739b5533d', 'c4d58b4cf85a348ff3d410dd936fa460c4f18da962c01b1963792b9dcc8a6ea6', 'd187b9e334b0050154de10bf69b3e4208a584e1a65015ec28b14bcc252cf84b8baa9c94867daa60f2a82d09ba9652d41e8dde292b624afc8d2c26441b95e3c0e'), - ('c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b', '95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a', '815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d'), ] + ('c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b', '95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a', '815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d'), + ] def test_publickey(self): for sk, pk, _ in self.vectors: @@ -48,5 +50,6 @@ class TestCryptoEd25519(unittest.TestCase): sig = ed25519.sign(sk, msg) self.assertTrue(ed25519.verify(pk, sig, msg)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.curve.ed25519_cosi.py b/tests/test_trezor.crypto.curve.ed25519_cosi.py index a048a27af..7a398241e 100644 --- a/tests/test_trezor.crypto.curve.ed25519_cosi.py +++ b/tests/test_trezor.crypto.curve.ed25519_cosi.py @@ -3,6 +3,7 @@ from common import * from trezor.crypto import random from trezor.crypto.curve import ed25519 + class TestCryptoEd25519Cosi(unittest.TestCase): def test_cosi(self): @@ -41,5 +42,6 @@ class TestCryptoEd25519Cosi(unittest.TestCase): res = ed25519.verify(pubkey, sig, msg) self.assertTrue(res) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.curve.nist256p1.py b/tests/test_trezor.crypto.curve.nist256p1.py index a1e257902..d435bdd71 100644 --- a/tests/test_trezor.crypto.curve.nist256p1.py +++ b/tests/test_trezor.crypto.curve.nist256p1.py @@ -1,9 +1,9 @@ from common import * from trezor.crypto import random - from trezor.crypto.curve import nist256p1 + class TestCryptoNist256p1(unittest.TestCase): # vectors from http://point-at-infinity.org/ecc/nisttv @@ -75,9 +75,9 @@ class TestCryptoNist256p1(unittest.TestCase): if len(sk) < 64: sk = '0' * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify(nist256p1.publickey(unhexlify(sk), False)).decode('ascii') # uncompressed + pk65 = hexlify(nist256p1.publickey(unhexlify(sk), False)).decode() # uncompressed self.assertEqual(str(pk65), '04' + pk) - pk33 = hexlify(nist256p1.publickey(unhexlify(sk))).decode('ascii') + pk33 = hexlify(nist256p1.publickey(unhexlify(sk))).decode() if pk[-1] in '02468ace': self.assertEqual(pk33, '02' + pk[:64]) else: @@ -87,17 +87,17 @@ class TestCryptoNist256p1(unittest.TestCase): sk = nist256p1.generate_secret() pk = nist256p1.publickey(sk) - dig = bytes([1] + [0]*31) + dig = bytes([1] + [0] * 31) sig = nist256p1.sign(sk, dig) self.assertTrue(nist256p1.verify(pk, sig, dig)) self.assertTrue(nist256p1.verify(pk, sig[1:], dig)) - dig = bytes([0]*31 + [1]) + dig = bytes([0] * 31 + [1]) sig = nist256p1.sign(sk, dig) self.assertTrue(nist256p1.verify(pk, sig, dig)) self.assertTrue(nist256p1.verify(pk, sig[1:], dig)) - dig = bytes([0xFF]*32) + dig = bytes([0xFF] * 32) sig = nist256p1.sign(sk, dig) self.assertTrue(nist256p1.verify(pk, sig, dig)) self.assertTrue(nist256p1.verify(pk, sig[1:], dig)) @@ -121,5 +121,6 @@ class TestCryptoNist256p1(unittest.TestCase): pk2 = nist256p1.verify_recover(sig, dig) self.assertEqual(pk, pk2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.curve.secp256k1.py b/tests/test_trezor.crypto.curve.secp256k1.py index 63c672d04..bf0115e1d 100644 --- a/tests/test_trezor.crypto.curve.secp256k1.py +++ b/tests/test_trezor.crypto.curve.secp256k1.py @@ -1,9 +1,9 @@ from common import * from trezor.crypto import random - from trezor.crypto.curve import secp256k1 + class TestCryptoSecp256k1(unittest.TestCase): # vectors from https://crypto.stackexchange.com/questions/784/are-there-any-secp256k1-ecdsa-test-examples-available @@ -68,9 +68,9 @@ class TestCryptoSecp256k1(unittest.TestCase): if len(sk) < 64: sk = '0' * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify(secp256k1.publickey(unhexlify(sk), False)).decode('ascii') # uncompressed + pk65 = hexlify(secp256k1.publickey(unhexlify(sk), False)).decode() # uncompressed self.assertEqual(str(pk65), '04' + pk) - pk33 = hexlify(secp256k1.publickey(unhexlify(sk))).decode('ascii') + pk33 = hexlify(secp256k1.publickey(unhexlify(sk))).decode() if pk[-1] in '02468ace': self.assertEqual(pk33, '02' + pk[:64]) else: @@ -80,15 +80,15 @@ class TestCryptoSecp256k1(unittest.TestCase): sk = secp256k1.generate_secret() pk = secp256k1.publickey(sk) - dig = bytes([1] + [0]*31) + dig = bytes([1] + [0] * 31) sig = secp256k1.sign(sk, dig) self.assertTrue(secp256k1.verify(pk, sig, dig)) - dig = bytes([0]*31 + [1]) + dig = bytes([0] * 31 + [1]) sig = secp256k1.sign(sk, dig) self.assertTrue(secp256k1.verify(pk, sig, dig)) - dig = bytes([0xFF]*32) + dig = bytes([0xFF] * 32) sig = secp256k1.sign(sk, dig) self.assertTrue(secp256k1.verify(pk, sig, dig)) @@ -110,5 +110,6 @@ class TestCryptoSecp256k1(unittest.TestCase): pk2 = secp256k1.verify_recover(sig, dig) self.assertEqual(pk, pk2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.der.py b/tests/test_trezor.crypto.der.py index 5486c13f7..6adf42d06 100644 --- a/tests/test_trezor.crypto.der.py +++ b/tests/test_trezor.crypto.der.py @@ -2,12 +2,13 @@ from common import * from trezor.crypto import der + class TestCryptoDer(unittest.TestCase): vectors_seq = [ (('9a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b70771', '2b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781'), - '30450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781'), + '30450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781'), (('6666666666666666666666666666666666666666666666666666666666666666', '7777777777777777777777777777777777777777777777777777777777777777'), @@ -27,19 +28,19 @@ class TestCryptoDer(unittest.TestCase): (('0000000000000000000000000000000000000000000000000000000000000066', '0000000000000000000000000000000000000000000000000000000000000077'), - '3006020166020177'), + '3006020166020177'), (('0000000000000000000000000000000000000000000000000000000000000066', '00000000000000000000000000000000000000000000000000000000000000ee'), - '3007020166020200ee'), + '3007020166020200ee'), (('00000000000000000000000000000000000000000000000000000000000000ee', '0000000000000000000000000000000000000000000000000000000000000077'), - '3007020200ee020177'), + '3007020200ee020177'), (('00000000000000000000000000000000000000000000000000000000000000ee', '00000000000000000000000000000000000000000000000000000000000000ff'), - '3008020200ee020200ff'), + '3008020200ee020200ff'), ] def test_der_encode_seq(self): @@ -50,5 +51,6 @@ class TestCryptoDer(unittest.TestCase): d2 = der.encode_seq(s) self.assertEqual(d, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.blake2b.py b/tests/test_trezor.crypto.hashlib.blake2b.py index 7193a8f84..1f66a631b 100644 --- a/tests/test_trezor.crypto.hashlib.blake2b.py +++ b/tests/test_trezor.crypto.hashlib.blake2b.py @@ -2,10 +2,10 @@ from common import * from trezor.crypto import hashlib + class TestCryptoBlake2b(unittest.TestCase): # vectors from https://raw.githubusercontent.com/BLAKE2/BLAKE2/master/testvectors/blake2b-kat.txt - vectors = [ ('', '10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568'), ('00', '961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd'), @@ -44,5 +44,6 @@ class TestCryptoBlake2b(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.blake2s.py b/tests/test_trezor.crypto.hashlib.blake2s.py index 686310258..0d4d229a4 100644 --- a/tests/test_trezor.crypto.hashlib.blake2s.py +++ b/tests/test_trezor.crypto.hashlib.blake2s.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoBlake2s(unittest.TestCase): # vectors from https://raw.githubusercontent.com/BLAKE2/BLAKE2/master/testvectors/blake2s-kat.txt @@ -44,5 +45,6 @@ class TestCryptoBlake2s(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.ripemd160.py b/tests/test_trezor.crypto.hashlib.ripemd160.py index 9c2170ada..a975cabba 100644 --- a/tests/test_trezor.crypto.hashlib.ripemd160.py +++ b/tests/test_trezor.crypto.hashlib.ripemd160.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoRipemd160(unittest.TestCase): # vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html @@ -39,5 +40,6 @@ class TestCryptoRipemd160(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.sha1.py b/tests/test_trezor.crypto.hashlib.sha1.py index 5ec363410..b68306a73 100644 --- a/tests/test_trezor.crypto.hashlib.sha1.py +++ b/tests/test_trezor.crypto.hashlib.sha1.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoSha1(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html @@ -12,7 +13,6 @@ class TestCryptoSha1(unittest.TestCase): (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'a49b2446a02c645bf419f995b67091253a04a259') ] - def test_digest(self): for b, d in self.vectors: self.assertEqual(hashlib.sha1(b).digest(), unhexlify(d)) @@ -43,5 +43,6 @@ class TestCryptoSha1(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.sha256.py b/tests/test_trezor.crypto.hashlib.sha256.py index 9cb9fdec5..28a7db1ab 100644 --- a/tests/test_trezor.crypto.hashlib.sha256.py +++ b/tests/test_trezor.crypto.hashlib.sha256.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoSha256(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html @@ -42,5 +43,6 @@ class TestCryptoSha256(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.sha3_256.py b/tests/test_trezor.crypto.hashlib.sha3_256.py index 8f41fe203..47606628a 100644 --- a/tests/test_trezor.crypto.hashlib.sha3_256.py +++ b/tests/test_trezor.crypto.hashlib.sha3_256.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoSha3_256(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html @@ -59,7 +60,7 @@ class TestCryptoSha3_256(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) - def test_digest_multi(self): + def test_digest_multi_keccak(self): x = hashlib.sha3_256() d0 = x.digest(True) d1 = x.digest(True) @@ -67,5 +68,6 @@ class TestCryptoSha3_256(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.sha3_512.py b/tests/test_trezor.crypto.hashlib.sha3_512.py index 0b87d3866..c7e273bc2 100644 --- a/tests/test_trezor.crypto.hashlib.sha3_512.py +++ b/tests/test_trezor.crypto.hashlib.sha3_512.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoSha3_512(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html @@ -59,7 +60,7 @@ class TestCryptoSha3_512(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) - def test_digest_multi(self): + def test_digest_multi_keccak(self): x = hashlib.sha3_512() d0 = x.digest(True) d1 = x.digest(True) @@ -67,5 +68,6 @@ class TestCryptoSha3_512(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hashlib.sha512.py b/tests/test_trezor.crypto.hashlib.sha512.py index 78b8de013..66530eadc 100644 --- a/tests/test_trezor.crypto.hashlib.sha512.py +++ b/tests/test_trezor.crypto.hashlib.sha512.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import hashlib + class TestCryptoSha512(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html @@ -42,5 +43,6 @@ class TestCryptoSha512(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.hmac.py b/tests/test_trezor.crypto.hmac.py index 6bcf2bad3..d827d7d37 100644 --- a/tests/test_trezor.crypto.hmac.py +++ b/tests/test_trezor.crypto.hmac.py @@ -4,6 +4,7 @@ from trezor.crypto import hashlib from trezor.crypto import hmac + class TestCryptoHmac(unittest.TestCase): # vectors from https://tools.ietf.org/html/rfc4231 @@ -34,13 +35,13 @@ class TestCryptoHmac(unittest.TestCase): self.assertEqual(hmac.new(key, msg, hashlib.sha256).digest(), unhexlify('82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b')) self.assertEqual(hmac.new(key, msg, hashlib.sha512).digest(), unhexlify('b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd')) - # case 6 + # case 6 key = bytes([0xAA] * 131) msg = b'Test Using Larger Than Block-Size Key - Hash Key First' self.assertEqual(hmac.new(key, msg, hashlib.sha256).digest(), unhexlify('60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54')) self.assertEqual(hmac.new(key, msg, hashlib.sha512).digest(), unhexlify('80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598')) - # case 7 + # case 7 key = bytes([0xAA] * 131) msg = b'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.' self.assertEqual(hmac.new(key, msg, hashlib.sha256).digest(), unhexlify('9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2')) @@ -78,5 +79,6 @@ class TestCryptoHmac(unittest.TestCase): self.assertEqual(d0, d1) self.assertEqual(d0, d2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.pbkdf2.py b/tests/test_trezor.crypto.pbkdf2.py index 2646ed703..80246d168 100644 --- a/tests/test_trezor.crypto.pbkdf2.py +++ b/tests/test_trezor.crypto.pbkdf2.py @@ -2,9 +2,11 @@ from common import * from trezor.crypto import pbkdf2 + class TestCryptoPbkdf2(unittest.TestCase): # vectors from https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors + def test_pbkdf2_hmac_sha256(self): P = b'password' S = b'salt' @@ -45,6 +47,7 @@ class TestCryptoPbkdf2(unittest.TestCase): self.assertEqual(dk, unhexlify('348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1')) # vectors from https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors + def test_pbkdf2_hmac_sha512(self): P = b'password' S = b'salt' @@ -100,5 +103,6 @@ class TestCryptoPbkdf2(unittest.TestCase): self.assertEqual(k0, k1) self.assertEqual(k0, k2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.random.py b/tests/test_trezor.crypto.random.py index 1662eb631..5a3aaf094 100644 --- a/tests/test_trezor.crypto.random.py +++ b/tests/test_trezor.crypto.random.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import random + class TestCryptoRandom(unittest.TestCase): def test_uniform(self): @@ -41,5 +42,6 @@ class TestCryptoRandom(unittest.TestCase): self.assertEqual(len(lst), l) self.assertEqual(sorted(lst), list(range(l))) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.rfc6979.py b/tests/test_trezor.crypto.rfc6979.py index 328d017e6..b303231d1 100644 --- a/tests/test_trezor.crypto.rfc6979.py +++ b/tests/test_trezor.crypto.rfc6979.py @@ -3,6 +3,7 @@ from common import * from trezor.crypto import rfc6979 from trezor.crypto.hashlib import sha256 + class TestCryptoRfc6979(unittest.TestCase): def test_vectors(self): @@ -34,5 +35,6 @@ class TestCryptoRfc6979(unittest.TestCase): rng = rfc6979(unhexlify(key), sha256(msg).digest()) self.assertEqual(rng.next(), unhexlify(k)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.crypto.rlp.py b/tests/test_trezor.crypto.rlp.py index b7db3ecb5..9c57d9141 100644 --- a/tests/test_trezor.crypto.rlp.py +++ b/tests/test_trezor.crypto.rlp.py @@ -2,6 +2,7 @@ from common import * from trezor.crypto import rlp + class TestCryptoRlp(unittest.TestCase): # from https://raw.githubusercontent.com/ethereum/pyrlp/develop/tests/rlptest.json @@ -40,11 +41,11 @@ class TestCryptoRlp(unittest.TestCase): 'cc83646f6783676f6483636174'), ([b'zw', [4], 1], 'c6827a77c10401'), - ([b'asdf', b'qwer', b'zxcv', b'asdf',b'qwer', b'zxcv', b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer'], + ([b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer'], 'f784617364668471776572847a78637684617364668471776572847a78637684617364668471776572847a78637684617364668471776572'), - ([[b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv']], + ([[b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv']], 'f840cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376'), - ([[b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv'], [b'asdf',b'qwer',b'zxcv']], + ([[b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv']], 'f90200cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376'), ([[[], []], []], 'c4c2c0c0c0'), @@ -63,5 +64,6 @@ class TestCryptoRlp(unittest.TestCase): o2 = rlp.encode(i) self.assertEqual(o, o2) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.io.py b/tests/test_trezor.io.py index c960726f8..69cf31a16 100644 --- a/tests/test_trezor.io.py +++ b/tests/test_trezor.io.py @@ -7,27 +7,27 @@ class TestIo(unittest.TestCase): def test_sdcard_start(self): sd = io.SDCard() - assert sd.present() == True + assert sd.present() is True def test_sdcard_power(self): sd = io.SDCard() x = bytearray(8 * 512) assert sd.capacity() == 0 - assert sd.read(0, x) == False + assert sd.read(0, x) is False sd.power(True) assert sd.capacity() > 0 - assert sd.read(0, x) == True + assert sd.read(0, x) is True sd.power(False) assert sd.capacity() == 0 - assert sd.read(0, x) == False + assert sd.read(0, x) is False def test_sdcard_read(self): sd = io.SDCard() x = bytearray(8 * 512) sd.power(True) - assert sd.read(0, x) == True + assert sd.read(0, x) is True sd.power(False) - assert sd.read(0, x) == False + assert sd.read(0, x) is False def test_sdcard_read_write(self): sd = io.SDCard() @@ -35,11 +35,11 @@ class TestIo(unittest.TestCase): w0 = bytearray(b'0' * (8 * 512)) w1 = bytearray(b'1' * (8 * 512)) sd.power(True) - assert sd.write(0, w0) == True - assert sd.read(0, r) == True + assert sd.write(0, w0) is True + assert sd.read(0, r) is True assert r == w0 - assert sd.write(0, w1) == True - assert sd.read(0, r) == True + assert sd.write(0, w1) is True + assert sd.read(0, r) is True assert r == w1 sd.power(False) diff --git a/tests/test_trezor.ui.display.py b/tests/test_trezor.ui.display.py index a8f6a5111..21a8e3902 100644 --- a/tests/test_trezor.ui.display.py +++ b/tests/test_trezor.ui.display.py @@ -4,6 +4,7 @@ from trezor.crypto import random from trezor.ui import display + class TestDisplay(unittest.TestCase): def test_clear(self): @@ -68,5 +69,6 @@ class TestDisplay(unittest.TestCase): def test_save(self): pass + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.utils.py b/tests/test_trezor.utils.py index 7e22d16c0..0adba98f4 100644 --- a/tests/test_trezor.utils.py +++ b/tests/test_trezor.utils.py @@ -2,6 +2,7 @@ from common import * from trezor import utils + class TestUtils(unittest.TestCase): def test_chunks(self): @@ -12,5 +13,6 @@ class TestUtils(unittest.TestCase): self.assertEqual(c[i].stop, 100 if (i == 14) else (i + 1) * 7) self.assertEqual(c[i].step, 1) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_trezor.wire.codec_v1.py b/tests/test_trezor.wire.codec_v1.py index 78ac96599..e5736d08a 100644 --- a/tests/test_trezor.wire.codec_v1.py +++ b/tests/test_trezor.wire.codec_v1.py @@ -40,26 +40,26 @@ def test_reader(): # open, expected one read first_report = report_header + message[:rep_len - len(report_header)] - assert_async(reader.aopen(), [(None, select(io.POLL_READ | interface_num)), (first_report, StopIteration()),]) + assert_async(reader.aopen(), [(None, select(io.POLL_READ | interface_num)), (first_report, StopIteration()), ]) assert_eq(reader.type, message_type) assert_eq(reader.size, message_len) # empty read empty_buffer = bytearray() - assert_async(reader.areadinto(empty_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(empty_buffer), [(None, StopIteration()), ]) assert_eq(len(empty_buffer), 0) assert_eq(reader.size, message_len) # short read, expected no read short_buffer = bytearray(32) - assert_async(reader.areadinto(short_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(short_buffer), [(None, StopIteration()), ]) assert_eq(len(short_buffer), 32) assert_eq(short_buffer, message[:len(short_buffer)]) assert_eq(reader.size, message_len - len(short_buffer)) # aligned read, expected no read aligned_buffer = bytearray(rep_len - len(report_header) - len(short_buffer)) - assert_async(reader.areadinto(aligned_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(aligned_buffer), [(None, StopIteration()), ]) assert_eq(aligned_buffer, message[len(short_buffer):][:len(aligned_buffer)]) assert_eq(reader.size, message_len - len(short_buffer) - len(aligned_buffer)) @@ -67,12 +67,12 @@ def test_reader(): next_report_header = bytearray(unhexlify('3f')) next_report = next_report_header + message[rep_len - len(report_header):][:rep_len - len(next_report_header)] onebyte_buffer = bytearray(1) - assert_async(reader.areadinto(onebyte_buffer), [(None, select(io.POLL_READ | interface_num)), (next_report, StopIteration()),]) + assert_async(reader.areadinto(onebyte_buffer), [(None, select(io.POLL_READ | interface_num)), (next_report, StopIteration()), ]) assert_eq(onebyte_buffer, message[len(short_buffer):][len(aligned_buffer):][:len(onebyte_buffer)]) assert_eq(reader.size, message_len - len(short_buffer) - len(aligned_buffer) - len(onebyte_buffer)) # too long read, raises eof - assert_async(reader.areadinto(bytearray(reader.size + 1)), [(None, EOFError()),]) + assert_async(reader.areadinto(bytearray(reader.size + 1)), [(None, EOFError()), ]) # long read, expect multiple reads start_size = reader.size @@ -93,7 +93,7 @@ def test_reader(): assert_eq(reader.size, 0) # one byte read, raises eof - assert_async(reader.areadinto(onebyte_buffer), [(None, EOFError()),]) + assert_async(reader.areadinto(onebyte_buffer), [(None, EOFError()), ]) def test_writer(): @@ -112,35 +112,35 @@ def test_writer(): # empty write start_size = writer.size - assert_async(writer.awrite(bytearray()), [(None, StopIteration()),]) + assert_async(writer.awrite(bytearray()), [(None, StopIteration()), ]) assert_eq(writer.data, report_header + bytearray(rep_len - len(report_header))) assert_eq(writer.size, start_size) # short write, expected no report start_size = writer.size short_payload = bytearray(range(4)) - assert_async(writer.awrite(short_payload), [(None, StopIteration()),]) + assert_async(writer.awrite(short_payload), [(None, StopIteration()), ]) assert_eq(writer.size, start_size - len(short_payload)) assert_eq(writer.data, - report_header - + short_payload - + bytearray(rep_len - len(report_header) - len(short_payload))) + report_header + + short_payload + + bytearray(rep_len - len(report_header) - len(short_payload))) # aligned write, expected one report start_size = writer.size aligned_payload = bytearray(range(rep_len - len(report_header) - len(short_payload))) - assert_async(writer.awrite(aligned_payload), [(None, select(io.POLL_WRITE | interface_num)), (None, StopIteration()),]) - assert_eq(interface.data, [report_header - + short_payload - + aligned_payload - + bytearray(rep_len - len(report_header) - len(short_payload) - len(aligned_payload)), ]) + assert_async(writer.awrite(aligned_payload), [(None, select(io.POLL_WRITE | interface_num)), (None, StopIteration()), ]) + assert_eq(interface.data, [report_header + + short_payload + + aligned_payload + + bytearray(rep_len - len(report_header) - len(short_payload) - len(aligned_payload)), ]) assert_eq(writer.size, start_size - len(aligned_payload)) interface.data.clear() # short write, expected no report, but data starts with correct seq and cont marker report_header = bytearray(unhexlify('3f')) start_size = writer.size - assert_async(writer.awrite(short_payload), [(None, StopIteration()),]) + assert_async(writer.awrite(short_payload), [(None, StopIteration()), ]) assert_eq(writer.size, start_size - len(short_payload)) assert_eq(writer.data[:len(report_header) + len(short_payload)], report_header + short_payload) diff --git a/tests/test_trezor.wire.codec_v2.py b/tests/test_trezor.wire.codec_v2.py index ce10f582e..c3fcf0fe9 100644 --- a/tests/test_trezor.wire.codec_v2.py +++ b/tests/test_trezor.wire.codec_v2.py @@ -40,26 +40,26 @@ def test_reader(): # open, expected one read first_report = report_header + message[:rep_len - len(report_header)] - assert_async(reader.aopen(), [(None, select(io.POLL_READ | interface_num)), (first_report, StopIteration()),]) + assert_async(reader.aopen(), [(None, select(io.POLL_READ | interface_num)), (first_report, StopIteration()), ]) assert_eq(reader.type, message_type) assert_eq(reader.size, message_len) # empty read empty_buffer = bytearray() - assert_async(reader.areadinto(empty_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(empty_buffer), [(None, StopIteration()), ]) assert_eq(len(empty_buffer), 0) assert_eq(reader.size, message_len) # short read, expected no read short_buffer = bytearray(32) - assert_async(reader.areadinto(short_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(short_buffer), [(None, StopIteration()), ]) assert_eq(len(short_buffer), 32) assert_eq(short_buffer, message[:len(short_buffer)]) assert_eq(reader.size, message_len - len(short_buffer)) # aligned read, expected no read aligned_buffer = bytearray(rep_len - len(report_header) - len(short_buffer)) - assert_async(reader.areadinto(aligned_buffer), [(None, StopIteration()),]) + assert_async(reader.areadinto(aligned_buffer), [(None, StopIteration()), ]) assert_eq(aligned_buffer, message[len(short_buffer):][:len(aligned_buffer)]) assert_eq(reader.size, message_len - len(short_buffer) - len(aligned_buffer)) @@ -67,12 +67,12 @@ def test_reader(): next_report_header = bytearray(unhexlify('021234567800000000')) next_report = next_report_header + message[rep_len - len(report_header):][:rep_len - len(next_report_header)] onebyte_buffer = bytearray(1) - assert_async(reader.areadinto(onebyte_buffer), [(None, select(io.POLL_READ | interface_num)), (next_report, StopIteration()),]) + assert_async(reader.areadinto(onebyte_buffer), [(None, select(io.POLL_READ | interface_num)), (next_report, StopIteration()), ]) assert_eq(onebyte_buffer, message[len(short_buffer):][len(aligned_buffer):][:len(onebyte_buffer)]) assert_eq(reader.size, message_len - len(short_buffer) - len(aligned_buffer) - len(onebyte_buffer)) # too long read, raises eof - assert_async(reader.areadinto(bytearray(reader.size + 1)), [(None, EOFError()),]) + assert_async(reader.areadinto(bytearray(reader.size + 1)), [(None, EOFError()), ]) # long read, expect multiple reads start_size = reader.size @@ -93,7 +93,7 @@ def test_reader(): assert_eq(reader.size, 0) # one byte read, raises eof - assert_async(reader.areadinto(onebyte_buffer), [(None, EOFError()),]) + assert_async(reader.areadinto(onebyte_buffer), [(None, EOFError()), ]) def test_writer(): @@ -113,35 +113,35 @@ def test_writer(): # empty write start_size = writer.size - assert_async(writer.awrite(bytearray()), [(None, StopIteration()),]) + assert_async(writer.awrite(bytearray()), [(None, StopIteration()), ]) assert_eq(writer.data, report_header + bytearray(rep_len - len(report_header))) assert_eq(writer.size, start_size) # short write, expected no report start_size = writer.size short_payload = bytearray(range(4)) - assert_async(writer.awrite(short_payload), [(None, StopIteration()),]) + assert_async(writer.awrite(short_payload), [(None, StopIteration()), ]) assert_eq(writer.size, start_size - len(short_payload)) assert_eq(writer.data, - report_header - + short_payload - + bytearray(rep_len - len(report_header) - len(short_payload))) + report_header + + short_payload + + bytearray(rep_len - len(report_header) - len(short_payload))) # aligned write, expected one report start_size = writer.size aligned_payload = bytearray(range(rep_len - len(report_header) - len(short_payload))) - assert_async(writer.awrite(aligned_payload), [(None, select(io.POLL_WRITE | interface_num)), (None, StopIteration()),]) - assert_eq(interface.data, [report_header - + short_payload - + aligned_payload - + bytearray(rep_len - len(report_header) - len(short_payload) - len(aligned_payload)), ]) + assert_async(writer.awrite(aligned_payload), [(None, select(io.POLL_WRITE | interface_num)), (None, StopIteration()), ]) + assert_eq(interface.data, [report_header + + short_payload + + aligned_payload + + bytearray(rep_len - len(report_header) - len(short_payload) - len(aligned_payload)), ]) assert_eq(writer.size, start_size - len(aligned_payload)) interface.data.clear() # short write, expected no report, but data starts with correct seq and cont marker report_header = bytearray(unhexlify('021234567800000000')) start_size = writer.size - assert_async(writer.awrite(short_payload), [(None, StopIteration()),]) + assert_async(writer.awrite(short_payload), [(None, StopIteration()), ]) assert_eq(writer.size, start_size - len(short_payload)) assert_eq(writer.data[:len(report_header) + len(short_payload)], report_header + short_payload)