Exemplo n.º 1
0
    def test_generator_with_offset(self):
        """
    Creating a generator that starts at an offset greater than 0.
    """
        # Seed is not important for this test; it is only used by
        # :py:class:`KeyGenerator`, which we will mock in this test.
        ag = AddressGenerator(seed=b'')

        # noinspection PyUnresolvedReferences
        with patch.object(ag, '_get_digest', self._mock_get_digest):
            generator = ag.create_iterator(start=1, step=2)

            self.assertEqual(next(generator), self.addy1)
            self.assertEqual(next(generator), self.addy3)
Exemplo n.º 2
0
    def _find_addresses(self, seed, index, count):
        """
    Find addresses matching the command parameters.
    """
        # type: (Seed, int, Optional[int]) -> List[Address]
        generator = AddressGenerator(seed)

        if count is None:
            # Connect to Tangle and find the first address without any
            # transactions.
            for addy in generator.create_iterator(start=index):
                response = FindTransactionsCommand(
                    self.adapter)(addresses=[addy])

                if not response.get('hashes'):
                    return [addy]

        return generator.get_addresses(start=index, count=count)