|
|
|
@ -2,7 +2,7 @@
@@ -2,7 +2,7 @@
|
|
|
|
|
# Copyright (c) 2017 The Bitcoin Core developers |
|
|
|
|
# Distributed under the MIT software license, see the accompanying |
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
|
|
|
|
"""Class for bitcoind node under test""" |
|
|
|
|
"""Class for litecoind node under test""" |
|
|
|
|
|
|
|
|
|
import decimal |
|
|
|
|
import errno |
|
|
|
@ -24,7 +24,7 @@ from .authproxy import JSONRPCException
@@ -24,7 +24,7 @@ from .authproxy import JSONRPCException
|
|
|
|
|
BITCOIND_PROC_WAIT_TIMEOUT = 60 |
|
|
|
|
|
|
|
|
|
class TestNode(): |
|
|
|
|
"""A class for representing a bitcoind node under test. |
|
|
|
|
"""A class for representing a litecoind node under test. |
|
|
|
|
|
|
|
|
|
This class contains: |
|
|
|
|
|
|
|
|
@ -45,7 +45,7 @@ class TestNode():
@@ -45,7 +45,7 @@ class TestNode():
|
|
|
|
|
# Wait for up to 60 seconds for the RPC server to respond |
|
|
|
|
self.rpc_timeout = 60 |
|
|
|
|
if binary is None: |
|
|
|
|
self.binary = os.getenv("BITCOIND", "bitcoind") |
|
|
|
|
self.binary = os.getenv("LITECOIND", "litecoind") |
|
|
|
|
else: |
|
|
|
|
self.binary = binary |
|
|
|
|
self.stderr = stderr |
|
|
|
@ -54,7 +54,7 @@ class TestNode():
@@ -54,7 +54,7 @@ class TestNode():
|
|
|
|
|
self.extra_args = extra_args |
|
|
|
|
self.args = [self.binary, "-datadir=" + self.datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(mocktime), "-uacomment=testnode%d" % i] |
|
|
|
|
|
|
|
|
|
self.cli = TestNodeCLI(os.getenv("BITCOINCLI", "bitcoin-cli"), self.datadir) |
|
|
|
|
self.cli = TestNodeCLI(os.getenv("LITECOINCLI", "litecoin-cli"), self.datadir) |
|
|
|
|
|
|
|
|
|
self.running = False |
|
|
|
|
self.process = None |
|
|
|
@ -76,14 +76,14 @@ class TestNode():
@@ -76,14 +76,14 @@ class TestNode():
|
|
|
|
|
stderr = self.stderr |
|
|
|
|
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr) |
|
|
|
|
self.running = True |
|
|
|
|
self.log.debug("bitcoind started, waiting for RPC to come up") |
|
|
|
|
self.log.debug("litecoind started, waiting for RPC to come up") |
|
|
|
|
|
|
|
|
|
def wait_for_rpc_connection(self): |
|
|
|
|
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" |
|
|
|
|
"""Sets up an RPC connection to the litecoind process. Returns False if unable to connect.""" |
|
|
|
|
# Poll at a rate of four times per second |
|
|
|
|
poll_per_s = 4 |
|
|
|
|
for _ in range(poll_per_s * self.rpc_timeout): |
|
|
|
|
assert self.process.poll() is None, "bitcoind exited with status %i during initialization" % self.process.returncode |
|
|
|
|
assert self.process.poll() is None, "litecoind exited with status %i during initialization" % self.process.returncode |
|
|
|
|
try: |
|
|
|
|
self.rpc = get_rpc_proxy(rpc_url(self.datadir, self.index, self.rpchost), self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir) |
|
|
|
|
self.rpc.getblockcount() |
|
|
|
@ -102,7 +102,7 @@ class TestNode():
@@ -102,7 +102,7 @@ class TestNode():
|
|
|
|
|
if "No RPC credentials" not in str(e): |
|
|
|
|
raise |
|
|
|
|
time.sleep(1.0 / poll_per_s) |
|
|
|
|
raise AssertionError("Unable to connect to bitcoind") |
|
|
|
|
raise AssertionError("Unable to connect to litecoind") |
|
|
|
|
|
|
|
|
|
def get_wallet_rpc(self, wallet_name): |
|
|
|
|
assert self.rpc_connected |
|
|
|
@ -146,13 +146,13 @@ class TestNode():
@@ -146,13 +146,13 @@ class TestNode():
|
|
|
|
|
def node_encrypt_wallet(self, passphrase): |
|
|
|
|
""""Encrypts the wallet. |
|
|
|
|
|
|
|
|
|
This causes bitcoind to shutdown, so this method takes |
|
|
|
|
This causes litecoind to shutdown, so this method takes |
|
|
|
|
care of cleaning up resources.""" |
|
|
|
|
self.encryptwallet(passphrase) |
|
|
|
|
self.wait_until_stopped() |
|
|
|
|
|
|
|
|
|
class TestNodeCLI(): |
|
|
|
|
"""Interface to bitcoin-cli for an individual node""" |
|
|
|
|
"""Interface to litecoin-cli for an individual node""" |
|
|
|
|
|
|
|
|
|
def __init__(self, binary, datadir): |
|
|
|
|
self.args = [] |
|
|
|
@ -161,7 +161,7 @@ class TestNodeCLI():
@@ -161,7 +161,7 @@ class TestNodeCLI():
|
|
|
|
|
self.input = None |
|
|
|
|
|
|
|
|
|
def __call__(self, *args, input=None): |
|
|
|
|
# TestNodeCLI is callable with bitcoin-cli command-line args |
|
|
|
|
# TestNodeCLI is callable with litecoin-cli command-line args |
|
|
|
|
self.args = [str(arg) for arg in args] |
|
|
|
|
self.input = input |
|
|
|
|
return self |
|
|
|
@ -172,11 +172,11 @@ class TestNodeCLI():
@@ -172,11 +172,11 @@ class TestNodeCLI():
|
|
|
|
|
return dispatcher |
|
|
|
|
|
|
|
|
|
def send_cli(self, command, *args, **kwargs): |
|
|
|
|
"""Run bitcoin-cli command. Deserializes returned string as python object.""" |
|
|
|
|
"""Run litecoin-cli command. Deserializes returned string as python object.""" |
|
|
|
|
|
|
|
|
|
pos_args = [str(arg) for arg in args] |
|
|
|
|
named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()] |
|
|
|
|
assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call" |
|
|
|
|
assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same litecoin-cli call" |
|
|
|
|
p_args = [self.binary, "-datadir=" + self.datadir] + self.args |
|
|
|
|
if named_args: |
|
|
|
|
p_args += ["-named"] |
|
|
|
|