ttests: test with all AES implementations - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit d03da4d1a22a5f77e5700a89ab3bd78f3eedd9c9 DIR parent 770f438249078b598964d44b72242fc64e4ece75 HTML Author: SomberNight <somber.night@protonmail.com> Date: Fri, 25 May 2018 22:06:45 +0200 ttests: test with all AES implementations Diffstat: M lib/tests/test_bitcoin.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+), 0 deletions(-) --- DIR diff --git a/lib/tests/test_bitcoin.py b/lib/tests/test_bitcoin.py t@@ -53,12 +53,40 @@ def needs_test_with_all_ecc_implementations(func): return run_test +def needs_test_with_all_aes_implementations(func): + """Function decorator to run a unit test twice: + once when pycryptodomex is not available, once when it is. + + NOTE: this is inherently sequential; + tests running in parallel would break things + """ + def run_test(*args, **kwargs): + _aes = crypto.AES + crypto.AES = None + try: + # first test without pycryptodomex + func(*args, **kwargs) + finally: + # if pycryptodomex is not available, we are done + if not _aes: + return + crypto.AES = _aes + # if pycryptodomex is available, test again now + func(*args, **kwargs) + return run_test + + class Test_bitcoin(SequentialTestCase): def test_libsecp256k1_is_available(self): # we want the unit testing framework to test with libsecp256k1 available. self.assertTrue(bool(ecc_fast._libsecp256k1)) + def test_pycryptodomex_is_available(self): + # we want the unit testing framework to test with pycryptodomex available. + self.assertTrue(bool(crypto.AES)) + + @needs_test_with_all_aes_implementations @needs_test_with_all_ecc_implementations def test_crypto(self): for message in [b"Chancellor on brink of second bailout for banks", b'\xff'*512]: t@@ -120,6 +148,7 @@ class Test_bitcoin(SequentialTestCase): self.assertFalse(ecc.verify_message_with_address(addr1, b'wrong', msg1)) self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1)) + @needs_test_with_all_aes_implementations @needs_test_with_all_ecc_implementations def test_decrypt_message(self): key = WalletStorage.get_eckey_from_password('pw123') t@@ -127,6 +156,7 @@ class Test_bitcoin(SequentialTestCase): self.assertEqual(b'me<(s_s)>age', key.decrypt_message(b'QklFMQKXOXbylOQTSMGfo4MFRwivAxeEEkewWQrpdYTzjPhqjHcGBJwdIhB7DyRfRQihuXx1y0ZLLv7XxLzrILzkl/H4YUtZB4uWjuOAcmxQH4i/Og==')) parazyd.org:70 /git/electrum/commit/d03da4d1a22a5f77e5700a89ab3bd78f3eedd9c9.gph:72: line too long