From feaee606321dbae2fc2b796784e3e38d046e3ca8 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Thu, 29 Jul 2021 16:33:33 +0300 Subject: [PATCH] Add a test for WIF decoding and encoding --- src/tests/samples.py | 10 ++++++++++ src/tests/test_addresses.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/tests/samples.py b/src/tests/samples.py index e33c5f50..42a14f58 100644 --- a/src/tests/samples.py +++ b/src/tests/samples.py @@ -73,3 +73,13 @@ sample_sig = unhexlify( sample_sig_sha1 = unhexlify( '30460221008ad234687d1bdc259932e28ea6ee091b88b0900d8134902aa8c2fd7f016b96e' 'd022100dafb94e28322c2fa88878f9dcbf0c2d33270466ab3bbffaec3dca0a2d1ef9354') + +# [chan] bitmessage +sample_wif_privsigningkey = unhexlify( + b'a2e8b841a531c1c558ee0680c396789c7a2ea3ac4795ae3f000caf9fe367d144') +sample_wif_privencryptionkey = unhexlify( + b'114ec0e2dca24a826a0eed064b0405b0ac148abc3b1d52729697f4d7b873fdc6') +sample_privsigningkey_wif = \ + b'5K42shDERM5g7Kbi3JT5vsAWpXMqRhWZpX835M2pdSoqQQpJMYm' +sample_privencryptionkey_wif = \ + b'5HwugVWm31gnxtoYcvcK7oywH2ezYTh6Y4tzRxsndAeMi6NHqpA' diff --git a/src/tests/test_addresses.py b/src/tests/test_addresses.py index 8f9c283d..dd989562 100644 --- a/src/tests/test_addresses.py +++ b/src/tests/test_addresses.py @@ -2,12 +2,14 @@ import unittest from binascii import unhexlify -from pybitmessage import addresses +from pybitmessage import addresses, highlevelcrypto from .samples import ( sample_address, sample_daddr3_512, sample_daddr4_512, sample_deterministic_addr4, sample_deterministic_addr3, - sample_deterministic_ripe, sample_ripe) + sample_deterministic_ripe, sample_ripe, + sample_privsigningkey_wif, sample_privencryptionkey_wif, + sample_wif_privsigningkey, sample_wif_privencryptionkey) sample_addr3 = sample_deterministic_addr3.split('-')[1] sample_addr4 = sample_deterministic_addr4.split('-')[1] @@ -59,3 +61,26 @@ class TestAddresses(unittest.TestCase): sample_addr4, addresses.encodeBase58(sample_daddr4_512)) self.assertEqual( sample_addr3, addresses.encodeBase58(sample_daddr3_512)) + + def test_wif(self): + """Decode WIFs of [chan] bitmessage and check the keys""" + self.assertEqual( + sample_wif_privsigningkey, + highlevelcrypto.decodeWalletImportFormat( + sample_privsigningkey_wif)) + self.assertEqual( + sample_wif_privencryptionkey, + highlevelcrypto.decodeWalletImportFormat( + sample_privencryptionkey_wif)) + self.assertEqual( + sample_privsigningkey_wif, + highlevelcrypto.encodeWalletImportFormat( + sample_wif_privsigningkey)) + self.assertEqual( + sample_privencryptionkey_wif, + highlevelcrypto.encodeWalletImportFormat( + sample_wif_privencryptionkey)) + + with self.assertRaises(ValueError): + highlevelcrypto.decodeWalletImportFormat( + sample_privencryptionkey_wif[:-2])