Skip to content

Commit

Permalink
test: Adjust some Zcash RPC tests to work with parallel runner
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Nov 21, 2020
1 parent 01449d8 commit 891fbff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
3 changes: 2 additions & 1 deletion qa/rpc-tests/key_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from test_framework.util import assert_equal, assert_greater_than, start_nodes, connect_nodes_bi

import logging
import sys

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)


class KeyImportExportTest (BitcoinTestFramework):
Expand Down
49 changes: 36 additions & 13 deletions qa/rpc-tests/reorg_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
from test_framework.util import (
check_node,
connect_nodes_bi,
start_node,
sync_blocks,
)

import tempfile
from time import sleep

def check_stopped(i, timeout=10):
Expand All @@ -28,6 +31,17 @@ def check_stopped(i, timeout=10):

class ReorgLimitTest(BitcoinTestFramework):

def setup_nodes(self):
self.log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)

nodes = []
nodes.append(start_node(0, self.options.tmpdir, stderr=self.log_stderr))
nodes.append(start_node(1, self.options.tmpdir))
nodes.append(start_node(2, self.options.tmpdir))
nodes.append(start_node(3, self.options.tmpdir))

return nodes

def run_test(self):
assert(self.nodes[0].getblockcount() == 200)
assert(self.nodes[2].getblockcount() == 200)
Expand Down Expand Up @@ -66,19 +80,28 @@ def run_test(self):
assert(self.nodes[0].getblockcount() == 400)
assert(self.nodes[2].getblockcount() == 401)

print("Sync nodes to force a reorg")
connect_nodes_bi(self.nodes, 0, 2)
self.is_network_split = False
# sync_blocks uses RPC calls to wait for nodes to be synced, so don't
# call it here, because it will have a non-specific connection error
# when Node 0 stops. Instead, we explicitly check for the process itself
# to stop.

print("Check Node 0 is no longer running")
assert(check_stopped(0))

# Dummy stop to enable the test to tear down
self.nodes[0].stop = lambda: True
try:
print("Sync nodes to force a reorg")
connect_nodes_bi(self.nodes, 0, 2)
self.is_network_split = False
# sync_blocks uses RPC calls to wait for nodes to be synced, so don't
# call it here, because it will have a non-specific connection error
# when Node 0 stops. Instead, we explicitly check for the process itself
# to stop.

print("Check Node 0 is no longer running")
assert(check_stopped(0))

# Check that node 0 stopped for the expected reason.
self.log_stderr.seek(0)
stderr = self.log_stderr.read().decode('utf-8')
expected_msg = "A block chain reorganization has been detected that would roll back 100 blocks!"
if expected_msg not in stderr:
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
finally:
self.log_stderr.close()
# Dummy stop to enable the test to tear down
self.nodes[0].stop = lambda: True

if __name__ == '__main__':
ReorgLimitTest().main()
43 changes: 13 additions & 30 deletions qa/rpc-tests/sapling_rewind_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, assert_true,
assert_start_raises_init_error,
start_nodes, start_node, connect_nodes_bi,
bitcoind_processes,
nuparams, OVERWINTER_BRANCH_ID, SAPLING_BRANCH_ID)

import re
import logging
import sys

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)

HAS_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 15)]
NO_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 150)]
Expand Down Expand Up @@ -92,35 +95,15 @@ def run_test(self):

# Restart the nodes, reconnect, and sync the network. This succeeds if "-reindex" is passed.
logging.info("Reconnecting the network...")
try:
# expect an exception; the node will refuse to fully start because its last point of
# agreement with the rest of the network was prior to the network upgrade activation
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=HAS_SAPLING) # + ["-reindex"])
except:
logpath = self.options.tmpdir + "/node2/regtest/debug.log"
found = False
with open(logpath, 'r', encoding='utf8') as f:
for line in f:
# Search for the rollback message in the debug log, and ensure that it has the
# correct expected rollback length.
m = re.search(r'roll back ([0-9]+)', line)
if m is None:
continue
elif m.group(1) == "120":
found = True
break
else:
raise AssertionError("Incorrect rollback length %s found, expected 120." %(m.group(1)))

if not found:
raise AssertionError("Expected rollback message not found in log file.")

# restart the node with -reindex to allow the test to complete gracefully,
# otherwise the node shutdown call in test cleanup will throw an error since
# it can't connect
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=NO_SAPLING + ["-reindex"])
else:
raise AssertionError("Expected node to halt due to excessive rewind length.")

# expect an exception; the node will refuse to fully start because its last point of
# agreement with the rest of the network was prior to the network upgrade activation
assert_start_raises_init_error(2, self.options.tmpdir, HAS_SAPLING, "roll back 120")

# restart the node with -reindex to allow the test to complete gracefully,
# otherwise the node shutdown call in test cleanup will throw an error since
# it can't connect
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=NO_SAPLING + ["-reindex"])

if __name__ == '__main__':
SaplingRewindTest().main()
3 changes: 2 additions & 1 deletion qa/rpc-tests/zkey_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
initialize_chain_clean, connect_nodes_bi, wait_and_assert_operationid_status
from functools import reduce
import logging
import sys

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)

fee = Decimal('0.0001') # constant (but can be changed within reason)

Expand Down

0 comments on commit 891fbff

Please sign in to comment.