Refactoring crypto base changes #1806

Merged
g1itch merged 14 commits from crypto-sort into v0.6 2021-08-17 15:07:33 +02:00
2 changed files with 39 additions and 21 deletions
Showing only changes of commit ddb366b477 - Show all commits

View File

@ -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)

View File

@ -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))