Separate address tests from crypto and rename the test case

This commit is contained in:
Dmitri Bogomolov 2021-07-20 20:06:01 +03:00
parent 159245b72e
commit ddb366b477
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 39 additions and 21 deletions

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 = \ sample_privencryptionkey = \
'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a' '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f' sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
# stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733 sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733
# G * sample_factor # G * sample_factor
@ -76,8 +74,9 @@ class TestCrypto(RIPEMD160TestCase, unittest.TestCase):
return RIPEMD.RIPEMD160Hash(data).digest() return RIPEMD.RIPEMD160Hash(data).digest()
class TestAddresses(unittest.TestCase): class TestHighlevelcrypto(unittest.TestCase):
"""Test addresses manipulations""" """Test highlevelcrypto public functions"""
def test_base10_multiply(self): def test_base10_multiply(self):
"""Test arithmetic.base10_multiply""" """Test arithmetic.base10_multiply"""
self.assertEqual( self.assertEqual(
@ -94,20 +93,3 @@ class TestAddresses(unittest.TestCase):
arithmetic.privtopub(sample_privencryptionkey).encode(), arithmetic.privtopub(sample_privencryptionkey).encode(),
hexlify(sample_pubencryptionkey) 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))