aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2020-06-11 13:42:37 -0400
committerJohn Newbery <john@johnnewbery.com>2020-09-03 16:47:46 +0100
commite4557133f595f357df5e16ae4f2f19c579631396 (patch)
tree6fbd169281e04a8a00866515a091ad4577f30421 /test/functional
parent68f0ab26bca825edf7e48a69176c38b04e3158d0 (diff)
downloadbitcoin-e4557133f595f357df5e16ae4f2f19c579631396.tar.xz
[tests] Move bech32 unit tests to test framework
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/test_framework/segwit_addr.py16
-rwxr-xr-xtest/functional/test_runner.py1
-rwxr-xr-xtest/functional/wallet_address_types.py13
3 files changed, 16 insertions, 14 deletions
diff --git a/test/functional/test_framework/segwit_addr.py b/test/functional/test_framework/segwit_addr.py
index 02368e938f..10d20eeda7 100644
--- a/test/functional/test_framework/segwit_addr.py
+++ b/test/functional/test_framework/segwit_addr.py
@@ -3,7 +3,7 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Reference implementation for Bech32 and segwit addresses."""
-
+import unittest
CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
@@ -105,3 +105,17 @@ def encode(hrp, witver, witprog):
if decode(hrp, ret) == (None, None):
return None
return ret
+
+class TestFrameworkScript(unittest.TestCase):
+ def test_segwit_encode_decode(self):
+ def test_python_bech32(addr):
+ hrp = addr[:4]
+ self.assertEqual(hrp, "bcrt")
+ (witver, witprog) = decode(hrp, addr)
+ self.assertEqual(encode(hrp, witver, witprog), addr)
+
+ # P2WPKH
+ test_python_bech32('bcrt1qthmht0k2qnh3wy7336z05lu2km7emzfpm3wg46')
+ # P2WSH
+ test_python_bech32('bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj')
+ test_python_bech32('bcrt1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsqseac85')
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 578afe5f30..933dd82c5a 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -71,6 +71,7 @@ TEST_FRAMEWORK_MODULES = [
"blocktools",
"muhash",
"script",
+ "segwit_addr",
"util",
]
diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py
index 68e22b7e86..bba0b8974d 100755
--- a/test/functional/wallet_address_types.py
+++ b/test/functional/wallet_address_types.py
@@ -64,10 +64,6 @@ from test_framework.util import (
assert_raises_rpc_error,
connect_nodes,
)
-from test_framework.segwit_addr import (
- encode,
- decode,
-)
class AddressTypeTest(BitcoinTestFramework):
def set_test_params(self):
@@ -101,13 +97,6 @@ class AddressTypeTest(BitcoinTestFramework):
"""Return a list of balances."""
return [self.nodes[i].getbalances()['mine'][key] for i in range(4)]
- # Quick test of python bech32 implementation
- def test_python_bech32(self, addr):
- hrp = addr[:4]
- assert_equal(hrp, "bcrt")
- (witver, witprog) = decode(hrp, addr)
- assert_equal(encode(hrp, witver, witprog), addr)
-
def test_address(self, node, address, multisig, typ):
"""Run sanity checks on an address."""
info = self.nodes[node].getaddressinfo(address)
@@ -132,7 +121,6 @@ class AddressTypeTest(BitcoinTestFramework):
assert_equal(info['witness_version'], 0)
assert_equal(len(info['witness_program']), 40)
assert 'pubkey' in info
- self.test_python_bech32(info["address"])
elif typ == 'legacy':
# P2SH-multisig
assert info['isscript']
@@ -158,7 +146,6 @@ class AddressTypeTest(BitcoinTestFramework):
assert_equal(info['witness_version'], 0)
assert_equal(len(info['witness_program']), 64)
assert 'pubkeys' in info
- self.test_python_bech32(info["address"])
else:
# Unknown type
assert False