Skip to content

Commit fbeb8c4

Browse files
committed
test: add type annotations to util.get_rpc_proxy
Remove proxy.url assignment: error: "AuthServiceProxy" has no attribute "url"
1 parent 1488f55 commit fbeb8c4

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

test/functional/test_framework/coverage.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import os
1212

13+
from .authproxy import AuthServiceProxy
1314

1415
REFERENCE_FILENAME = 'rpc_interface.txt'
1516

@@ -19,24 +20,25 @@ class AuthServiceProxyWrapper():
1920
An object that wraps AuthServiceProxy to record specific RPC calls.
2021
2122
"""
22-
def __init__(self, auth_service_proxy_instance, coverage_logfile=None):
23+
def __init__(self, auth_service_proxy_instance: AuthServiceProxy, rpc_url: str, coverage_logfile: str=None):
2324
"""
2425
Kwargs:
25-
auth_service_proxy_instance (AuthServiceProxy): the instance
26-
being wrapped.
27-
coverage_logfile (str): if specified, write each service_name
26+
auth_service_proxy_instance: the instance being wrapped.
27+
rpc_url: url of the RPC instance being wrapped
28+
coverage_logfile: if specified, write each service_name
2829
out to a file when called.
2930
3031
"""
3132
self.auth_service_proxy_instance = auth_service_proxy_instance
33+
self.rpc_url = rpc_url
3234
self.coverage_logfile = coverage_logfile
3335

3436
def __getattr__(self, name):
3537
return_val = getattr(self.auth_service_proxy_instance, name)
3638
if not isinstance(return_val, type(self.auth_service_proxy_instance)):
3739
# If proxy getattr returned an unwrapped value, do the same here.
3840
return return_val
39-
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
41+
return AuthServiceProxyWrapper(return_val, self.rpc_url, self.coverage_logfile)
4042

4143
def __call__(self, *args, **kwargs):
4244
"""
@@ -57,6 +59,7 @@ def _log_call(self):
5759

5860
def __truediv__(self, relative_uri):
5961
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri,
62+
self.rpc_url,
6063
self.coverage_logfile)
6164

6265
def get_request(self, *args, **kwargs):
@@ -74,18 +77,18 @@ def get_filename(dirname, n_node):
7477
dirname, "coverage.pid%s.node%s.txt" % (pid, str(n_node)))
7578

7679

77-
def write_all_rpc_commands(dirname, node):
80+
def write_all_rpc_commands(dirname: str, node: AuthServiceProxy) -> bool:
7881
"""
7982
Write out a list of all RPC functions available in `bitcoin-cli` for
8083
coverage comparison. This will only happen once per coverage
8184
directory.
8285
8386
Args:
84-
dirname (str): temporary test dir
85-
node (AuthServiceProxy): client
87+
dirname: temporary test dir
88+
node: client
8689
8790
Returns:
88-
bool. if the RPC interface file was written.
91+
if the RPC interface file was written.
8992
9093
"""
9194
filename = os.path.join(dirname, REFERENCE_FILENAME)

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def wait_for_rpc_connection(self):
258258
return
259259
self.rpc = rpc
260260
self.rpc_connected = True
261-
self.url = self.rpc.url
261+
self.url = self.rpc.rpc_url
262262
return
263263
except JSONRPCException as e: # Initialization phase
264264
# -28 RPC in warmup

test/functional/test_framework/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ class PortSeed:
286286
n = None
287287

288288

289-
def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
289+
def get_rpc_proxy(url: str, node_number: int, *, timeout: int=None, coveragedir: str=None) -> coverage.AuthServiceProxyWrapper:
290290
"""
291291
Args:
292-
url (str): URL of the RPC server to call
293-
node_number (int): the node number (or id) that this calls to
292+
url: URL of the RPC server to call
293+
node_number: the node number (or id) that this calls to
294294
295295
Kwargs:
296-
timeout (int): HTTP timeout in seconds
297-
coveragedir (str): Directory
296+
timeout: HTTP timeout in seconds
297+
coveragedir: Directory
298298
299299
Returns:
300300
AuthServiceProxy. convenience object for making RPC calls.
@@ -305,11 +305,10 @@ def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
305305
proxy_kwargs['timeout'] = int(timeout)
306306

307307
proxy = AuthServiceProxy(url, **proxy_kwargs)
308-
proxy.url = url # store URL on proxy for info
309308

310309
coverage_logfile = coverage.get_filename(coveragedir, node_number) if coveragedir else None
311310

312-
return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile)
311+
return coverage.AuthServiceProxyWrapper(proxy, url, coverage_logfile)
313312

314313

315314
def p2p_port(n):

0 commit comments

Comments
 (0)