diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 64d187fc9e..c31a1c989d 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -2,7 +2,7 @@ # Copyright (c) 2017-2022 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 BGLd node under test""" +"""Class for bitcoind node under test""" import contextlib import decimal @@ -55,7 +55,7 @@ class ErrorMatch(Enum): class TestNode(): - """A class for representing a BGLd node under test. + """A class for representing a bitcoind node under test. This class contains: @@ -95,8 +95,8 @@ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor, # Note that common args are set in the config file (see initialize_datadir) self.extra_args = extra_args self.version = version - # Configuration for logging is set as command-line args rather than in the BGL.conf file. - # This means that starting a BGLd using the temp dir to debug a failed test won't + # Configuration for logging is set as command-line args rather than in the bitcoin.conf file. + # This means that starting a bitcoind using the temp dir to debug a failed test won't # spam debug.log. self.args = [ self.binary, @@ -200,7 +200,7 @@ def _raise_assertion_error(self, msg: str): raise AssertionError(self._node_msg(msg)) def __del__(self): - # Ensure that we don't leave any BGLd processes lying around after + # Ensure that we don't leave any bitcoind processes lying around after # the test ends if self.process and self.cleanup_on_exit: # Should only happen on test failure @@ -236,7 +236,7 @@ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None cwd = self.cwd # Delete any existing cookie file -- if such a file exists (eg due to - # unclean shutdown), it will get overwritten anyway by BGLd, and + # unclean shutdown), it will get overwritten anyway by bitcoind, and # potentially interfere with our attempt to authenticate delete_cookie_file(self.datadir_path, self.chain) @@ -254,7 +254,7 @@ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None self._start_perf() def wait_for_rpc_connection(self): - """Sets up an RPC connection to the BGLd process. Returns False if unable to connect.""" + """Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" # Poll at a rate of four times per second poll_per_s = 4 for _ in range(poll_per_s * self.rpc_timeout): @@ -319,11 +319,11 @@ def wait_for_rpc_connection(self): pass # Port not yet open? else: raise # unknown OS error - except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; BGLd is still starting + except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting if "No RPC credentials" not in str(e): raise time.sleep(1.0 / poll_per_s) - self._raise_assertion_error("Unable to connect to BGLd") + self._raise_assertion_error("Unable to connect to BGLd after {}s".format(self.rpc_timeout)) def wait_for_cookie_credentials(self): """Ensures auth cookie credentials can be read, e.g. for testing CLI with -rpcwait before RPC connection is up.""" @@ -335,7 +335,7 @@ def wait_for_cookie_credentials(self): get_auth_cookie(self.datadir_path, self.chain) self.log.debug("Cookie credentials successfully retrieved") return - except ValueError: # cookie file not found and no rpcuser or rpcpassword; BGLd is still starting + except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting pass # so we continue polling until RPC credentials are retrieved time.sleep(1.0 / poll_per_s) self._raise_assertion_error("Unable to retrieve cookie credentials after {}s".format(self.rpc_timeout)) @@ -635,11 +635,11 @@ def _stop_perf(self, profile_name): def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs): """Attempt to start the node and expect it to raise an error. - extra_args: extra arguments to pass through to BGLd - expected_msg: regex that stderr should match when BGLd fails + extra_args: extra arguments to pass through to bitcoind + expected_msg: regex that stderr should match when bitcoind fails - Will throw if BGLd starts without an error. - Will throw if an expected_msg is provided and it does not match BGLd's stdout.""" + Will throw if bitcoind starts without an error. + Will throw if an expected_msg is provided and it does not match bitcoind's stdout.""" assert not self.running with tempfile.NamedTemporaryFile(dir=self.stderr_dir, delete=False) as log_stderr, \ tempfile.NamedTemporaryFile(dir=self.stdout_dir, delete=False) as log_stdout: @@ -672,9 +672,9 @@ def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, mat self.process = None assert_msg = f'BGLd should have exited within {self.rpc_timeout}s ' if expected_msg is None: - assert_msg = "BGLd should have exited with an error" + assert_msg += "with an error" else: - assert_msg = "BGLd should have exited with expected error " + expected_msg + assert_msg += "with expected error " + expected_msg self._raise_assertion_error(assert_msg) def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=None, wait_for_v2_handshake=True, **kwargs): @@ -738,7 +738,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru def add_outbound_p2p_connection(self, p2p_conn, *, wait_for_verack=True, wait_for_disconnect=False, p2p_idx, connection_type="outbound-full-relay", supports_v2_p2p=None, advertise_v2_p2p=None, **kwargs): """Add an outbound p2p connection from node. Must be an - "outbound-full-relay", "block-relay-only" or "addr-fetch" connection. + "outbound-full-relay", "block-relay-only", "addr-fetch" or "feeler" connection. This method adds the p2p connection to the self.p2ps list and returns the connection to the caller. @@ -797,6 +797,7 @@ def addconnection_callback(address, port): if wait_for_verack: p2p_conn.wait_for_verack() p2p_conn.sync_with_ping() + return p2p_conn def num_test_p2p_connections(self): @@ -847,8 +848,7 @@ def arg_to_cli(arg): class TestNodeCLI(): - """Interface to BGL-cli for an individual node""" - + """Interface to bitcoin-cli for an individual node""" def __init__(self, binary, datadir): self.options = [] self.binary = binary @@ -857,7 +857,7 @@ def __init__(self, binary, datadir): self.log = logging.getLogger('TestFramework.BGLcli') def __call__(self, *options, input=None): - # TestNodeCLI is callable with BGL-cli command-line options + # TestNodeCLI is callable with bitcoin-cli command-line options cli = TestNodeCLI(self.binary, self.datadir) cli.options = [str(o) for o in options] cli.input = input @@ -876,7 +876,7 @@ def batch(self, requests): return results def send_cli(self, clicommand=None, *args, **kwargs): - """Run BGL-cli command. Deserializes returned string as python object.""" + """Run bitcoin-cli command. Deserializes returned string as python object.""" pos_args = [arg_to_cli(arg) for arg in args] named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()] p_args = [self.binary, f"-datadir={self.datadir}"] + self.options diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 08d898b586..f883dd7734 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -44,11 +44,11 @@ def assert_fee_amount(fee, tx_size, feerate_BGL_kvB): """Assert the fee is in range.""" assert isinstance(tx_size, int) target_fee = get_fee(tx_size, feerate_BGL_kvB) - feerate_BGL_vB = feerate_BGL_kvB / 1000 if fee < target_fee: raise AssertionError("Fee of %s BGL too low! (Should be %s BGL)" % (str(fee), str(target_fee))) # allow the wallet's estimation to be at most 2 bytes off - if fee > (tx_size + 2) * feerate_BGL_vB: + high_fee = get_fee(tx_size + 2, feerate_BGL_kvB) + if fee > high_fee: raise AssertionError("Fee of %s BGL too high! (Should be %s BGL)" % (str(fee), str(target_fee))) @@ -221,7 +221,7 @@ def assert_array_result(object_array, to_match, expected, should_not_find=False) def check_json_precision(): - """Make sure json library being used does not lose precision converting BGL values""" + """Make sure json library being used does not lose precision converting BTC values""" n = Decimal("20000000.00000003") satoshis = int(json.loads(json.dumps(float(n))) * 1.0e8) if satoshis != 2000000000000003: @@ -263,7 +263,7 @@ def wait_until_helper_internal(predicate, *, attempts=float('inf'), timeout=floa Warning: Note that this method is not recommended to be used in tests as it is not aware of the context of the test framework. Using the `wait_until()` members - from `BGLTestFramework` or `P2PInterface` class ensures the timeout is + from `BitcoinTestFramework` or `P2PInterface` class ensures the timeout is properly scaled. Furthermore, `wait_until()` from `P2PInterface` class in `p2p.py` has a preset lock. """ @@ -317,8 +317,7 @@ def sha256sum_file(filename): class PortSeed: # Must be initialized with a unique integer for each process - n = 0 # TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' - # Change from None to 0 + n = None def get_rpc_proxy(url: str, node_number: int, *, timeout: Optional[int]=None, coveragedir: Optional[str]=None) -> coverage.AuthServiceProxyWrapper: @@ -504,12 +503,12 @@ def check_node_connections(*, node, num_in, num_out): # Create large OP_RETURN txouts that can be appended to a transaction # to make it large (helper for constructing large transactions). The -# total serialized size of the txouts is about 6k vbytes. +# total serialized size of the txouts is about 66k vbytes. def gen_return_txouts(): from .messages import CTxOut from .script import CScript, OP_RETURN - txouts = [CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'\x01'*6743]))] - assert_equal(sum([len(txout.serialize()) for txout in txouts]), 6758) + txouts = [CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'\x01'*67437]))] + assert_equal(sum([len(txout.serialize()) for txout in txouts]), 67456) return txouts @@ -531,10 +530,11 @@ def create_lots_of_big_transactions(mini_wallet, node, fee, tx_batch_size, txout def mine_large_block(test_framework, mini_wallet, node): - # generate a large block with 16 transactions close to the 400kB block limit + # generate a 66k transaction, + # and 14 of them is close to the 1MB block limit txouts = gen_return_txouts() fee = 100 * node.getnetworkinfo()["relayfee"] - create_lots_of_big_transactions(mini_wallet, node, fee, 16, txouts) + create_lots_of_big_transactions(mini_wallet, node, fee, 14, txouts) test_framework.generate(node, 1)