Пример #1
0
    def test_get_addresses_single(self):
        """
    Generating a single address.
    """
        ag = AddressGenerator(self.seed_1)

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=0),
            [
                Address(
                    b'DLEIS9XU9V9T9OURAKDUSQWBQEYFGJLRPRVEWKN9'
                    b'SSUGIHBEIPBPEWISSAURGTQKWKWNHXGCBQTWNOGIY', ),
            ],
        )

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=10),
            [
                Address(
                    b'XLXFTFBXUOOHRJDVBDBFEBDQDUKSLSOCLUYWGLAP'
                    b'R9FUROUHPFINIUFKYSRTFMNWKNEPDZATWXIVWJMDD', ),
            ],
        )
Пример #2
0
    def test_get_addresses_error_step_zero(self):
        """
    Providing a ``step`` value of 0 to ``get_addresses``.
    """
        ag = AddressGenerator(seed=b'')

        with self.assertRaises(ValueError):
            ag.get_addresses(start=0, step=0)
Пример #3
0
    def test_get_addresses_error_start_too_small(self):
        """
    Providing a negative ``start`` value to ``get_addresses``.

    :py:class:`AddressGenerator` can potentially generate an infinite
    number of addresses, so there is no "end" to offset against.
    """
        ag = AddressGenerator(seed=b'')

        with self.assertRaises(ValueError):
            ag.get_addresses(start=-1)
Пример #4
0
    def test_get_addresses_multiple(self):
        """
    Generating multiple addresses in one go.
    """
        ag = AddressGenerator(self.seed_2)

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=0, count=3),
            [
                Address(
                    b'FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJ'
                    b'AFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY', ),
                Address(
                    b'MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQ'
                    b'LTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB', ),
                Address(
                    b'IIREHGHXUHARKVZDMHGUUCHZLUEQQULLEUSJHIIB'
                    b'WFYZIZDUFTOVHAWCKRJXUZ9CSUVLTRYSUGBVRMTOW', ),
            ],
        )

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=10, count=3),
            [
                Address(
                    b'BPXMVV9UPKBTVPJXPBHHOJYAFLALOYCGTSEDLZBH'
                    b'NFMGEHREBQTRIPZAPREANPMZJNZZNCDIUFOYYGGFY', ),
                Address(
                    b'RUCZQJWKXVDIXTLHHOKGMHOV9AKVDBG9HUQHPWNZ'
                    b'UNKJNFVMULUSLKFJGSTBSNJMRYSJOBVBQSKVXISZB', ),
                Address(
                    b'FQAKF9XVCLTBESJKWCHFOCTVABYEEJP9RXUVAEUW'
                    b'ENFUUQK9VCHFEORHCYDUJQHNUDWNRDUDZTUGKHSPD', ),
            ],
        )
Пример #5
0
    def test_get_addresses_step_negative(self):
        """
    Providing a negative ``step`` value to ``get_addresses``.

    This is probably a weird use case, but what the heck.
    """
        ag = AddressGenerator(self.seed_1)

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=1, count=2, step=-1),
            [
                Address(
                    b'PNLOTLFSALMICK9PSW9ZWLE9KJAKPKGJZQJDAFMO'
                    b'VLHXMJCJXFPVHOTTOYDIAUAYELXKZWZUITCQBIQKY', ),
                Address(
                    b'DLEIS9XU9V9T9OURAKDUSQWBQEYFGJLRPRVEWKN9'
                    b'SSUGIHBEIPBPEWISSAURGTQKWKWNHXGCBQTWNOGIY', ),
            ],
        )
Пример #6
0
    def test_security_level_elevated(self):
        """
    Generating addresses with a higher security level.
    """
        ag = AddressGenerator(self.seed_1, security_level=3)

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=0, count=3),
            [
                Address(
                    b'BGHTGOUKKNTYFHYUAAPSRUEVN9QQXFOGVCH9Y9BO'
                    b'NWXUBDLSKAWEOFZIVMHXBAYVPGDZEYCKNTUJCLPAX', ),
                Address(
                    b'EGMRJEUIYFUGWAIXXZCHCZUVUUYITICVHDSHCQXG'
                    b'FHJIVDCLTI9ZVRIKRLZQWW9CPOIXVDCBAHVGLUHI9', ),
                Address(
                    b'ENPSARVJZGMMPWZTAIRHADEOZCEVIFNJWSZQHNEI'
                    b'RVEVI9GYMFNEOGNUYCPGPSEFCSDHUHOQKDPVGDKYC', ),
            ],
        )
Пример #7
0
    def test_security_level_lowered(self):
        """
    Generating addresses with a lower security level.
    """
        ag = AddressGenerator(self.seed_1, security_level=1)

        # noinspection SpellCheckingInspection
        self.assertListEqual(
            ag.get_addresses(start=0, count=3),
            [
                Address(
                    b'KNDWDEEWWFVZLISLYRABGVWZCHZNZLNSEJXFKVGA'
                    b'UFLL9UMZYEZMEJB9BDLAASWTHEKFREUDIUPY9ICKW', ),
                Address(
                    b'CHOBTRTQWTMH9GWFWGWUODRSGPOJOIVJUNIQIBZL'
                    b'HSWNYPHOD9APWJBMJMGLHFZENWFKDYWHX9JDFXTAB', ),
                Address(
                    b'YHTOYQUCLDHAIDILFNPITVPYSTOCFAZIUNDYTRDZ'
                    b'CVMVGZPONPINNVPJTOAOKHHZWLOKIZPVASTOGAKPA', ),
            ],
        )
Пример #8
0
    async def _find_addresses(self, seed, index, count, security_level, checksum):
        # type: (Seed, int, Optional[int], int, bool) -> List[Address]
        """
        Find addresses matching the command parameters.
        """
        generator = AddressGenerator(seed, security_level, checksum)

        if count is None:
            # Connect to Tangle and find the first address without any
            # transactions.
            for addy in generator.create_iterator(start=index):
                # We use addy.address here because FindTransactions does
                # not work on an address with a checksum
                response = await FindTransactionsCommand(self.adapter)(
                    addresses=[addy.address],
                )

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

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