Auto merge of #4386 - oxarbitrage:issue4385, r=daira

add check_node_log utility function

Closes https://github.com/zcash/zcash/issues/4385
This commit is contained in:
Homu 2020-03-19 13:26:42 +00:00
commit c3df71a8e9
6 changed files with 85 additions and 58 deletions

View File

@ -82,6 +82,7 @@ testScripts=(
'sprout_sapling_migration.py'
'turnstile.py'
'mining_shielded_coinbase.py'
'framework.py'
);
testScriptsExt=(
'getblocktemplate_longpoll.py'

51
qa/rpc-tests/framework.py Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env python3
# Copyright (c) 2020 The Zcash developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_raises,
connect_nodes,
initialize_chain_clean,
start_node,
check_node_log,
)
class FrameworkTest (BitcoinTestFramework):
def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 4)
def start_node_with(self, index, extra_args=[]):
args = []
return start_node(index, self.options.tmpdir, args + extra_args)
def setup_network(self, split=False):
self.nodes = []
self.nodes.append(self.start_node_with(0))
self.nodes.append(self.start_node_with(1))
connect_nodes(self.nodes[1], 0)
self.is_network_split=False
self.sync_all()
def run_test (self):
# Test the check_node_log utility function
string_to_find = "Zcash version"
check_node_log(self, 1, string_to_find)
# Node 1 was stopped to check the logs, need to be restarted
self.nodes[1] = self.start_node_with(1, [])
connect_nodes(self.nodes[1], 0)
assert_raises(AssertionError, check_node_log, self, 1, "Will not be found")
# Need to start node 1 before leaving the test
self.nodes[1] = self.start_node_with(1, [])
connect_nodes(self.nodes[1], 0)
if __name__ == '__main__':
FrameworkTest().main()

View File

@ -14,6 +14,7 @@ from test_framework.util import (
initialize_chain_clean,
start_node,
wait_and_assert_operationid_status,
check_node_log,
)
class ShieldCoinbaseTest (BitcoinTestFramework):
@ -65,23 +66,11 @@ class ShieldCoinbaseTest (BitcoinTestFramework):
assert_equal(self.nodes[1].z_getbalance(node1_zaddr), 0)
# Stop node 1 and check logs to verify the block was rejected correctly
print("Checking node 1 logs")
self.nodes[1].stop()
bitcoind_processes[1].wait()
logpath = self.options.tmpdir + "/node1/regtest/debug.log"
foundErrorMsg = False
with open(logpath, "r") as myfile:
logdata = myfile.readlines()
for logline in logdata:
if "CheckTransaction(): coinbase has output descriptions" in logline:
foundErrorMsg = True
break
assert(foundErrorMsg)
string_to_find = "CheckTransaction(): coinbase has output descriptions"
check_node_log(self, 1, string_to_find)
# Restart node 1
self.nodes[1] = self.start_node_with(1, [
"-mineraddress=%s" % node1_zaddr,
])
self.nodes[1] = self.start_node_with(1, ["-mineraddress=%s" % node1_zaddr])
connect_nodes(self.nodes[1], 0)
# Activate Heartwood

View File

@ -494,3 +494,16 @@ def get_coinbase_address(node, expected_utxos=None):
addrs = [a for a in set(addrs) if addrs.count(a) == expected_utxos]
assert(len(addrs) > 0)
return addrs[0]
def check_node_log(self, node_number, line_to_check, stop_node = True):
print("Checking node " + str(node_number) + " logs")
if stop_node:
self.nodes[node_number].stop()
bitcoind_processes[node_number].wait()
logpath = self.options.tmpdir + "/node" + str(node_number) + "/regtest/debug.log"
with open(logpath, "r") as myfile:
logdata = myfile.readlines()
for (n, logline) in enumerate(logdata):
if line_to_check in logline:
return n
raise AssertionError(repr(line_to_check) + " not found")

View File

@ -34,7 +34,8 @@ from test_framework.util import (
sync_blocks, sync_mempools,
initialize_chain_clean, connect_nodes_bi,
wait_and_assert_operationid_status,
bitcoind_processes
bitcoind_processes,
check_node_log
)
from decimal import Decimal
@ -131,17 +132,8 @@ class TurnstileTest (BitcoinTestFramework):
assert_equal(block["height"], count + 1)
# Stop node 0 and check logs to verify the miner excluded the transaction from the block
self.nodes[0].stop()
bitcoind_processes[0].wait()
logpath = self.options.tmpdir + "/node0/regtest/debug.log"
foundErrorMsg = False
with open(logpath, "r") as myfile:
logdata = myfile.readlines()
for logline in logdata:
if "CreateNewBlock(): tx " + mytxid + " appears to violate " + POOL_NAME.capitalize() + " turnstile" in logline:
foundErrorMsg = True
break
assert(foundErrorMsg)
string_to_find = "CreateNewBlock(): tx " + mytxid + " appears to violate " + POOL_NAME.capitalize() + " turnstile"
check_node_log(self, 0, string_to_find)
# Launch node 0 with in-memory size of value pools set to zero.
self.start_and_sync_node(0, TURNSTILE_ARGS)
@ -171,25 +163,14 @@ class TurnstileTest (BitcoinTestFramework):
self.assert_pool_balance(self.nodes[2], POOL_NAME.lower(), Decimal('9'))
# Stop node 0 and check logs to verify the block was rejected as a turnstile violation
self.nodes[0].stop()
bitcoind_processes[0].wait()
logpath = self.options.tmpdir + "/node0/regtest/debug.log"
foundConnectBlockErrorMsg = False
foundInvalidBlockErrorMsg = False
foundConnectTipErrorMsg = False
with open(logpath, "r") as myfile:
logdata = myfile.readlines()
for logline in logdata:
if "ConnectBlock(): turnstile violation in " + POOL_NAME.capitalize() + " shielded value pool" in logline:
foundConnectBlockErrorMsg = True
elif "InvalidChainFound: invalid block=" + newhash in logline:
foundInvalidBlockErrorMsg = True
elif "ConnectTip(): ConnectBlock " + newhash + " failed" in logline:
foundConnectTipErrorMsg = True
assert(foundConnectBlockErrorMsg and foundInvalidBlockErrorMsg and foundConnectTipErrorMsg)
# Launch node 0 without overriding the pool size, so the node can sync with rest of network.
string_to_find1 = "ConnectBlock(): turnstile violation in " + POOL_NAME.capitalize() + " shielded value pool"
string_to_find2 = "InvalidChainFound: invalid block="
string_to_find3 = "ConnectTip(): ConnectBlock " + newhash + " failed"
check_node_log(self, 0, string_to_find1, True)
check_node_log(self, 0, string_to_find2, False)
check_node_log(self, 0, string_to_find3, False)
self.start_and_sync_node(0)
assert_equal(newhash, self.nodes[0].getbestblockhash())
if __name__ == '__main__':

View File

@ -8,7 +8,8 @@ from test_framework.authproxy import JSONRPCException
from test_framework.mininode import COIN
from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, \
wait_and_assert_operationid_status_result, get_coinbase_address
wait_and_assert_operationid_status_result, get_coinbase_address, \
check_node_log
import sys
import timeit
@ -153,18 +154,9 @@ class WalletShieldingCoinbaseTest (BitcoinTestFramework):
assert_equal("Invalid parameter, spending key for address does not belong to wallet" in errorString, True)
# Verify that debug=zrpcunsafe logs params, and that full txid is associated with opid
logpath = self.options.tmpdir+"/node0/regtest/debug.log"
logcounter = 0
with open(logpath, "r") as myfile:
logdata = myfile.readlines()
for logline in logdata:
if myopid + ": z_sendmany initialized" in logline and mytaddr in logline and myzaddr in logline:
assert_equal(logcounter, 0) # verify order of log messages
logcounter = logcounter + 1
if myopid + ": z_sendmany finished" in logline and mytxid in logline:
assert_equal(logcounter, 1)
logcounter = logcounter + 1
assert_equal(logcounter, 2)
initialized_line = check_node_log(self, 0, myopid + ": z_sendmany initialized", False)
finished_line = check_node_log(self, 0, myopid + ": z_sendmany finished", False)
assert(initialized_line < finished_line)
# check balances (the z_sendmany consumes 3 coinbase utxos)
resp = self.nodes[0].z_gettotalbalance()