rpc.py: minor fixes and cleanups

This commit is contained in:
The MMGen Project 2022-10-17 18:37:24 +00:00
commit 931c5dc7ca
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 10 additions and 8 deletions

View file

@ -49,6 +49,10 @@ class bitcoin_core_daemon(CoinDaemon):
'regtest': 'regtest',
}[self.network] )
@property
def auth_cookie_fn(self):
return os.path.join(self.network_datadir,'.cookie')
def init_subclass(self):
if self.network == 'regtest':

View file

@ -89,7 +89,8 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
host = 'localhost' if g.test_suite else (g.rpc_host or 'localhost'),
port = daemon.rpc_port )
self.set_auth() # set_auth() requires cookie, so must be called after __init__() tests daemon is listening
self.set_auth()
await self.set_backend_async(backend) # backend requires self.auth
self.cached = {}
@ -212,9 +213,6 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
(os.path.dirname(g.data_dir) if self.proto.regtest else self.daemon.datadir),
self.daemon.cfg_file )
def get_daemon_auth_cookie_fn(self):
return os.path.join(self.daemon.network_datadir,'.cookie')
def get_daemon_cfg_options(self,req_keys):
fn = self.get_daemon_cfg_fn()
@ -238,7 +236,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
return dict(gen())
def get_daemon_auth_cookie(self):
fn = self.get_daemon_auth_cookie_fn()
fn = self.daemon.auth_cookie_fn
return get_lines_from_file(fn,'cookie',quiet=True)[0] if os.access(fn,os.R_OK) else ''
def info(self,info_id):

View file

@ -85,7 +85,7 @@ class init_test:
def run_test(network_ids,test_cf_auth=False,daemon_ids=None):
def do(d):
def do_test(d):
if not opt.no_daemon_stop:
d.stop()
@ -114,7 +114,7 @@ def run_test(network_ids,test_cf_auth=False,daemon_ids=None):
set(daemon_ids) & set(x) if daemon_ids else x
)(CoinDaemon.get_daemon_ids(proto.coin))
for daemon_id in ids:
do( CoinDaemon(proto=proto,test_suite=True,daemon_id=daemon_id) )
do_test( CoinDaemon(proto=proto,test_suite=True,daemon_id=daemon_id) )
return True

View file

@ -20,7 +20,7 @@ def print_info(name,extra_desc):
cyan(f'{name} ({extra_desc})'),
'' if opt.quiet else '\n'))
else:
Msg_r(f'Testing {extra_desc} transactions')
Msg_r(f'Testing {extra_desc}')
if not opt.quiet:
Msg('')