Esempio n. 1
0
 def test_address_type(self):
     self.assertEqual(
         address_type('bc1qh2egksgfejqpktc3kkdtuqqrukrpzzp9lr0phn'),
         ADDRESS.P2WPKH)
     self.assertEqual(
         address_type(
             'bc1q8yh8l8ft3220q328hlapqhflpzy6xvkq6u36mctk8gq5pyxm3rwqv5h5dg'
         ), ADDRESS.P2WSH)
Esempio n. 2
0
 def test_address_type(self):
     self.assertEqual(address_type('mgxVT9fzHwYDsgEGJSZekKgYbAyrBkqdpi'),
                      ADDRESS.P2PKH)
     self.assertEqual(address_type('2MzAQDXGpmJyS6ybm2q57dbe8j2oxmvRDkc'),
                      ADDRESS.P2SH)
     self.assertEqual(address_type('n2NGrooSecJaiD6ssp4YqFoj9eZ7GrCJ66'),
                      ADDRESS.P2PKH)
     self.assertEqual(
         address_type('tb1q7w5dhw4hl5yvxvl3yvv2xxvh7jwm28p9kpelcp'),
         ADDRESS.P2WPKH)
Esempio n. 3
0
 def test_p2wpkh(self):
     """https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#examples"""
     pubkey = PublicKey.from_hex(
         '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798'
     )
     self.assertEqual(
         bech32.encode(self.hrp, self.witver,
                       hash160(pubkey.encode(compressed=True))),
         'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
     address = pubkey_to_address(pubkey, version='P2WPKH')
     self.assertEqual(address, 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
     self.assertEqual(address_type(address), ADDRESS.P2WPKH)
Esempio n. 4
0
 def test_p2wsh(self):
     """https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#examples"""
     pubkey = PublicKey.from_hex(
         '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798'
     )
     script = push(pubkey.encode(
         compressed=True)) + OP.CHECKSIG.byte  # <key> <OP_CHECKSIG>
     address = script_to_address(script, 'P2WSH')
     self.assertEqual(
         address,
         'bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3')
     self.assertEqual(address_type(address), ADDRESS.P2WSH)
Esempio n. 5
0
    def test_p2sh(self):
        script = secrets.token_bytes(32)
        scripthash = hash160(script)

        payload = {'RIPEMDWithHash': '05' + bytes_to_hex(scripthash)}
        data = urllib.parse.urlencode(payload).encode('ascii')
        req = urllib.request.Request(self.url, data)

        with urllib.request.urlopen(req) as response:
            html = HtmlLegacyAddress()
            html.feed(response.read().decode('utf-8'))

        address = html.address

        self.assertEqual(script_to_address(script, 'P2SH'), address)
        self.assertEqual(address_type(address), ADDRESS.P2SH)
Esempio n. 6
0
    def test_p2pkh(self):
        """https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#See_Also"""

        payload = {'Random': 'Random'}
        data = urllib.parse.urlencode(payload).encode('ascii')
        req = urllib.request.Request(self.url, data)

        with urllib.request.urlopen(req) as response:
            html = HtmlLegacyAddress()
            html.feed(response.read().decode('utf-8'))

        private, public, address = html.private, html.public, html.address

        my_pubkey = PrivateKey.from_hex(private).to_public()

        self.assertEqual(public.lower(), my_pubkey.hex())
        self.assertEqual(pubkey_to_address(my_pubkey), address)
        self.assertEqual(address_type(address), ADDRESS.P2PKH)
Esempio n. 7
0
 def test_address_type(self):
     self.assertEqual(address_type('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'),
                      ADDRESS.P2PKH)
     self.assertEqual(address_type('34eBzenHJEdk5PK9ojuuBZvCRtNhvvysYZ'),
                      ADDRESS.P2SH)