From ddb366b47701d470eeb54cb737f7e31ecc911d80 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 20 Jul 2021 20:06:01 +0300 Subject: [PATCH] Separate address tests from crypto and rename the test case --- src/tests/test_addresses.py | 36 ++++++++++++++++++++++++++++++++++++ src/tests/test_crypto.py | 24 +++--------------------- 2 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 src/tests/test_addresses.py diff --git a/src/tests/test_addresses.py b/src/tests/test_addresses.py new file mode 100644 index 00000000..69208e2e --- /dev/null +++ b/src/tests/test_addresses.py @@ -0,0 +1,36 @@ + +import unittest +from binascii import unhexlify + +from pybitmessage import addresses + + +sample_ripe = unhexlify('003cd097eb7f35c87b5dc8b4538c22cb55312a9f') +# stream: 1, version: 2 +sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79' + + +class TestAddresses(unittest.TestCase): + """Test addresses manipulations""" + + def test_decode(self): + """Decode some well known addresses and check the result""" + self.assertEqual( + addresses.decodeAddress(sample_address), + ('success', 2, 1, sample_ripe)) + status, version, stream, ripe1 = addresses.decodeAddress( + '2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK') + self.assertEqual(status, 'success') + self.assertEqual(stream, 1) + self.assertEqual(version, 4) + status, version, stream, ripe2 = addresses.decodeAddress( + '2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN') + self.assertEqual(status, 'success') + self.assertEqual(stream, 1) + self.assertEqual(version, 3) + self.assertEqual(ripe1, ripe2) + + def test_encode(self): + """Encode sample ripe and compare the result to sample address""" + self.assertEqual( + addresses.encodeAddress(2, 1, sample_ripe), sample_address) diff --git a/src/tests/test_crypto.py b/src/tests/test_crypto.py index b94f626e..0c2675a3 100644 --- a/src/tests/test_crypto.py +++ b/src/tests/test_crypto.py @@ -28,8 +28,6 @@ sample_privsigningkey = \ sample_privencryptionkey = \ '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a' sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f' -# stream: 1, version: 2 -sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79' sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733 # G * sample_factor @@ -76,8 +74,9 @@ class TestCrypto(RIPEMD160TestCase, unittest.TestCase): return RIPEMD.RIPEMD160Hash(data).digest() -class TestAddresses(unittest.TestCase): - """Test addresses manipulations""" +class TestHighlevelcrypto(unittest.TestCase): + """Test highlevelcrypto public functions""" + def test_base10_multiply(self): """Test arithmetic.base10_multiply""" self.assertEqual( @@ -94,20 +93,3 @@ class TestAddresses(unittest.TestCase): arithmetic.privtopub(sample_privencryptionkey).encode(), hexlify(sample_pubencryptionkey) ) - - def test_address(self): - """Create address and check the result""" - from pybitmessage import addresses - from pybitmessage.fallback import RIPEMD160Hash - - sha = hashlib.new('sha512') - sha.update(sample_pubsigningkey + sample_pubencryptionkey) - ripe_hash = RIPEMD160Hash(sha.digest()).digest() - self.assertEqual(ripe_hash, unhexlify(sample_ripe)) - - self.assertEqual( - addresses.encodeAddress(2, 1, ripe_hash), sample_address) - - self.assertEqual( - addresses.decodeAddress(sample_address), - ('success', 2, 1, ripe_hash))