Пример #1
0
 def __str__(self) -> str:
     """Convert to string"""
     result = encode(self.bech32_hrp, self.bech32_witness_version, self)
     if result is None:
         raise AssertionError(
             'encode should not fail, this is data that '
             'was successfully decoded earlier')
     return result
Пример #2
0
    def test_encode_decode(self):
        for exp_bin, exp_bech32 in load_test_vectors(
                'bech32_encode_decode.json'):
            exp_bin = unhexlify(exp_bin.encode('utf8'))
            witver = self.op_decode(exp_bin[0])
            hrp = exp_bech32[:exp_bech32.rindex('1')].lower()
            self.assertEqual(exp_bin[1], len(exp_bin[2:]))
            act_bech32 = encode(hrp, witver, exp_bin[2:])
            act_bin = decode(hrp, exp_bech32)

            self.assertEqual(act_bech32.lower(), exp_bech32.lower())
            self.assertEqual(to_scriptPubKey(*act_bin), bytes(exp_bin))
Пример #3
0
    def test_encode_decode(self) -> None:
        for exp_bin_str, exp_bech32 in load_test_vectors('bech32_encode_decode.json'):
            exp_bin = unhexlify(exp_bin_str.encode('utf8'))
            witver = self.op_decode(exp_bin[0])
            hrp = exp_bech32[:exp_bech32.rindex('1')].lower()
            self.assertEqual(exp_bin[1], len(exp_bin[2:]))
            act_bech32 = encode(hrp, witver, exp_bin[2:])
            assert act_bech32 is not None
            act_bin = decode(hrp, exp_bech32)
            wv, wp = act_bin
            assert wv is not None
            assert wp is not None

            self.assertEqual(act_bech32.lower(), exp_bech32.lower())
            self.assertEqual(to_scriptPubKey(wv, wp), bytes(exp_bin))
Пример #4
0
 def __str__(self):
     """Convert to string"""
     return encode(bitcointx.params.BECH32_HRP, self.witver, self)
Пример #5
0
 def __str__(self):
     """Convert to string"""
     return encode(self.__class__.bech32_hrp, self.witver, self)