mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-15 09:02:02 +00:00
tests: cleanup flake8 warnings
This commit is contained in:
parent
ea404b53ee
commit
965bf84cdb
6
Makefile
6
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:
|
||||
|
||||
|
@ -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()
|
||||
|
@ -2,6 +2,7 @@ from common import *
|
||||
|
||||
from apps.common import coins
|
||||
|
||||
|
||||
class TestCoins(unittest.TestCase):
|
||||
|
||||
def test_coins(self):
|
||||
|
@ -91,6 +91,5 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
|
||||
self.assertEqual(hexlify(result), b'c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670')
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -78,6 +78,5 @@ class TestSegwitBip143(unittest.TestCase):
|
||||
self.assertEqual(hexlify(result), b'64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6')
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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
|
||||
|
||||
|
@ -105,5 +105,6 @@ class TestConfig(unittest.TestCase):
|
||||
value = config.get(appid, key)
|
||||
self.assertEqual(value, bytes())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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",
|
||||
@ -129,5 +131,6 @@ class TestCryptoBech32(unittest.TestCase):
|
||||
code = bech32.encode(hrp, version, [0] * length)
|
||||
self.assertIsNone(code)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
@ -121,5 +121,6 @@ class TestCryptoNist256p1(unittest.TestCase):
|
||||
pk2 = nist256p1.verify_recover(sig, dig)
|
||||
self.assertEqual(pk, pk2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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:
|
||||
@ -110,5 +110,6 @@ class TestCryptoSecp256k1(unittest.TestCase):
|
||||
pk2 = secp256k1.verify_recover(sig, dig)
|
||||
self.assertEqual(pk, pk2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -2,6 +2,7 @@ from common import *
|
||||
|
||||
from trezor.crypto import der
|
||||
|
||||
|
||||
class TestCryptoDer(unittest.TestCase):
|
||||
|
||||
vectors_seq = [
|
||||
@ -50,5 +51,6 @@ class TestCryptoDer(unittest.TestCase):
|
||||
d2 = der.encode_seq(s)
|
||||
self.assertEqual(d, d2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
@ -78,5 +79,6 @@ class TestCryptoHmac(unittest.TestCase):
|
||||
self.assertEqual(d0, d1)
|
||||
self.assertEqual(d0, d2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
@ -63,5 +64,6 @@ class TestCryptoRlp(unittest.TestCase):
|
||||
o2 = rlp.encode(i)
|
||||
self.assertEqual(o, o2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -122,18 +122,18 @@ def test_writer():
|
||||
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_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()
|
||||
|
||||
|
@ -123,18 +123,18 @@ def test_writer():
|
||||
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_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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user