44
55from threading import Thread
66from time import sleep
7- from typing import List , Tuple
87from unittest import TestCase
98
109from mock import Mock , patch
1110
12- from iota import Address , Hash
11+ from iota import Address
1312from iota .crypto .addresses import AddressGenerator , MemoryAddressCache
1413from iota .crypto .signing import KeyIterator
15- from iota .crypto .types import Seed
14+ from iota .crypto .types import Digest , Seed
1615
1716
1817class AddressGeneratorTestCase (TestCase ):
@@ -21,7 +20,7 @@ def setUp(self):
2120 super (AddressGeneratorTestCase , self ).setUp ()
2221
2322 # Addresses that correspond to the digests defined in
24- # :py:meth:`_mock_get_digest_params `.
23+ # :py:meth:`_mock_get_digest `.
2524 self .addy0 = \
2625 Address (
2726 b'VOPYUSDRHYGGOHLAYDWCLLOFWBLK99PYYKENW9IQ'
@@ -52,13 +51,16 @@ def test_address_from_digest(self):
5251 Generating an address from a private key digest.
5352 """
5453 digest = \
55- Hash (
56- b'ABQXVJNER9MPMXMBPNMFBMDGTXRWSYHNZKGAGUOI'
57- b'JKOJGZVGHCUXXGFZEMMGDSGWDCKJXO9ILLFAKGGZE'
54+ Digest (
55+ trytes =
56+ b'ABQXVJNER9MPMXMBPNMFBMDGTXRWSYHNZKGAGUOI'
57+ b'JKOJGZVGHCUXXGFZEMMGDSGWDCKJXO9ILLFAKGGZE' ,
58+
59+ key_index = 0 ,
5860 )
5961
6062 self .assertEqual (
61- AddressGenerator .address_from_digest_trits (digest . as_trits (), 0 ),
63+ AddressGenerator .address_from_digest (digest ),
6264
6365 Address (
6466 b'QLOEDSBXXOLLUJYLEGKEPYDRIJJTPIMEPKMFHUVJ'
@@ -75,13 +77,13 @@ def test_get_addresses_single(self):
7577 ag = AddressGenerator (seed = b'' )
7678
7779 # noinspection PyUnresolvedReferences
78- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
80+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
7981 addresses = ag .get_addresses (start = 0 )
8082
8183 self .assertListEqual (addresses , [self .addy0 ])
8284
8385 # noinspection PyUnresolvedReferences
84- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
86+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
8587 # You can provide any positive integer as the ``start`` value.
8688 addresses = ag .get_addresses (start = 2 )
8789
@@ -96,7 +98,7 @@ def test_get_addresses_multiple(self):
9698 ag = AddressGenerator (seed = b'' )
9799
98100 # noinspection PyUnresolvedReferences
99- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
101+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
100102 addresses = ag .get_addresses (start = 1 , count = 2 )
101103
102104 self .assertListEqual (addresses , [self .addy1 , self .addy2 ])
@@ -145,7 +147,7 @@ def test_get_addresses_step_negative(self):
145147 ag = AddressGenerator (seed = b'' )
146148
147149 # noinspection PyUnresolvedReferences
148- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
150+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
149151 addresses = ag .get_addresses (start = 1 , count = 2 , step = - 1 )
150152
151153 self .assertListEqual (
@@ -165,7 +167,7 @@ def test_generator(self):
165167 ag = AddressGenerator (seed = b'' )
166168
167169 # noinspection PyUnresolvedReferences
168- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
170+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
169171 generator = ag .create_iterator ()
170172
171173 self .assertEqual (next (generator ), self .addy0 )
@@ -181,15 +183,15 @@ def test_generator_with_offset(self):
181183 ag = AddressGenerator (seed = b'' )
182184
183185 # noinspection PyUnresolvedReferences
184- with patch .object (ag , '_get_digest_params ' , self ._mock_get_digest_params ):
186+ with patch .object (ag , '_get_digest ' , self ._mock_get_digest ):
185187 generator = ag .create_iterator (start = 1 , step = 2 )
186188
187189 self .assertEqual (next (generator ), self .addy1 )
188190 self .assertEqual (next (generator ), self .addy3 )
189191
190192 @staticmethod
191- def _mock_get_digest_params (key_iterator ):
192- # type: (KeyIterator) -> Tuple[List[int], int]
193+ def _mock_get_digest (key_iterator ):
194+ # type: (KeyIterator) -> Digest
193195 """
194196 Mocks the behavior of :py:class:`KeyGenerator`, to speed up unit
195197 tests.
@@ -220,7 +222,7 @@ def _mock_get_digest_params(key_iterator):
220222 # This should still behave like the real thing, so that we can
221223 # verify that :py:class`AddressGenerator` is invoking the key
222224 # generator correctly.
223- return Hash (digests [key_index ]). as_trits () , key_index
225+ return Digest (digests [key_index ], key_index )
224226
225227
226228class MemoryAddressCacheTestCase (TestCase ):
0 commit comments