aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework/address.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-10-17 16:02:09 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-10-17 16:02:30 +0200
commit09bc76de60b7f91b05b79a24b57f65b68f789b11 (patch)
treebe242fa610542d81903d797b1d68c9bd29ab1b47 /qa/rpc-tests/test_framework/address.py
parent4ed26277347c4b1c6d20d6ea913bb40d75eff810 (diff)
parent9777fe12722ddab7b1b17df11077d448c7a25006 (diff)
downloadbitcoin-09bc76de60b7f91b05b79a24b57f65b68f789b11.tar.xz
Merge #8916: 0.13.1 backports
9777fe1 remove redundant tests in p2p-segwit.py (Johnson Lau) fef7b46 test segwit uncompressed key fixes (Johnson Lau) 4ec21e8 Fix ismine and addwitnessaddress: no uncompressed keys in segwit (Pieter Wuille) 908fced [qa] Add tests for uncompressed pubkeys in segwit (Suhas Daftuar) b4b8527 Make test framework produce lowS signatures (Johnson Lau) 821f3e6 Require compressed keys in segwit as policy and disable signing with uncompressed keys for segwit scripts (Johnson Lau) 540413d Add standard limits for P2WSH with tests (Johnson Lau) 9bb2a02 [qa] Build v4 blocks in p2p-compactblocktests (Matt Corallo) df5069b [qa] Send segwit-encoded blocktxn messages in p2p-compactblocks (Matt Corallo) bcf3806 Update bitcoin-tx to output witness data. (jonnynewbs) cc6f551 [qa] Fix compact block shortids for a test case (Dagur Valberg Johannsson) 4bb9ce8 Use cmpctblock type 2 for segwit-enabled transfer (Matt Corallo) 890ac25 Fix overly-prescriptive p2p-segwit test for new fetch logic (Matt Corallo) fe1975a Use cmpctblock type 2 for segwit-enabled transfer (Pieter Wuille) 611cc50 [qa] Fix bug in mininode witness deserialization (Suhas Daftuar) 61e282b [qa] Add support for compactblocks v2 to mininode (Suhas Daftuar) e47299a [qa] Update p2p-compactblocks.py for compactblocks v2 (Suhas Daftuar) 7a34a46 Add NULLDUMMY verify flag in bitcoinconsensus.h (Johnson Lau) 7ae6242 net: fix a few cases where messages were sent rather than dropped upon disconnection (Cory Fields) 3e80ab7 Add policy: null signature for failed CHECK(MULTI)SIG (Johnson Lau) 0027672 Make non-minimal OP_IF/NOTIF argument non-standard for P2WSH (Johnson Lau)
Diffstat (limited to 'qa/rpc-tests/test_framework/address.py')
-rw-r--r--qa/rpc-tests/test_framework/address.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/qa/rpc-tests/test_framework/address.py b/qa/rpc-tests/test_framework/address.py
new file mode 100644
index 0000000000..50b999be61
--- /dev/null
+++ b/qa/rpc-tests/test_framework/address.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+# Copyright (c) 2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#
+# address.py
+#
+# This file encodes and decodes BASE58 P2PKH and P2SH addresses
+#
+
+from .script import hash256, hash160, sha256, CScript, OP_0
+from .util import bytes_to_hex_str, hex_str_to_bytes
+
+chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
+
+def byte_to_base58(b, version):
+ result = ''
+ str = bytes_to_hex_str(b)
+ str = bytes_to_hex_str(chr(version).encode('latin-1')) + str
+ checksum = bytes_to_hex_str(hash256(hex_str_to_bytes(str)))
+ str += checksum[:8]
+ value = int('0x'+str,0)
+ while value > 0:
+ result = chars[value % 58] + result
+ value //= 58
+ while (str[:2] == '00'):
+ result = chars[0] + result
+ str = str[2:]
+ return result
+
+# TODO: def base58_decode
+
+def keyhash_to_p2pkh(hash, main = False):
+ assert (len(hash) == 20)
+ version = 0 if main else 111
+ return byte_to_base58(hash, version)
+
+def scripthash_to_p2sh(hash, main = False):
+ assert (len(hash) == 20)
+ version = 5 if main else 196
+ return byte_to_base58(hash, version)
+
+def key_to_p2pkh(key, main = False):
+ key = check_key(key)
+ return keyhash_to_p2pkh(hash160(key), main)
+
+def script_to_p2sh(script, main = False):
+ script = check_script(script)
+ return scripthash_to_p2sh(hash160(script), main)
+
+def key_to_p2sh_p2wpkh(key, main = False):
+ key = check_key(key)
+ p2shscript = CScript([OP_0, hash160(key)])
+ return script_to_p2sh(p2shscript, main)
+
+def script_to_p2sh_p2wsh(script, main = False):
+ script = check_script(script)
+ p2shscript = CScript([OP_0, sha256(script)])
+ return script_to_p2sh(p2shscript, main)
+
+def check_key(key):
+ if (type(key) is str):
+ key = hex_str_to_bytes(key) # Assuming this is hex string
+ if (type(key) is bytes and (len(key) == 33 or len(key) == 65)):
+ return key
+ assert(False)
+
+def check_script(script):
+ if (type(script) is str):
+ script = hex_str_to_bytes(script) # Assuming this is hex string
+ if (type(script) is bytes or type(script) is CScript):
+ return script
+ assert(False)