diff --git a/tests/beekeepy_test/interface/test_errors/__init__.py b/tests/beekeepy_test/interface/test_errors/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/beekeepy_test/interface/test_errors/conftest.py b/tests/beekeepy_test/interface/test_errors/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..8bd6d38e3c87275ab4e5180d8783a946eb05f210 --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/conftest.py @@ -0,0 +1,40 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy import Beekeeper + +if TYPE_CHECKING: + from typing import Iterator + + from local_tools.beekeepy.models import SettingsFactory + + from beekeepy import Session, UnlockedWallet, Wallet + + +@pytest.fixture() +def beekeeper(settings: SettingsFactory) -> Iterator[Beekeeper]: + with Beekeeper.factory(settings=settings()) as bk: + yield bk + + +@pytest.fixture() +def session(beekeeper: Beekeeper) -> Iterator[Session]: + with beekeeper.create_session() as ss: + yield ss + + +@pytest.fixture() +def wallet(session: Session) -> Wallet: + with session.create_wallet(name="wallet", password="wallet"): # noqa: S106 + pass + + return session.open_wallet(name="wallet") + + +@pytest.fixture() +def unlocked_wallet(wallet: Wallet) -> Iterator[UnlockedWallet]: + with wallet.unlock(password="wallet") as uw: # noqa: S106 + yield uw diff --git a/tests/beekeepy_test/interface/test_errors/test_invalid_password.py b/tests/beekeepy_test/interface/test_errors/test_invalid_password.py new file mode 100644 index 0000000000000000000000000000000000000000..e9641f4b7e117268c8fecfb53b95fe7fa0fce5fe --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_invalid_password.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions.detectable import InvalidPasswordError +from helpy.exceptions import InvalidPasswordError as HelpyInvalidPasswordError + +if TYPE_CHECKING: + from beekeepy import Wallet + + +def test_basic_detection() -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidPasswordError), InvalidPasswordError(wallet_name="wallet"): + raise HelpyInvalidPasswordError( + url="", + request="", + request_id=None, + ) + + +def test_test_invalid_private_key(wallet: Wallet) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidPasswordError): + wallet.unlock(password="invalid") # noqa: S106 diff --git a/tests/beekeepy_test/interface/test_errors/test_invalid_private_key.py b/tests/beekeepy_test/interface/test_errors/test_invalid_private_key.py new file mode 100644 index 0000000000000000000000000000000000000000..e1207a0716c4c986a8993e788f481aa7a76f8a6a --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_invalid_private_key.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions.detectable import InvalidPrivateKeyError +from helpy.exceptions import ErrorInResponseError + +if TYPE_CHECKING: + from beekeepy import UnlockedWallet + + +def test_basic_detection() -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidPrivateKeyError), InvalidPrivateKeyError(wifs="aaa"): + raise ErrorInResponseError( + url="", + request="", + request_id=None, + response="Assert Exception:false: Key can't be constructed", + ) + + +def test_invalid_private_key(unlocked_wallet: UnlockedWallet) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidPrivateKeyError): + unlocked_wallet.import_key(private_key="key" * 17) diff --git a/tests/beekeepy_test/interface/test_errors/test_invalid_wallet.py b/tests/beekeepy_test/interface/test_errors/test_invalid_wallet.py new file mode 100644 index 0000000000000000000000000000000000000000..4cd7f997cd17616b1dd8ef7d457b9a399a5baf4f --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_invalid_wallet.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions.detectable import InvalidWalletError +from helpy.exceptions import ErrorInResponseError + +if TYPE_CHECKING: + from beekeepy import Session + + +@pytest.mark.parametrize( + "message", + [ + "Name of wallet is incorrect. Is empty.", + "Name of wallet is incorrect. Name: #####. Only alphanumeric and '._-@' chars are allowed", + "Name of wallet is incorrect. Name: #####. File creation with given name is impossible.", + ], + ids=[1, 2, 3], +) +def test_basic_detection(message: str) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidWalletError), InvalidWalletError(wallet_name="#####"): + raise ErrorInResponseError( + url="", + request="", + request_id=None, + response=message, + ) + + +def test_not_existing_key(session: Session) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(InvalidWalletError): + session.create_wallet(name="####", password="wallet") # noqa: S106 diff --git a/tests/beekeepy_test/interface/test_errors/test_missing_stm_prefix.py b/tests/beekeepy_test/interface/test_errors/test_missing_stm_prefix.py new file mode 100644 index 0000000000000000000000000000000000000000..0f67e86e71d37013cee473d03a62ace8e62badce --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_missing_stm_prefix.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +import pytest + +from beekeepy.exceptions.detectable import MissingSTMPrefixError +from helpy.exceptions import ErrorInResponseError + + +def test_basic_detection() -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(MissingSTMPrefixError), MissingSTMPrefixError( + public_key="8Ya14mz5HiZ3JiEhoad4uoSjuK17fMJgJVVuY4991qrf6tbNdH" + ): + raise ErrorInResponseError( + url="", + request="", + request_id=None, + response=( + "Assert Exception:source.substr( 0, prefix.size() ) == prefix: " + "public key requires STM prefix, but was given " + "`8Ya14mz5HiZ3JiEhoad4uoSjuK17fMJgJVVuY4991qrf6tbNdH`" + ), + ) diff --git a/tests/beekeepy_test/interface/test_errors/test_no_wallet_with_such_name.py b/tests/beekeepy_test/interface/test_errors/test_no_wallet_with_such_name.py new file mode 100644 index 0000000000000000000000000000000000000000..879a467bcf0a3088c274770ca60012f7f2d51a41 --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_no_wallet_with_such_name.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions.detectable import NoWalletWithSuchNameError +from helpy.exceptions import UnableToOpenWalletError + +if TYPE_CHECKING: + from beekeepy import Session + + +def test_basic_detection() -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(NoWalletWithSuchNameError), NoWalletWithSuchNameError(wallet_name="some-wallet"): + raise UnableToOpenWalletError(url="", request="", request_id=None) + + +def test_no_wallet_with_such_name(session: Session) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(NoWalletWithSuchNameError): + session.open_wallet(name="not-existing") diff --git a/tests/beekeepy_test/interface/test_errors/test_not_existing_key.py b/tests/beekeepy_test/interface/test_errors/test_not_existing_key.py new file mode 100644 index 0000000000000000000000000000000000000000..1defc198ac1f79c1c4d623c93561263c01e8e7a7 --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_not_existing_key.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions.detectable import NotExistingKeyError +from helpy.exceptions import ErrorInResponseError + +if TYPE_CHECKING: + from beekeepy import Session, UnlockedWallet + + +@pytest.mark.parametrize("wallet_name", ["wallet", None]) +@pytest.mark.parametrize( + "message", + ["Assert Exception:false: Key not in wallet", "Assert Exception:false: Public key aaa not found in wallet wallet"], +) +def test_basic_detection(message: str, wallet_name: str | None) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(NotExistingKeyError), NotExistingKeyError(public_key="aaa", wallet_name=wallet_name): + raise ErrorInResponseError( + url="", + request="", + request_id=None, + response=message, + ) + + +def test_not_existing_key(session: Session, unlocked_wallet: UnlockedWallet) -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(NotExistingKeyError): + unlocked_wallet.sign_digest(sig_digest="aaa", key="STM8Ya14mz5HiZ3JiEhoad4uoSjuK17fMJgJVVuY4991qrf6tbNdH") + + with pytest.raises(NotExistingKeyError): + session.sign_digest(sig_digest="aaa", key="STM8Ya14mz5HiZ3JiEhoad4uoSjuK17fMJgJVVuY4991qrf6tbNdH") diff --git a/tests/beekeepy_test/interface/test_errors/test_wallet_with_such_name_already_exists.py b/tests/beekeepy_test/interface/test_errors/test_wallet_with_such_name_already_exists.py new file mode 100644 index 0000000000000000000000000000000000000000..6a5a13aedcdb4d2d1feb9c39158dd6b5435a6b4b --- /dev/null +++ b/tests/beekeepy_test/interface/test_errors/test_wallet_with_such_name_already_exists.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from beekeepy.exceptions import WalletWithSuchNameAlreadyExistsError +from helpy.exceptions import ErrorInResponseError + +if TYPE_CHECKING: + from beekeepy import Session + + +def test_basic_detection() -> None: + # ARRANGE, ACT & ASSERT + with pytest.raises(WalletWithSuchNameAlreadyExistsError), WalletWithSuchNameAlreadyExistsError(wallet_name="aaa"): + raise ErrorInResponseError( + url="", + request="", + request_id=None, + response=( + "Assert Exception:!fc::exists( wallet_file_name ): " + "Wallet with name: 'aaa' already exists at /some/path/to/aaa.wallet" + ), + ) + + +def test_wallet_with_such_name_already_exists(session: Session) -> None: + # ARRANGE + session.create_wallet(name="aaa", password="wallet") # noqa: S106 + + # ACT & ASSERT + with pytest.raises(WalletWithSuchNameAlreadyExistsError): + session.create_wallet(name="aaa", password="wallet") # noqa: S106