From 931c5dc7cafaab3d91e68f3386806d1869ca9873 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 17 Oct 2022 18:37:24 +0000 Subject: [PATCH] rpc.py: minor fixes and cleanups --- mmgen/proto/btc/daemon.py | 4 ++++ mmgen/proto/btc/rpc.py | 8 +++----- test/unit_tests_d/ut_rpc.py | 4 ++-- test/unit_tests_d/ut_tx_deserialize.py | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mmgen/proto/btc/daemon.py b/mmgen/proto/btc/daemon.py index 8424a5c2..e3a2e2bc 100755 --- a/mmgen/proto/btc/daemon.py +++ b/mmgen/proto/btc/daemon.py @@ -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': diff --git a/mmgen/proto/btc/rpc.py b/mmgen/proto/btc/rpc.py index c2ef9b23..4e4122a8 100755 --- a/mmgen/proto/btc/rpc.py +++ b/mmgen/proto/btc/rpc.py @@ -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): diff --git a/test/unit_tests_d/ut_rpc.py b/test/unit_tests_d/ut_rpc.py index 91582a84..02a96772 100755 --- a/test/unit_tests_d/ut_rpc.py +++ b/test/unit_tests_d/ut_rpc.py @@ -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 diff --git a/test/unit_tests_d/ut_tx_deserialize.py b/test/unit_tests_d/ut_tx_deserialize.py index 8c732fee..3289f605 100755 --- a/test/unit_tests_d/ut_tx_deserialize.py +++ b/test/unit_tests_d/ut_tx_deserialize.py @@ -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('')