pytest: Use the bitcoind config file to read RPC params from

With python-bitcoinlib==0.9.0 it appears that the URL based auth
information is no longer used, so we fall back to reading the config
file for the bitcoind daemon instead.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2017-12-22 15:17:22 +01:00
committed by Rusty Russell
parent 047a2ea043
commit 2a7ba010c3

View File

@@ -162,6 +162,7 @@ class TailableProc(object):
""" """
return self.wait_for_logs([regex], timeout) return self.wait_for_logs([regex], timeout)
class SimpleBitcoinProxy: class SimpleBitcoinProxy:
"""Wrapper for BitcoinProxy to reconnect. """Wrapper for BitcoinProxy to reconnect.
@@ -170,8 +171,8 @@ class SimpleBitcoinProxy:
throwaway connections. This is easier than to reach into the RPC throwaway connections. This is easier than to reach into the RPC
library to close, reopen and reauth upon failure. library to close, reopen and reauth upon failure.
""" """
def __init__(self, url): def __init__(self, btc_conf_file, *args, **kwargs):
self.url = url self.__btc_conf_file__= btc_conf_file
def __getattr__(self, name): def __getattr__(self, name):
if name.startswith('__') and name.endswith('__'): if name.startswith('__') and name.endswith('__'):
@@ -179,7 +180,9 @@ class SimpleBitcoinProxy:
raise AttributeError raise AttributeError
# Create a callable to do the actual call # Create a callable to do the actual call
f = lambda *args: BitcoinProxy(self.url)._call(name, *args) proxy = BitcoinProxy(btc_conf_file=self.__btc_conf_file__)
f = lambda *args: proxy._call(name, *args)
# Make debuggers show <function bitcoin.rpc.name> rather than <function # Make debuggers show <function bitcoin.rpc.name> rather than <function
# bitcoin.rpc.<lambda>> # bitcoin.rpc.<lambda>>
@@ -210,10 +213,10 @@ class BitcoinD(TailableProc):
'-nolisten', '-nolisten',
] ]
BITCOIND_CONFIG['rpcport'] = rpcport BITCOIND_CONFIG['rpcport'] = rpcport
btc_conf_file = os.path.join(regtestdir, 'bitcoin.conf')
write_config(os.path.join(bitcoin_dir, 'bitcoin.conf'), BITCOIND_CONFIG) write_config(os.path.join(bitcoin_dir, 'bitcoin.conf'), BITCOIND_CONFIG)
write_config(os.path.join(regtestdir, 'bitcoin.conf'), BITCOIND_CONFIG) write_config(btc_conf_file, BITCOIND_CONFIG)
self.rpc = SimpleBitcoinProxy( self.rpc = SimpleBitcoinProxy(btc_conf_file=btc_conf_file)
"http://rpcuser:rpcpass@127.0.0.1:{}".format(self.rpcport))
def start(self): def start(self):
TailableProc.start(self) TailableProc.start(self)