From 6ab97cbfca374b4582c590d1b87566babb890278 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 12 Jun 2020 23:50:03 -0500 Subject: [PATCH] Merge #14024: qa: Add TestNode::assert_debug_log fa3e9f7627 qa: Add TestNode::assert_debug_log (MarcoFalke) Pull request description: Closes #13006 Tree-SHA512: 8e2d2331039d70525a425aad65a4eaf9b83fb1f85a4260d69453176f04dbede6dd9b7bb4d5f089b46cf8f8c98571aa6ba7fac8fa6847bb3bdf6a6ad21a27b1a7 --- test/functional/invalidtxrequest.py | 9 +++++++-- test/functional/test_framework/test_node.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/functional/invalidtxrequest.py b/test/functional/invalidtxrequest.py index ff7ec4e29f..ea597790d6 100755 --- a/test/functional/invalidtxrequest.py +++ b/test/functional/invalidtxrequest.py @@ -96,9 +96,13 @@ class InvalidTxRequestTest(BitcoinTestFramework): # restart node with sending BIP61 messages disabled, check that it disconnects without sending the reject message self.log.info('Test a transaction that is rejected, with BIP61 disabled') - self.restart_node(0, ['-enablebip61=0','-persistmempool=0']) + self.restart_node(0, ['-enablebip61=0', '-persistmempool=0']) self.reconnect_p2p(num_connections=1) - node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True) + with node.assert_debug_log(expected_msgs=[ + "{} from peer=0 was not accepted: mandatory-script-verify-flag-failed (Invalid OP_IF construction) (code 16)".format(tx1.hash), + "disconnecting peer=0", + ]): + node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True) # send_txs_and_test will have waited for disconnect, so we can safely check that no reject has been received assert_equal(node.p2p.reject_code_received, None) @@ -181,5 +185,6 @@ class InvalidTxRequestTest(BitcoinTestFramework): assert_equal(expected_mempool, set(node.getrawmempool())) + if __name__ == '__main__': InvalidTxRequestTest().main() diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 82d697ef26..9347e5fb5e 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Class for dashd node under test""" +import contextlib import decimal import errno import http.client @@ -187,6 +188,23 @@ class TestNode(): def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): wait_until(self.is_node_stopped, timeout=timeout) + @contextlib.contextmanager + def assert_debug_log(self, expected_msgs): + debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') + with open(debug_log, encoding='utf-8') as dl: + dl.seek(0, 2) + prev_size = dl.tell() + try: + yield + finally: + with open(debug_log, encoding='utf-8') as dl: + dl.seek(prev_size) + log = dl.read() + print_log = " - " + "\n - ".join(log.splitlines()) + for expected_msg in expected_msgs: + if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None: + self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) + def node_encrypt_wallet(self, passphrase): """"Encrypts the wallet.