diff --git a/package/test_tools/__private/base_node.py b/package/test_tools/__private/base_node.py index 0a5fd1ea6ef7feaeb0f88b43f4686340edf72986..404b68595f8fae859cd4e3a2e09a1d7567f21cb1 100644 --- a/package/test_tools/__private/base_node.py +++ b/package/test_tools/__private/base_node.py @@ -17,10 +17,13 @@ if TYPE_CHECKING: class BaseNode(UserHandleImplementation, Hived): def __init__(self, *, name: str, handle: NodeHandleBase | None = None) -> None: self.__name = context.names.register_numbered_name(name) - super().__init__(handle=handle, settings=Settings( - period_between_retries=timedelta(seconds=0.5), - max_retries=8, - )) + super().__init__( + handle=handle, + settings=Settings( + period_between_retries=timedelta(seconds=0.5), + max_retries=8, + ), + ) def __str__(self) -> str: return self.__name diff --git a/package/test_tools/__private/communication.py b/package/test_tools/__private/communication.py index 843be85b7e80cd93fbf8d36d9c217627dd3ceaee..ff666686d7ee288ecbb266e0941b1034e7ad36b7 100644 --- a/package/test_tools/__private/communication.py +++ b/package/test_tools/__private/communication.py @@ -13,9 +13,9 @@ from schemas.fields.assets import AssetBase from schemas.fields.json_string import JsonString from schemas._preconfigured_base_model import PreconfiguredBaseModel from schemas.operations.representations import LegacyRepresentation -from test_tools.__private.exceptions import CommunicationError +from helpy.exceptions import CommunicationError from loguru import logger -from helpy import Time +from helpy import HttpUrl, Time class CommonJsonEncoder(json.JSONEncoder): @@ -54,13 +54,12 @@ def __workaround_communication_problem_with_node(send_request: Callable) -> Call try: return send_request(*args, **kwargs) except CommunicationError as exception: - if ( - "Unable to acquire database lock" in exception.error - or "Unable to acquire forkdb lock" in exception.error + if "Unable to acquire database lock" in str(exception) or "Unable to acquire forkdb lock" in str( + exception ): message = str(args[1]) logger.debug( - f'Ignored "Unable to acquire {"database" if "database" in exception.error else "forkdb"} lock" error during sending request: {message}' + f'Ignored "Unable to acquire {"database" if "database" in str(exception) else "forkdb"} lock" error during sending request: {message}' ) continue @@ -100,7 +99,9 @@ def request(url: str, message: dict, use_nai_assets: bool = False, max_attempts= if "error" in response: logger.debug(f"Error in response from {url}: message={body}, response={response}") else: - raise CommunicationError(f"Unknown response format from {url}: ", body, response) + raise CommunicationError( + url=HttpUrl(url), request=body, response=f"Unknown response format from {url}: " + ) else: logger.debug( f"Received bad status code {status_code} != 200 from {url}, message={body}, response={response}" @@ -109,4 +110,4 @@ def request(url: str, message: dict, use_nai_assets: bool = False, max_attempts= if attempts_left > 0: time.sleep(seconds_between_attempts) - raise CommunicationError(body, decoded_content) + raise CommunicationError(url=HttpUrl(url), request=body, response=decoded_content) diff --git a/package/test_tools/__private/exceptions.py b/package/test_tools/__private/exceptions.py index 1c6d8685e014ce9949c9951226e9ef17075240c4..41eb935038670c4d69c84270efc0d66b42d4967f 100644 --- a/package/test_tools/__private/exceptions.py +++ b/package/test_tools/__private/exceptions.py @@ -1,7 +1,5 @@ from __future__ import annotations -from helpy.exceptions import RequestError - class TestToolsError(Exception): """Base exception class for test-tools package.""" @@ -11,9 +9,6 @@ class WalletError(TestToolsError): """Base exception class for Wallet.""" -CommunicationError = RequestError - - class InternalNodeError(TestToolsError): pass diff --git a/package/test_tools/__private/old_wallet.py b/package/test_tools/__private/old_wallet.py index a1a29ca2111e03c9ae9c06ab03213a6913a0bd6b..d505b6f5817ae4f70ed3778a7fead427dc63787e 100644 --- a/package/test_tools/__private/old_wallet.py +++ b/package/test_tools/__private/old_wallet.py @@ -19,7 +19,8 @@ from loguru import logger from test_tools.__private import communication, paths_to_executables from test_tools.__private.account import Account from helpy import Hf26Asset as Asset -from test_tools.__private.exceptions import CommunicationError, NodeIsNotRunningError +from test_tools.__private.exceptions import NodeIsNotRunningError +from helpy.exceptions import CommunicationError from test_tools.__private.node import Node from test_tools.__private.remote_node import RemoteNode from test_tools.__private.scope import ScopedObject, context diff --git a/package/test_tools/__private/wallet/wallet.py b/package/test_tools/__private/wallet/wallet.py index aad6eea0dd670fbbb97fc586fcf6ceaae8563791..165e0006855c37ffe836afa174d242c9f0acffaa 100644 --- a/package/test_tools/__private/wallet/wallet.py +++ b/package/test_tools/__private/wallet/wallet.py @@ -7,10 +7,10 @@ from typing import TYPE_CHECKING, Any, get_args from beekeepy import Beekeeper, Settings -import helpy import wax from helpy import Hf26Asset as Asset from helpy import wax as wax_helpy +from helpy.exceptions import ErrorInResponseError from schemas.fields.basic import PublicKey from schemas.fields.hex import Hex from schemas.fields.hive_int import HiveInt @@ -164,7 +164,7 @@ class Wallet(UserHandleImplementation, ScopedObject): self._beekeeper_wallet = self.__beekeeper_session.create_wallet(name=self.name, password=DEFAULT_PASSWORD) if preconfigure: self._beekeeper_wallet.import_key(private_key=Account("initminer").private_key) - except helpy.exceptions.RequestError as exception: + except ErrorInResponseError as exception: if f"Wallet with name: '{self.name}' already exists" in exception.error: locked_wallet = self.__beekeeper_session.open_wallet(name=self.name) self._beekeeper_wallet = locked_wallet.unlock(DEFAULT_PASSWORD) diff --git a/tests/functional_tests/beekeeper_wallet_tests/test_smoke.py b/tests/functional_tests/beekeeper_wallet_tests/test_smoke.py index 74484a8edb9164addc6ae7577528015a6c14a1b3..6089e7e9f31b30dcf6516b0afea62c625406099c 100644 --- a/tests/functional_tests/beekeeper_wallet_tests/test_smoke.py +++ b/tests/functional_tests/beekeeper_wallet_tests/test_smoke.py @@ -3,7 +3,7 @@ from __future__ import annotations import pytest import test_tools as tt -from helpy.exceptions import RequestError +from helpy.exceptions import ErrorInResponseError @pytest.fixture() @@ -55,7 +55,7 @@ def test_create_account_with_keys(wallet: tt.Wallet) -> None: def test_create_account_delegated(wallet: tt.Wallet) -> None: try: wallet.api.create_account_delegated("initminer", tt.Asset.Test(3), tt.Asset.Vest(6.123456), "alicex", "{}") - except RequestError as e: + except ErrorInResponseError as e: message = str(e) found = message.find("Account creation with delegation is deprecated as of Hardfork 20") assert found != -1 @@ -75,7 +75,7 @@ def test_create_account_with_keys_delegated(wallet: tt.Wallet) -> None: alice.public_key, alice.public_key, ) - except RequestError as e: + except ErrorInResponseError as e: message = str(e) found = message.find("Account creation with delegation is deprecated as of Hardfork 20") assert found != -1 diff --git a/tests/functional_tests/node_tests/test_node_api_errors.py b/tests/functional_tests/node_tests/test_node_api_errors.py index 00b24e03057e1872e4709fba929747fe761856d5..7f1bb13ac04a43ba371c92d3e00af1a0871e486a 100644 --- a/tests/functional_tests/node_tests/test_node_api_errors.py +++ b/tests/functional_tests/node_tests/test_node_api_errors.py @@ -4,12 +4,12 @@ from typing import TYPE_CHECKING import pytest -from helpy.exceptions import RequestError +from helpy.exceptions import ErrorInResponseError if TYPE_CHECKING: import test_tools as tt def test_if_raise_when_parameters_are_bad(node: tt.InitNode) -> None: - with pytest.raises(RequestError): + with pytest.raises(ErrorInResponseError): node.api.database.list_accounts(name=[]) # type: ignore[call-arg] diff --git a/tests/functional_tests/wallet_tests/test_wallet_api_errors.py b/tests/functional_tests/wallet_tests/test_wallet_api_errors.py index fa06d1e38bc035c6986cd532b14a3dd107218f5e..30052530d42edfcf7c734584ceaf8ca763db1060 100644 --- a/tests/functional_tests/wallet_tests/test_wallet_api_errors.py +++ b/tests/functional_tests/wallet_tests/test_wallet_api_errors.py @@ -4,6 +4,7 @@ import pytest import test_tools as tt from helpy import Hf26Asset as Asset +from helpy.exceptions import ErrorInResponseError @pytest.fixture() @@ -17,6 +18,6 @@ def test_if_raise_when_parameters_are_bad(wallet: tt.Wallet) -> None: def test_if_raise_when_operation_is_invalid(wallet: tt.Wallet) -> None: - with pytest.raises(tt.exceptions.CommunicationError): + with pytest.raises(ErrorInResponseError): # Operation is invalid because account "alice" doesn't exists wallet.api.transfer("initminer", "alice", Asset.Test(1), "memo")