Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Enter your source directory between the quotes here
SOURCE_DIRECTORY = ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not strong on best practices for keeping user config values separate from other utility functions. Could keep as setup.py and somehow reference path from util.py, but could be awkward.

@jachiang jachiang Aug 30, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the only reason source dir path import and TestWrapper are consolidated in util.py is because I wanted to avoid to reference path from util.py, after setup.py sets source directory.


assert not SOURCE_DIRECTORY == '', 'SOURCE_DIRECTORY not configured'

print("Source directory configured as {}".format(SOURCE_DIRECTORY))

import sys
sys.path.insert(0, SOURCE_DIRECTORY + '/test/functional')

#############################################################################

import argparse
import os

from test_framework.test_framework import BitcoinTestFramework

# TestWrapper utility class.
class TestWrapper(BitcoinTestFramework):
"""Wrapper Class for BitcoinTestFramework.

Provides the BitcoinTestFramework rpc & daemon process management
functionality to external python projects."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might note here that the value of this class instead of just using BitcoinTestFramework is that weve provided a bunch of sane default settings as well as defaulting to setup 3 nodes. (at least that is my understanding of the raison d'etre for this class)

@jachiang jachiang Aug 30, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, BitcoinTestFramework sets defaults when reading command line arguments with argparse. Since we don't do that, we have to set the defaults in TestWrapper. Only when these options are set can we run the setup() and shutdown().


def set_test_params(self):
# This can be overriden in setup() parameter.
self.num_nodes=3

def run_test(self):
pass

def setup(self,
bitcoind=os.path.abspath(SOURCE_DIRECTORY + "/src/bitcoind"),
bitcoincli=None,
setup_clean_chain=True,
num_nodes=3,
network_thread=None,
rpc_timeout=60,
supports_cli=False,
bind_to_localhost_only=True,
nocleanup=False,
noshutdown=False,
cachedir=os.path.abspath(SOURCE_DIRECTORY + "/test/cache"),
tmpdir=None,
loglevel='INFO',
trace_rpc=False,
port_seed=os.getpid(),
coveragedir=None,
configfile=os.path.abspath(SOURCE_DIRECTORY + "/test/config.ini"),
pdbonfailure=False,
usecli = False,
perf = False,
randomseed = None):

self.setup_clean_chain = setup_clean_chain
self.num_nodes = num_nodes
self.network_thread = network_thread
self.rpc_timeout = rpc_timeout
self.supports_cli = supports_cli
self.bind_to_localhost_only = bind_to_localhost_only

self.options = argparse.Namespace
self.options.nocleanup = nocleanup
self.options.noshutdown = noshutdown
self.options.cachedir = cachedir
self.options.tmpdir = tmpdir
self.options.loglevel = loglevel
self.options.trace_rpc = trace_rpc
self.options.port_seed = port_seed
self.options.coveragedir = coveragedir
self.options.configfile = configfile
self.options.pdbonfailure = pdbonfailure
self.options.usecli = usecli
self.options.perf = perf
self.options.randomseed = randomseed

self.options.bitcoind = bitcoind
self.options.bitcoincli = bitcoincli

super(TestWrapper,self).setup()