Skip to content
Snippets Groups Projects
Commit 80225df9 authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Add tests for detectable errors

parent e99b739f
No related branches found
No related tags found
No related merge requests found
Pipeline #116918 failed
Showing with 248 additions and 0 deletions
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
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
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)
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
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`"
),
)
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")
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")
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment