Refactoring crypto base changes #1806
36
src/tests/test_addresses.py
Normal file
36
src/tests/test_addresses.py
Normal 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)
|
|
@ -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))
|
||||
|
|
Reference in New Issue
Block a user