1
|
|
|
from unittest import TestCase |
2
|
|
|
from tests import WALLET_MNEMONIC, WALLET_PRIVATE_KEY, WALLET_PUBLIC_KEY, WALLET_ADDRESS |
3
|
|
|
from tradehub.wallet import Wallet |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class TestTradeHubGenerateWallet(TestCase): |
7
|
|
|
|
8
|
|
|
def setUp(self) -> None: |
9
|
|
|
self._wallet = Wallet(mnemonic=WALLET_MNEMONIC) |
10
|
|
|
|
11
|
|
|
def test_get_12_word_wallet(self): |
12
|
|
|
""" |
13
|
|
|
Check if Wallet generates a 12 word mnemonic. |
14
|
|
|
:return: |
15
|
|
|
""" |
16
|
|
|
|
17
|
|
|
result: str = self._wallet.generate_12_word_wallet() |
18
|
|
|
self.assertIsInstance(result, str, msg="Expected result to be type {}, got {} instead.".format("str", type(result))) |
19
|
|
|
self.assertEqual(len(result.split()), 12) |
20
|
|
|
|
21
|
|
|
def test_get_24_word_wallet(self): |
22
|
|
|
""" |
23
|
|
|
Check if Wallet generates a 24 word mnemonic. |
24
|
|
|
:return: |
25
|
|
|
""" |
26
|
|
|
|
27
|
|
|
result: str = self._wallet.generate_24_word_wallet() |
28
|
|
|
self.assertIsInstance(result, str, msg="Expected result to be type {}, got {} instead.".format("str", type(result))) |
29
|
|
|
self.assertEqual(len(result.split()), 24) |
30
|
|
|
|
31
|
|
|
def test_mnemonic_to_private_key(self): |
32
|
|
|
""" |
33
|
|
|
Check if Wallet Private Key derivation is accurate. |
34
|
|
|
:return: |
35
|
|
|
""" |
36
|
|
|
|
37
|
|
|
result: bytes = self._wallet.mnemonic_to_private_key(mnemonic_phrase=WALLET_MNEMONIC) |
38
|
|
|
self.assertIsInstance(result, bytes, msg="Expected result to be type {}, got {} instead.".format("bytes", type(result))) |
39
|
|
|
self.assertEqual(result, WALLET_PRIVATE_KEY) |
40
|
|
|
|
41
|
|
|
def test_private_key_to_public_key(self): |
42
|
|
|
""" |
43
|
|
|
Check if Wallet Public Key derived from the Private Key is as expected. |
44
|
|
|
:return: |
45
|
|
|
""" |
46
|
|
|
|
47
|
|
|
result: bytes = self._wallet.private_key_to_public_key(private_key=WALLET_PRIVATE_KEY) |
48
|
|
|
self.assertIsInstance(result, bytes, msg="Expected result to be type {}, got {} instead.".format("bytes", type(result))) |
49
|
|
|
self.assertEqual(result, WALLET_PUBLIC_KEY) |
50
|
|
|
|
51
|
|
|
def test_public_key_to_address(self): |
52
|
|
|
""" |
53
|
|
|
Check if Wallet Address derived from the Public Key is as expected. |
54
|
|
|
:return: |
55
|
|
|
""" |
56
|
|
|
|
57
|
|
|
result: str = self._wallet.public_key_to_address(public_key=WALLET_PUBLIC_KEY, hrp="tswth") |
58
|
|
|
self.assertIsInstance(result, str, msg="Expected result to be type {}, got {} instead.".format("str", type(result))) |
59
|
|
|
self.assertEqual(result, WALLET_ADDRESS) |
60
|
|
|
|
61
|
|
|
def test_private_key_to_address(self): |
62
|
|
|
""" |
63
|
|
|
Check if Wallet Address derived from the Private Key is as expected. |
64
|
|
|
:return: |
65
|
|
|
""" |
66
|
|
|
|
67
|
|
|
result: str = self._wallet.private_key_to_address(private_key=WALLET_PRIVATE_KEY, hrp="tswth") |
68
|
|
|
self.assertIsInstance(result, str, msg="Expected result to be type {}, got {} instead.".format("str", type(result))) |
69
|
|
|
self.assertEqual(result, WALLET_ADDRESS) |
70
|
|
|
|
71
|
|
|
def test_signing(self): |
72
|
|
|
""" |
73
|
|
|
Check if Signature returns the expected results. |
74
|
|
|
:return: |
75
|
|
|
""" |
76
|
|
|
|
77
|
|
|
result: str = self._wallet._sign(message="Hello Switcheo") |
78
|
|
|
self.assertIsInstance(result, str, msg="Expected result to be type {}, got {} instead.".format("str", type(result))) |
79
|
|
|
self.assertEqual(result, '104CCiE3SxWHhB0LI5apCOsC68CrNIcCIragNhr8ok0K8eoL+tuxDnKQ/BpBRT75oGxdh6g9nzAiV9t0KajYFQ==') |
80
|
|
|
|