Merge bitcoin/bitcoin#35049: test: remove circular dependency between authproxy and util

7be0d6fa18 test: remove the lazy import of util in authproxy (rkrux)
779f444680 test: move out JSONRPCException from authproxy to util (rkrux)

Pull request description:

  I noticed this issue while reviewing #34773 where a lazy import
  is added in the __call__ method of the AuthServiceProxy class in
  authproxy.py

  There's a circular dependency between authproxy.py and util.py
  due to which the former can't use the common utility functions
  and thus lazy imports are used as a workaround.

  This patch set breaks the dependency so that authproxy.py can use
  the utility functions from util.py in a standard fashion. Few tests that
  explicitly use get_rpc_proxy and JSONRPCException needed to have
  their imports updated.

ACKs for top commit:
  maflcko:
    review ACK 7be0d6fa18 🏽

Tree-SHA512: 56775cb13d989342ba9482edb255170d695ce5c2d5efbbd64586e0d5463af16467dbf9efe8a0411bde4dfb9bb531839284b2d6f5d828080171d847b70570977d
This commit is contained in:
merge-script
2026-05-26 09:41:43 +01:00
10 changed files with 16 additions and 18 deletions

View File

@@ -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

View File

@@ -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,
)

View File

@@ -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

View File

@@ -44,18 +44,13 @@ import socket
import time
import urllib.parse
from .util import JSONRPCException, assert_equal
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)
@@ -144,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({

View File

@@ -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,
)

View File

@@ -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
##################

View File

@@ -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,

View File

@@ -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

View File

@@ -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,

View File

@@ -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 (