aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_framework')
-rw-r--r--test/functional/test_framework/address.py2
-rw-r--r--test/functional/test_framework/blocktools.py39
-rw-r--r--test/functional/test_framework/coverage.py2
-rwxr-xr-xtest/functional/test_framework/messages.py3
-rwxr-xr-xtest/functional/test_framework/mininode.py11
-rw-r--r--test/functional/test_framework/netutil.py2
-rw-r--r--test/functional/test_framework/script.py2
-rw-r--r--test/functional/test_framework/siphash.py2
-rw-r--r--test/functional/test_framework/socks5.py2
-rwxr-xr-xtest/functional/test_framework/test_framework.py52
-rwxr-xr-xtest/functional/test_framework/test_node.py15
-rw-r--r--test/functional/test_framework/util.py10
12 files changed, 88 insertions, 54 deletions
diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py
index b076c9dd43..d1fb97b024 100644
--- a/test/functional/test_framework/address.py
+++ b/test/functional/test_framework/address.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2016-2017 The Bitcoin Core developers
+# Copyright (c) 2016-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Encode and decode BASE58, P2PKH and P2SH addresses."""
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index 5c2b1815e5..56f70d9833 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2015-2017 The Bitcoin Core developers
+# Copyright (c) 2015-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for manipulating blocks and transactions."""
@@ -39,6 +39,7 @@ from .script import (
hash160,
)
from .util import assert_equal
+from io import BytesIO
# From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"
@@ -117,17 +118,43 @@ def create_coinbase(height, pubkey=None):
coinbase.calc_sha256()
return coinbase
-def create_transaction(prevtx, n, sig, value, script_pub_key=CScript()):
- """Create a transaction.
+def create_tx_with_script(prevtx, n, script_sig=b"", amount=1, script_pub_key=CScript()):
+ """Return one-input, one-output transaction object
+ spending the prevtx's n-th output with the given amount.
- If the script_pub_key is not specified, make it anyone-can-spend."""
+ Can optionally pass scriptPubKey and scriptSig, default is anyone-can-spend ouput.
+ """
tx = CTransaction()
assert(n < len(prevtx.vout))
- tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
- tx.vout.append(CTxOut(value, script_pub_key))
+ tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, 0xffffffff))
+ tx.vout.append(CTxOut(amount, script_pub_key))
tx.calc_sha256()
return tx
+def create_transaction(node, txid, to_address, amount):
+ """ Return signed transaction spending the first output of the
+ input txid. Note that the node must be able to sign for the
+ output that is being spent, and the node must not be running
+ multiple wallets.
+ """
+ raw_tx = create_raw_transaction(node, txid, to_address, amount)
+ tx = CTransaction()
+ tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
+ return tx
+
+def create_raw_transaction(node, txid, to_address, amount):
+ """ Return raw signed transaction spending the first output of the
+ input txid. Note that the node must be able to sign for the
+ output that is being spent, and the node must not be running
+ multiple wallets.
+ """
+ inputs = [{"txid": txid, "vout": 0}]
+ outputs = {to_address: amount}
+ rawtx = node.createrawtransaction(inputs, outputs)
+ signresult = node.signrawtransactionwithwallet(rawtx)
+ assert_equal(signresult["complete"], True)
+ return signresult['hex']
+
def get_legacy_sigopcount_block(block, accurate=True):
count = 0
for tx in block.vtx:
diff --git a/test/functional/test_framework/coverage.py b/test/functional/test_framework/coverage.py
index f8761f2bb3..7705dd3e4d 100644
--- a/test/functional/test_framework/coverage.py
+++ b/test/functional/test_framework/coverage.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2015-2017 The Bitcoin Core developers
+# Copyright (c) 2015-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for doing coverage analysis on the RPC interface.
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py
index af57e61f2f..7276f6b450 100755
--- a/test/functional/test_framework/messages.py
+++ b/test/functional/test_framework/messages.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Copyright (c) 2010 ArtForz -- public domain half-a-node
# Copyright (c) 2012 Jeff Garzik
-# Copyright (c) 2010-2017 The Bitcoin Core developers
+# Copyright (c) 2010-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Bitcoin test framework primitive and message structures
@@ -32,6 +32,7 @@ MY_SUBVERSION = b"/python-mininode-tester:0.0.3/"
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
MAX_INV_SZ = 50000
+MAX_LOCATOR_SZ = 101
MAX_BLOCK_BASE_SIZE = 1000000
COIN = 100000000 # 1 btc in satoshis
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index ccf767d357..ba37e17930 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Copyright (c) 2010 ArtForz -- public domain half-a-node
# Copyright (c) 2012 Jeff Garzik
-# Copyright (c) 2010-2017 The Bitcoin Core developers
+# Copyright (c) 2010-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Bitcoin P2P network half-a-node.
@@ -332,6 +332,15 @@ class P2PInterface(P2PConnection):
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
wait_until(test_function, timeout=timeout, lock=mininode_lock)
+ def wait_for_header(self, blockhash, timeout=60):
+ def test_function():
+ last_headers = self.last_message.get('headers')
+ if not last_headers:
+ return False
+ return last_headers.headers[0].rehash() == blockhash
+
+ wait_until(test_function, timeout=timeout, lock=mininode_lock)
+
def wait_for_getdata(self, timeout=60):
"""Waits for a getdata message.
diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py
index 36d1a2f856..5f1613d668 100644
--- a/test/functional/test_framework/netutil.py
+++ b/test/functional/test_framework/netutil.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2014-2017 The Bitcoin Core developers
+# Copyright (c) 2014-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Linux network utilities.
diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py
index 44650d7584..d1f605a2e0 100644
--- a/test/functional/test_framework/script.py
+++ b/test/functional/test_framework/script.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2015-2017 The Bitcoin Core developers
+# Copyright (c) 2015-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Functionality to build scripts, as well as SignatureHash().
diff --git a/test/functional/test_framework/siphash.py b/test/functional/test_framework/siphash.py
index 6ffc982cea..85836845d4 100644
--- a/test/functional/test_framework/siphash.py
+++ b/test/functional/test_framework/siphash.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2016-2017 The Bitcoin Core developers
+# Copyright (c) 2016-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Specialized SipHash-2-4 implementations.
diff --git a/test/functional/test_framework/socks5.py b/test/functional/test_framework/socks5.py
index 581de0ed5d..dd0f209268 100644
--- a/test/functional/test_framework/socks5.py
+++ b/test/functional/test_framework/socks5.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2015-2017 The Bitcoin Core developers
+# Copyright (c) 2015-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Dummy Socks5 server for testing."""
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index ebdf4d18fd..b876d9bd76 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2014-2017 The Bitcoin Core developers
+# Copyright (c) 2014-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Base class for RPC testing."""
@@ -7,7 +7,7 @@
import configparser
from enum import Enum
import logging
-import optparse
+import argparse
import os
import pdb
import shutil
@@ -96,31 +96,31 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
def main(self):
"""Main function. This should not be overridden by the subclass test scripts."""
- parser = optparse.OptionParser(usage="%prog [options]")
- parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
- help="Leave bitcoinds and test.* datadir on exit or error")
- parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true",
- help="Don't stop bitcoinds after the test execution")
- parser.add_option("--cachedir", dest="cachedir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
- help="Directory for caching pregenerated datadirs (default: %default)")
- parser.add_option("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
- parser.add_option("-l", "--loglevel", dest="loglevel", default="INFO",
- help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
- parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",
- help="Print out all RPC calls as they are made")
- parser.add_option("--portseed", dest="port_seed", default=os.getpid(), type='int',
- help="The seed to use for assigning port numbers (default: current process id)")
- parser.add_option("--coveragedir", dest="coveragedir",
- help="Write tested RPC commands into this directory")
- parser.add_option("--configfile", dest="configfile",
- default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
- help="Location of the test framework config file (default: %default)")
- parser.add_option("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
- help="Attach a python debugger if test fails")
- parser.add_option("--usecli", dest="usecli", default=False, action="store_true",
- help="use bitcoin-cli instead of RPC for all commands")
+ parser = argparse.ArgumentParser(usage="%(prog)s [options]")
+ parser.add_argument("--nocleanup", dest="nocleanup", default=False, action="store_true",
+ help="Leave bitcoinds and test.* datadir on exit or error")
+ parser.add_argument("--noshutdown", dest="noshutdown", default=False, action="store_true",
+ help="Don't stop bitcoinds after the test execution")
+ parser.add_argument("--cachedir", dest="cachedir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
+ help="Directory for caching pregenerated datadirs (default: %(default)s)")
+ parser.add_argument("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
+ parser.add_argument("-l", "--loglevel", dest="loglevel", default="INFO",
+ help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
+ parser.add_argument("--tracerpc", dest="trace_rpc", default=False, action="store_true",
+ help="Print out all RPC calls as they are made")
+ parser.add_argument("--portseed", dest="port_seed", default=os.getpid(), type=int,
+ help="The seed to use for assigning port numbers (default: current process id)")
+ parser.add_argument("--coveragedir", dest="coveragedir",
+ help="Write tested RPC commands into this directory")
+ parser.add_argument("--configfile", dest="configfile",
+ default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
+ help="Location of the test framework config file (default: %(default)s)")
+ parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
+ help="Attach a python debugger if test fails")
+ parser.add_argument("--usecli", dest="usecli", default=False, action="store_true",
+ help="use bitcoin-cli instead of RPC for all commands")
self.add_options(parser)
- (self.options, self.args) = parser.parse_args()
+ self.options = parser.parse_args()
PortSeed.n = self.options.port_seed
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 8ae7677f3b..0d00cc2082 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2017 The Bitcoin Core developers
+# Copyright (c) 2017-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Class for bitcoind node under test"""
@@ -122,7 +122,7 @@ class TestNode():
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
return getattr(self.rpc, name)
- def start(self, extra_args=None, stdout=None, stderr=None, *args, **kwargs):
+ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
"""Start the node."""
if extra_args is None:
extra_args = self.extra_args
@@ -143,7 +143,7 @@ class TestNode():
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
- self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, *args, **kwargs)
+ self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, **kwargs)
self.running = True
self.log.debug("bitcoind started, waiting for RPC to come up")
@@ -200,6 +200,9 @@ class TestNode():
if stderr != expected_stderr:
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
+ self.stdout.close()
+ self.stderr.close()
+
del self.p2ps[:]
def is_node_stopped(self):
@@ -276,7 +279,7 @@ class TestNode():
self.encryptwallet(passphrase)
self.wait_until_stopped()
- def add_p2p_connection(self, p2p_conn, *args, **kwargs):
+ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
"""Add a p2p connection to the node.
This method adds the p2p connection to the self.p2ps list and also
@@ -286,8 +289,10 @@ class TestNode():
if 'dstaddr' not in kwargs:
kwargs['dstaddr'] = '127.0.0.1'
- p2p_conn.peer_connect(*args, **kwargs)()
+ p2p_conn.peer_connect(**kwargs)()
self.p2ps.append(p2p_conn)
+ if wait_for_verack:
+ p2p_conn.wait_for_verack()
return p2p_conn
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 5e0b61b5e7..b355816d8b 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2014-2017 The Bitcoin Core developers
+# Copyright (c) 2014-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Helpful routines for regression testing."""
@@ -526,14 +526,6 @@ def gen_return_txouts():
txouts = txouts + script_pubkey
return txouts
-def create_tx(node, coinbase, to_address, amount):
- inputs = [{"txid": coinbase, "vout": 0}]
- outputs = {to_address: amount}
- rawtx = node.createrawtransaction(inputs, outputs)
- signresult = node.signrawtransactionwithwallet(rawtx)
- assert_equal(signresult["complete"], True)
- return signresult["hex"]
-
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
# transaction to make it large. See gen_return_txouts() above.
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):