diff options
Diffstat (limited to 'qa')
-rwxr-xr-x | qa/rpc-tests/bip68-sequence.py | 19 | ||||
-rwxr-xr-x | qa/rpc-tests/import-rescan.py | 6 | ||||
-rwxr-xr-x | qa/rpc-tests/pruning.py | 4 | ||||
-rwxr-xr-x | qa/rpc-tests/segwit.py | 15 | ||||
-rw-r--r-- | qa/rpc-tests/test_framework/util.py | 44 | ||||
-rwxr-xr-x | qa/rpc-tests/wallet-hd.py | 7 |
6 files changed, 42 insertions, 53 deletions
diff --git a/qa/rpc-tests/bip68-sequence.py b/qa/rpc-tests/bip68-sequence.py index 74ac393fe9..e516ed2ec3 100755 --- a/qa/rpc-tests/bip68-sequence.py +++ b/qa/rpc-tests/bip68-sequence.py @@ -46,14 +46,12 @@ class BIP68Test(BitcoinTestFramework): print("Running test BIP68 not consensus before versionbits activation") self.test_bip68_not_consensus() - print("Verifying nVersion=2 transactions aren't standard") - self.test_version2_relay(before_activation=True) - print("Activating BIP68 (and 112/113)") self.activateCSV() - print("Verifying nVersion=2 transactions are now standard") - self.test_version2_relay(before_activation=False) + print("Verifying nVersion=2 transactions are standard.") + print("Note that with current versions of bitcoin software, nVersion=2 transactions are always standard (independent of BIP68 activation status).") + self.test_version2_relay() print("Passed\n") @@ -403,8 +401,8 @@ class BIP68Test(BitcoinTestFramework): assert(get_bip9_status(self.nodes[0], 'csv')['status'] == 'active') sync_blocks(self.nodes) - # Use self.nodes[1] to test standardness relay policy - def test_version2_relay(self, before_activation): + # Use self.nodes[1] to test that version 2 transactions are standard. + def test_version2_relay(self): inputs = [ ] outputs = { self.nodes[1].getnewaddress() : 1.0 } rawtx = self.nodes[1].createrawtransaction(inputs, outputs) @@ -412,12 +410,7 @@ class BIP68Test(BitcoinTestFramework): tx = FromHex(CTransaction(), rawtxfund) tx.nVersion = 2 tx_signed = self.nodes[1].signrawtransaction(ToHex(tx))["hex"] - try: - tx_id = self.nodes[1].sendrawtransaction(tx_signed) - assert(before_activation == False) - except: - assert(before_activation) - + tx_id = self.nodes[1].sendrawtransaction(tx_signed) if __name__ == '__main__': BIP68Test().main() diff --git a/qa/rpc-tests/import-rescan.py b/qa/rpc-tests/import-rescan.py index 7ca61824c9..64e0eec61e 100755 --- a/qa/rpc-tests/import-rescan.py +++ b/qa/rpc-tests/import-rescan.py @@ -56,7 +56,7 @@ class Variant(collections.namedtuple("Variant", "call data rescan prune")): "scriptPubKey": { "address": self.address["address"] }, - "timestamp": timestamp + RESCAN_WINDOW + (1 if self.rescan == Rescan.late_timestamp else 0), + "timestamp": timestamp + TIMESTAMP_WINDOW + (1 if self.rescan == Rescan.late_timestamp else 0), "pubkeys": [self.address["pubkey"]] if self.data == Data.pub else [], "keys": [self.key] if self.data == Data.priv else [], "label": self.label, @@ -108,7 +108,7 @@ ImportNode = collections.namedtuple("ImportNode", "prune rescan") IMPORT_NODES = [ImportNode(*fields) for fields in itertools.product((False, True), repeat=2)] # Rescans start at the earliest block up to 2 hours before the key timestamp. -RESCAN_WINDOW = 2 * 60 * 60 +TIMESTAMP_WINDOW = 2 * 60 * 60 class ImportRescanTest(BitcoinTestFramework): @@ -141,7 +141,7 @@ class ImportRescanTest(BitcoinTestFramework): self.nodes[0].generate(1) assert_equal(self.nodes[0].getrawmempool(), []) timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"] - set_node_times(self.nodes, timestamp + RESCAN_WINDOW + 1) + set_node_times(self.nodes, timestamp + TIMESTAMP_WINDOW + 1) self.nodes[0].generate(1) sync_blocks(self.nodes) diff --git a/qa/rpc-tests/pruning.py b/qa/rpc-tests/pruning.py index ace8ced422..d4924d058c 100755 --- a/qa/rpc-tests/pruning.py +++ b/qa/rpc-tests/pruning.py @@ -19,7 +19,7 @@ MIN_BLOCKS_TO_KEEP = 288 # Rescans start at the earliest block up to 2 hours before a key timestamp, so # the manual prune RPC avoids pruning blocks in the same window to be # compatible with pruning based on key creation time. -RESCAN_WINDOW = 2 * 60 * 60 +TIMESTAMP_WINDOW = 2 * 60 * 60 def calc_usage(blockdir): @@ -242,7 +242,7 @@ class PruneTest(BitcoinTestFramework): def height(index): if use_timestamp: - return node.getblockheader(node.getblockhash(index))["time"] + RESCAN_WINDOW + return node.getblockheader(node.getblockhash(index))["time"] + TIMESTAMP_WINDOW else: return index diff --git a/qa/rpc-tests/segwit.py b/qa/rpc-tests/segwit.py index f475427842..761c00dc01 100755 --- a/qa/rpc-tests/segwit.py +++ b/qa/rpc-tests/segwit.py @@ -248,20 +248,9 @@ class SegWitTest(BitcoinTestFramework): assert(tmpl['transactions'][0]['txid'] == txid) assert(tmpl['transactions'][0]['sigops'] == 8) - print("Verify non-segwit miners get a valid GBT response after the fork") + print("Non-segwit miners are not able to use GBT response after activation.") send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.998")) - try: - tmpl = self.nodes[0].getblocktemplate({}) - assert(len(tmpl['transactions']) == 1) # Doesn't include witness tx - assert(tmpl['sizelimit'] == 1000000) - assert('weightlimit' not in tmpl) - assert(tmpl['sigoplimit'] == 20000) - assert(tmpl['transactions'][0]['hash'] == txid) - assert(tmpl['transactions'][0]['sigops'] == 2) - assert(('!segwit' in tmpl['rules']) or ('segwit' not in tmpl['rules'])) - except JSONRPCException: - # This is an acceptable outcome - pass + assert_raises_jsonrpc(-8, "Support for 'segwit' rule requires explicit client support", self.nodes[0].getblocktemplate, {}) print("Verify behaviour of importaddress, addwitnessaddress and listunspent") diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index e838a40582..95619dda26 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -15,6 +15,7 @@ import http.client import random import shutil import subprocess +import tempfile import time import re import errno @@ -305,27 +306,7 @@ def initialize_chain_clean(test_dir, num_nodes): datadir=initialize_datadir(test_dir, i) -def _rpchost_to_args(rpchost): - '''Convert optional IP:port spec to rpcconnect/rpcport args''' - if rpchost is None: - return [] - - match = re.match('(\[[0-9a-fA-f:]+\]|[^:]+)(?::([0-9]+))?$', rpchost) - if not match: - raise ValueError('Invalid RPC host spec ' + rpchost) - - rpcconnect = match.group(1) - rpcport = match.group(2) - - if rpcconnect.startswith('['): # remove IPv6 [...] wrapping - rpcconnect = rpcconnect[1:-1] - - rv = ['-rpcconnect=' + rpcconnect] - if rpcport: - rv += ['-rpcport=' + rpcport] - return rv - -def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): +def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None): """ Start a bitcoind and return RPC connection to it """ @@ -334,7 +315,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= binary = os.getenv("BITCOIND", "bitcoind") args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ] if extra_args is not None: args.extend(extra_args) - bitcoind_processes[i] = subprocess.Popen(args) + bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr) if os.getenv("PYTHON_DEBUG", ""): print("start_node: bitcoind started, waiting for RPC to come up") url = rpc_url(i, rpchost) @@ -348,6 +329,25 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= return proxy +def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None): + with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr: + try: + node = start_node(i, dirname, extra_args, stderr=log_stderr) + stop_node(node, i) + except Exception as e: + assert 'bitcoind exited' in str(e) #node must have shutdown + if expected_msg is not None: + log_stderr.seek(0) + stderr = log_stderr.read().decode('utf-8') + if expected_msg not in stderr: + raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr) + else: + if expected_msg is None: + assert_msg = "bitcoind should have exited with an error" + else: + assert_msg = "bitcoind should have exited with expected error " + expected_msg + raise AssertionError(assert_msg) + def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): """ Start multiple bitcoinds, return RPC connections to them diff --git a/qa/rpc-tests/wallet-hd.py b/qa/rpc-tests/wallet-hd.py index bf07590098..1dcfe5300f 100755 --- a/qa/rpc-tests/wallet-hd.py +++ b/qa/rpc-tests/wallet-hd.py @@ -10,6 +10,7 @@ from test_framework.util import ( start_node, assert_equal, connect_nodes_bi, + assert_start_raises_init_error ) import os import shutil @@ -31,6 +32,12 @@ class WalletHDTest(BitcoinTestFramework): def run_test (self): tmpdir = self.options.tmpdir + # Make sure can't switch off usehd after wallet creation + self.stop_node(1) + assert_start_raises_init_error(1, self.options.tmpdir, ['-usehd=0'], 'already existing HD wallet') + self.nodes[1] = start_node(1, self.options.tmpdir, self.node_args[1]) + connect_nodes_bi(self.nodes, 0, 1) + # Make sure we use hd, keep masterkeyid masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] assert_equal(len(masterkeyid), 40) |