A working subset of #1788 #1875

Merged
g1itch merged 5 commits from compat-short into v0.6 2021-11-11 15:12:34 +01:00
2 changed files with 29 additions and 4 deletions
Showing only changes of commit ed52b41464 - Show all commits

View File

@ -27,5 +27,8 @@ sample_point = (
sample_seed = 'TIGER, tiger, burning bright. In the forests of the night'
# Deterministic addresses with stream 1 and versions 3, 4
sample_deterministic_ripe = b'00cfb69416ae76f68a81c459de4e13460c7d17eb'
sample_deterministic_addr3 = 'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN'
sample_deterministic_addr4 = 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
sample_daddr3_512 = 18875720106589866286514488037355423395410802084648916523381
sample_daddr4_512 = 25152821841976547050350277460563089811513157529113201589004

View File

@ -4,7 +4,13 @@ from binascii import unhexlify
from pybitmessage import addresses
from .samples import sample_address, sample_ripe
from .samples import (
sample_address, sample_daddr3_512, sample_daddr4_512,
sample_deterministic_addr4, sample_deterministic_addr3,
sample_deterministic_ripe, sample_ripe)
sample_addr3 = sample_deterministic_addr3.split('-')[1]
sample_addr4 = sample_deterministic_addr4.split('-')[1]
class TestAddresses(unittest.TestCase):
@ -17,19 +23,35 @@ class TestAddresses(unittest.TestCase):
('success', 2, 1, unhexlify(sample_ripe)))
status, version, stream, ripe1 = addresses.decodeAddress(
'2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
sample_deterministic_addr4)
self.assertEqual(status, 'success')
self.assertEqual(stream, 1)
self.assertEqual(version, 4)
status, version, stream, ripe2 = addresses.decodeAddress(
'2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN')
status, version, stream, ripe2 = addresses.decodeAddress(sample_addr3)
self.assertEqual(status, 'success')
self.assertEqual(stream, 1)
self.assertEqual(version, 3)
self.assertEqual(ripe1, ripe2)
self.assertEqual(ripe1, unhexlify(sample_deterministic_ripe))
def test_encode(self):
"""Encode sample ripe and compare the result to sample address"""
self.assertEqual(
sample_address,
addresses.encodeAddress(2, 1, unhexlify(sample_ripe)))
ripe = unhexlify(sample_deterministic_ripe)
self.assertEqual(
addresses.encodeAddress(3, 1, ripe),
'BM-%s' % addresses.encodeBase58(sample_daddr3_512))
def test_base58(self):
"""Check Base58 encoding and decoding"""
self.assertEqual(
addresses.decodeBase58(sample_addr4), sample_daddr4_512)
self.assertEqual(
addresses.decodeBase58(sample_addr3), sample_daddr3_512)
self.assertEqual(
sample_addr4, addresses.encodeBase58(sample_daddr4_512))
self.assertEqual(
sample_addr3, addresses.encodeBase58(sample_daddr3_512))