|
|
@ -5,6 +5,7 @@ |
|
|
|
"""Base class for RPC testing.""" |
|
|
|
"""Base class for RPC testing.""" |
|
|
|
|
|
|
|
|
|
|
|
from collections import deque |
|
|
|
from collections import deque |
|
|
|
|
|
|
|
from enum import Enum |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
import optparse |
|
|
|
import optparse |
|
|
|
import os |
|
|
|
import os |
|
|
@ -41,6 +42,15 @@ from .util import ( |
|
|
|
) |
|
|
|
) |
|
|
|
from .authproxy import JSONRPCException |
|
|
|
from .authproxy import JSONRPCException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestStatus(Enum): |
|
|
|
|
|
|
|
PASSED = 1 |
|
|
|
|
|
|
|
FAILED = 2 |
|
|
|
|
|
|
|
SKIPPED = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_EXIT_PASSED = 0 |
|
|
|
|
|
|
|
TEST_EXIT_FAILED = 1 |
|
|
|
|
|
|
|
TEST_EXIT_SKIPPED = 77 |
|
|
|
|
|
|
|
|
|
|
|
class BitcoinTestFramework(object): |
|
|
|
class BitcoinTestFramework(object): |
|
|
|
"""Base class for a bitcoin test script. |
|
|
|
"""Base class for a bitcoin test script. |
|
|
|
|
|
|
|
|
|
|
@ -57,11 +67,6 @@ class BitcoinTestFramework(object): |
|
|
|
This class also contains various public and private helper methods.""" |
|
|
|
This class also contains various public and private helper methods.""" |
|
|
|
|
|
|
|
|
|
|
|
# Methods to override in subclass test scripts. |
|
|
|
# Methods to override in subclass test scripts. |
|
|
|
|
|
|
|
|
|
|
|
TEST_EXIT_PASSED = 0 |
|
|
|
|
|
|
|
TEST_EXIT_FAILED = 1 |
|
|
|
|
|
|
|
TEST_EXIT_SKIPPED = 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
def __init__(self): |
|
|
|
self.num_nodes = 4 |
|
|
|
self.num_nodes = 4 |
|
|
|
self.setup_clean_chain = False |
|
|
|
self.setup_clean_chain = False |
|
|
@ -139,15 +144,18 @@ class BitcoinTestFramework(object): |
|
|
|
self.options.tmpdir = tempfile.mkdtemp(prefix="test") |
|
|
|
self.options.tmpdir = tempfile.mkdtemp(prefix="test") |
|
|
|
self._start_logging() |
|
|
|
self._start_logging() |
|
|
|
|
|
|
|
|
|
|
|
success = False |
|
|
|
success = TestStatus.FAILED |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
self.setup_chain() |
|
|
|
self.setup_chain() |
|
|
|
self.setup_network() |
|
|
|
self.setup_network() |
|
|
|
self.run_test() |
|
|
|
self.run_test() |
|
|
|
success = True |
|
|
|
success = TestStatus.PASSED |
|
|
|
except JSONRPCException as e: |
|
|
|
except JSONRPCException as e: |
|
|
|
self.log.exception("JSONRPC error") |
|
|
|
self.log.exception("JSONRPC error") |
|
|
|
|
|
|
|
except SkipTest as e: |
|
|
|
|
|
|
|
self.log.warning("Test Skipped: %s" % e.message) |
|
|
|
|
|
|
|
success = TestStatus.SKIPPED |
|
|
|
except AssertionError as e: |
|
|
|
except AssertionError as e: |
|
|
|
self.log.exception("Assertion failed") |
|
|
|
self.log.exception("Assertion failed") |
|
|
|
except KeyError as e: |
|
|
|
except KeyError as e: |
|
|
@ -159,11 +167,12 @@ class BitcoinTestFramework(object): |
|
|
|
|
|
|
|
|
|
|
|
if not self.options.noshutdown: |
|
|
|
if not self.options.noshutdown: |
|
|
|
self.log.info("Stopping nodes") |
|
|
|
self.log.info("Stopping nodes") |
|
|
|
self.stop_nodes() |
|
|
|
if self.nodes: |
|
|
|
|
|
|
|
self.stop_nodes() |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.log.info("Note: bitcoinds were not stopped and may still be running") |
|
|
|
self.log.info("Note: bitcoinds were not stopped and may still be running") |
|
|
|
|
|
|
|
|
|
|
|
if not self.options.nocleanup and not self.options.noshutdown and success: |
|
|
|
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED: |
|
|
|
self.log.info("Cleaning up") |
|
|
|
self.log.info("Cleaning up") |
|
|
|
shutil.rmtree(self.options.tmpdir) |
|
|
|
shutil.rmtree(self.options.tmpdir) |
|
|
|
else: |
|
|
|
else: |
|
|
@ -183,13 +192,17 @@ class BitcoinTestFramework(object): |
|
|
|
except OSError: |
|
|
|
except OSError: |
|
|
|
print("Opening file %s failed." % fn) |
|
|
|
print("Opening file %s failed." % fn) |
|
|
|
traceback.print_exc() |
|
|
|
traceback.print_exc() |
|
|
|
if success: |
|
|
|
|
|
|
|
|
|
|
|
if success == TestStatus.PASSED: |
|
|
|
self.log.info("Tests successful") |
|
|
|
self.log.info("Tests successful") |
|
|
|
sys.exit(self.TEST_EXIT_PASSED) |
|
|
|
sys.exit(TEST_EXIT_PASSED) |
|
|
|
|
|
|
|
elif success == TestStatus.SKIPPED: |
|
|
|
|
|
|
|
self.log.info("Test skipped") |
|
|
|
|
|
|
|
sys.exit(TEST_EXIT_SKIPPED) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir) |
|
|
|
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir) |
|
|
|
logging.shutdown() |
|
|
|
logging.shutdown() |
|
|
|
sys.exit(self.TEST_EXIT_FAILED) |
|
|
|
sys.exit(TEST_EXIT_FAILED) |
|
|
|
|
|
|
|
|
|
|
|
# Public helper methods. These can be accessed by the subclass test scripts. |
|
|
|
# Public helper methods. These can be accessed by the subclass test scripts. |
|
|
|
|
|
|
|
|
|
|
@ -346,6 +359,11 @@ class BitcoinTestFramework(object): |
|
|
|
# 2 binaries: 1 test binary, 1 ref binary |
|
|
|
# 2 binaries: 1 test binary, 1 ref binary |
|
|
|
# n>2 binaries: 1 test binary, n-1 ref binaries |
|
|
|
# n>2 binaries: 1 test binary, n-1 ref binaries |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SkipTest(Exception): |
|
|
|
|
|
|
|
"""This exception is raised to skip a test""" |
|
|
|
|
|
|
|
def __init__(self, message): |
|
|
|
|
|
|
|
self.message = message |
|
|
|
|
|
|
|
|
|
|
|
class ComparisonTestFramework(BitcoinTestFramework): |
|
|
|
class ComparisonTestFramework(BitcoinTestFramework): |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
def __init__(self): |
|
|
|