From 779f4446803da63494a2f08480db7ea7f6d4b586 Mon Sep 17 00:00:00 2001 From: rkrux Date: Sat, 11 Apr 2026 12:46:35 +0530 Subject: [PATCH 1/2] test: move out JSONRPCException from authproxy to util So that util is not dependent on authproxy at all and going forward authproxy can use util methods. Reviewing with --color-moved=dimmed-zebra option can be helpful. --- test/functional/feature_index_prune.py | 2 +- test/functional/rpc_getblockfrompeer.py | 2 +- test/functional/rpc_misc.py | 3 +-- test/functional/test_framework/authproxy.py | 9 ++------- test/functional/test_framework/test_framework.py | 2 +- test/functional/test_framework/util.py | 7 ++++++- test/functional/wallet_importdescriptors.py | 2 +- test/functional/wallet_multiwallet.py | 2 +- test/functional/wallet_send.py | 2 +- test/functional/wallet_v3_txs.py | 2 +- 10 files changed, 16 insertions(+), 17 deletions(-) diff --git a/test/functional/feature_index_prune.py b/test/functional/feature_index_prune.py index ba4907acdcf..89c8acd4626 100755 --- a/test/functional/feature_index_prune.py +++ b/test/functional/feature_index_prune.py @@ -5,13 +5,13 @@ """Test indices in conjunction with prune.""" import concurrent.futures import os -from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework from test_framework.test_node import TestNode from test_framework.util import ( assert_equal, assert_greater_than, assert_raises_rpc_error, + JSONRPCException, ) from typing import List, Any diff --git a/test/functional/rpc_getblockfrompeer.py b/test/functional/rpc_getblockfrompeer.py index 9adcd88c9ee..f646abed01d 100755 --- a/test/functional/rpc_getblockfrompeer.py +++ b/test/functional/rpc_getblockfrompeer.py @@ -4,7 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the getblockfrompeer RPC.""" -from test_framework.authproxy import JSONRPCException from test_framework.messages import ( CBlock, from_hex, @@ -19,6 +18,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_raises_rpc_error, + JSONRPCException, ) diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py index 86f22f00399..6e4c908d306 100755 --- a/test/functional/rpc_misc.py +++ b/test/functional/rpc_misc.py @@ -11,10 +11,9 @@ from test_framework.util import ( assert_equal, assert_greater_than, assert_greater_than_or_equal, + JSONRPCException, ) -from test_framework.authproxy import JSONRPCException - import http import subprocess diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py index 078672c3c62..3d263a64f6c 100644 --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -44,18 +44,13 @@ import socket import time import urllib.parse +from .util import JSONRPCException + HTTP_TIMEOUT = 30 USER_AGENT = "AuthServiceProxy/0.1" log = logging.getLogger("BitcoinRPC") -class JSONRPCException(Exception): - def __init__(self, rpc_error, http_status=None): - super().__init__(f"{rpc_error} [http_status={http_status}]") - self.error = rpc_error - self.http_status = http_status - - def serialization_fallback(o): if isinstance(o, decimal.Decimal): return str(o) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 549e6ff65ce..ad75076dab4 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -22,7 +22,6 @@ import tempfile import time from .address import create_deterministic_address_bcrt1_p2tr_op_true -from .authproxy import JSONRPCException from . import coverage from .p2p import NetworkThread from .test_node import TestNode @@ -40,6 +39,7 @@ from .util import ( p2p_port, wait_until_helper_internal, wallet_importprivkey, + JSONRPCException, ) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index d225f18e740..ee8061fda09 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -20,7 +20,6 @@ import shlex import time import types -from .authproxy import JSONRPCException from .descriptors import descsum_create from collections.abc import Callable from typing import Optional, Union @@ -29,6 +28,12 @@ SATOSHI_PRECISION = Decimal('0.00000001') logger = logging.getLogger("TestFramework.utils") +class JSONRPCException(Exception): + def __init__(self, rpc_error, http_status=None): + super().__init__(f"{rpc_error} [http_status={http_status}]") + self.error = rpc_error + self.http_status = http_status + # Assert functions ################## diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py index 3e8b05a28d6..9a3a1802982 100755 --- a/test/functional/wallet_importdescriptors.py +++ b/test/functional/wallet_importdescriptors.py @@ -18,7 +18,6 @@ variants. import concurrent.futures import time -from test_framework.authproxy import JSONRPCException from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.descriptors import descsum_create @@ -26,6 +25,7 @@ from test_framework.script import SEQUENCE_LOCKTIME_TYPE_FLAG from test_framework.util import ( assert_equal, assert_raises_rpc_error, + JSONRPCException, ) from test_framework.wallet_util import ( get_generate_key, diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 4f855ee0cf9..db865281f74 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -12,7 +12,6 @@ import platform import shutil import stat -from test_framework.authproxy import JSONRPCException from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.test_node import ErrorMatch @@ -20,6 +19,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, ensure_for, + JSONRPCException, ) got_loading_error = False diff --git a/test/functional/wallet_send.py b/test/functional/wallet_send.py index ba98699039d..f3784778376 100755 --- a/test/functional/wallet_send.py +++ b/test/functional/wallet_send.py @@ -7,7 +7,6 @@ from decimal import Decimal, getcontext from itertools import product -from test_framework.authproxy import JSONRPCException from test_framework.descriptors import descsum_create from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -18,6 +17,7 @@ from test_framework.util import ( assert_greater_than_or_equal, assert_raises_rpc_error, count_bytes, + JSONRPCException, ) from test_framework.wallet_util import ( calculate_input_weight, diff --git a/test/functional/wallet_v3_txs.py b/test/functional/wallet_v3_txs.py index 18fa0d546b9..6ba30de4a3f 100755 --- a/test/functional/wallet_v3_txs.py +++ b/test/functional/wallet_v3_txs.py @@ -6,7 +6,6 @@ from decimal import Decimal, getcontext -from test_framework.authproxy import JSONRPCException from test_framework.messages import ( COIN, CTransaction, @@ -28,6 +27,7 @@ from test_framework.util import ( assert_equal, assert_greater_than, assert_raises_rpc_error, + JSONRPCException, ) from test_framework.mempool_util import ( From 7be0d6fa180e077c7108818fefb3c8553e2eeb74 Mon Sep 17 00:00:00 2001 From: rkrux Date: Fri, 24 Apr 2026 18:02:02 +0530 Subject: [PATCH 2/2] test: remove the lazy import of util in authproxy This lazy import prompted the removal of the circular dependency, so remove it now that we can. --- test/functional/test_framework/authproxy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py index 3d263a64f6c..0377414acce 100644 --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -44,7 +44,7 @@ import socket import time import urllib.parse -from .util import JSONRPCException +from .util import JSONRPCException, assert_equal HTTP_TIMEOUT = 30 USER_AGENT = "AuthServiceProxy/0.1" @@ -139,7 +139,6 @@ class AuthServiceProxy(): else: return response['result'] else: - from .util import assert_equal assert_equal(response['jsonrpc'], '2.0') if status != HTTPStatus.OK: raise JSONRPCException({