Skip to content
Snippets Groups Projects
Commit ffba51a4 authored by Jakub Ziebinski's avatar Jakub Ziebinski
Browse files

Move account credentials to local-tools

parent 0e78b14d
No related branches found
No related tags found
1 merge request!66Make beekeepy independent
Pipeline #115911 passed
Showing
with 550 additions and 37 deletions
from __future__ import annotations
from beekeepy._interface.key_pair import KeyPair
from helpy._interfaces.wax import calculate_public_key, generate_private_key
class AccountCredentials(KeyPair):
name: str
@classmethod
def create(cls, name: str) -> AccountCredentials:
pv_key = generate_private_key()
pub_key = calculate_public_key(pv_key)
return AccountCredentials(name=name, public_key=pub_key, private_key=pv_key)
@classmethod
def create_multiple(cls, number_of_accounts: int, *, name_base: str = "account") -> list[AccountCredentials]:
return [AccountCredentials.create(f"{name_base}-{i}") for i in range(number_of_accounts)]
...@@ -2,7 +2,6 @@ from __future__ import annotations ...@@ -2,7 +2,6 @@ from __future__ import annotations
from beekeepy._interface._sanitize import mask, sanitize from beekeepy._interface._sanitize import mask, sanitize
from beekeepy._interface._suppress_api_not_found import SuppressApiNotFound from beekeepy._interface._suppress_api_not_found import SuppressApiNotFound
from beekeepy._interface.account_credentials import AccountCredentials
from beekeepy._interface.context import ( from beekeepy._interface.context import (
ContextAsync, ContextAsync,
ContextSync, ContextSync,
...@@ -20,7 +19,6 @@ from beekeepy._interface.stopwatch import Stopwatch, StopwatchResult ...@@ -20,7 +19,6 @@ from beekeepy._interface.stopwatch import Stopwatch, StopwatchResult
from beekeepy._interface.url import HttpUrl, P2PUrl, Url, WsUrl from beekeepy._interface.url import HttpUrl, P2PUrl, Url, WsUrl
__all__ = [ __all__ = [
"AccountCredentials",
"ContextAsync", "ContextAsync",
"ContextSettingsUpdater", "ContextSettingsUpdater",
"ContextSync", "ContextSync",
......
...@@ -9,8 +9,9 @@ from local_tools.beekeepy.models import WalletInfo ...@@ -9,8 +9,9 @@ from local_tools.beekeepy.models import WalletInfo
from beekeepy.exceptions import ErrorInResponseError from beekeepy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.account_credentials import AccountCredentials
from beekeepy.handle.runnable import Beekeeper from beekeepy.handle.runnable import Beekeeper
from beekeepy.interfaces import AccountCredentials
def test_api_close(beekeeper: Beekeeper, wallet: WalletInfo) -> None: def test_api_close(beekeeper: Beekeeper, wallet: WalletInfo) -> None:
......
...@@ -2,7 +2,7 @@ from __future__ import annotations ...@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from beekeepy.interfaces import AccountCredentials from local_tools.beekeepy.account_credentials import AccountCredentials
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
...@@ -12,7 +12,7 @@ if TYPE_CHECKING: ...@@ -12,7 +12,7 @@ if TYPE_CHECKING:
def test_api_has_matching_key(beekeeper: Beekeeper, wallet: WalletInfo) -> None: def test_api_has_matching_key(beekeeper: Beekeeper, wallet: WalletInfo) -> None:
# ARRANGE # ARRANGE
account = AccountCredentials.create("alice") account = AccountCredentials.create()
beekeeper.api.import_key(wallet_name=wallet.name, wif_key=account.private_key) beekeeper.api.import_key(wallet_name=wallet.name, wif_key=account.private_key)
# ACT # ACT
......
...@@ -7,10 +7,10 @@ import pytest ...@@ -7,10 +7,10 @@ import pytest
from beekeepy.exceptions import ErrorInResponseError from beekeepy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.account_credentials import AccountCredentials
from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT
from beekeepy.handle.runnable import Beekeeper from beekeepy.handle.runnable import Beekeeper
from beekeepy.interfaces import AccountCredentials
def test_api_import_key(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: def test_api_import_key(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None:
......
...@@ -3,9 +3,9 @@ from __future__ import annotations ...@@ -3,9 +3,9 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
from local_tools.beekeepy.account_credentials import AccountCredentials
from beekeepy.exceptions import ErrorInResponseError from beekeepy.exceptions import ErrorInResponseError
from beekeepy.interfaces import AccountCredentials
from schemas.fields.basic import PublicKey from schemas.fields.basic import PublicKey
if TYPE_CHECKING: if TYPE_CHECKING:
......
...@@ -4,9 +4,9 @@ from functools import wraps ...@@ -4,9 +4,9 @@ from functools import wraps
from typing import Iterator from typing import Iterator
import pytest import pytest
from local_tools.beekeepy.account_credentials import AccountCredentials
from local_tools.beekeepy.generators import ( from local_tools.beekeepy.generators import (
default_wallet_credentials, default_wallet_credentials,
generate_account_name,
generate_wallet_name, generate_wallet_name,
generate_wallet_password, generate_wallet_password,
) )
...@@ -18,7 +18,6 @@ from local_tools.beekeepy.models import ( ...@@ -18,7 +18,6 @@ from local_tools.beekeepy.models import (
) )
from beekeepy.handle.runnable import Beekeeper from beekeepy.handle.runnable import Beekeeper
from beekeepy.interfaces import AccountCredentials
@pytest.fixture() @pytest.fixture()
...@@ -47,7 +46,7 @@ def wallet(beekeeper: Beekeeper) -> WalletInfo: ...@@ -47,7 +46,7 @@ def wallet(beekeeper: Beekeeper) -> WalletInfo:
@pytest.fixture() @pytest.fixture()
def account(beekeeper: Beekeeper, wallet: WalletInfo) -> AccountCredentials: def account(beekeeper: Beekeeper, wallet: WalletInfo) -> AccountCredentials:
acc = AccountCredentials.create(generate_account_name()) acc = AccountCredentials.create()
beekeeper.api.import_key(wallet_name=wallet.name, wif_key=acc.private_key) beekeeper.api.import_key(wallet_name=wallet.name, wif_key=acc.private_key)
return acc return acc
...@@ -67,11 +66,7 @@ def setup_wallets(beekeeper: Beekeeper) -> WalletsGeneratorT: ...@@ -67,11 +66,7 @@ def setup_wallets(beekeeper: Beekeeper) -> WalletsGeneratorT:
WalletInfoWithImportedAccounts( WalletInfoWithImportedAccounts(
name=generate_wallet_name(i), name=generate_wallet_name(i),
password=generate_wallet_password(i), password=generate_wallet_password(i),
accounts=( accounts=(AccountCredentials.create_multiple(keys_per_wallet) if keys_per_wallet else []),
AccountCredentials.create_multiple(keys_per_wallet, name_base=generate_account_name(i))
if keys_per_wallet
else []
),
) )
for i in range(count) for i in range(count)
] ]
......
...@@ -6,12 +6,12 @@ import json ...@@ -6,12 +6,12 @@ import json
import sys import sys
from pathlib import Path from pathlib import Path
from local_tools.beekeepy.account_credentials import AccountCredentials
from local_tools.beekeepy.models import WalletInfoWithImportedAccounts from local_tools.beekeepy.models import WalletInfoWithImportedAccounts
from loguru import logger from loguru import logger
from beekeepy import Settings from beekeepy import Settings
from beekeepy.handle.runnable import AsyncBeekeeper from beekeepy.handle.runnable import AsyncBeekeeper
from beekeepy.interfaces import AccountCredentials
async def generate_wallets_and_keys(number_of_wallets: int) -> None: async def generate_wallets_and_keys(number_of_wallets: int) -> None:
......
...@@ -7,10 +7,10 @@ from local_tools.beekeepy.network import raw_http_call ...@@ -7,10 +7,10 @@ from local_tools.beekeepy.network import raw_http_call
from schemas.jsonrpc import JSONRPCRequest from schemas.jsonrpc import JSONRPCRequest
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.account_credentials import AccountCredentials
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
from beekeepy.handle.runnable import Beekeeper from beekeepy.handle.runnable import Beekeeper
from beekeepy.interfaces import AccountCredentials
def test_empty_sign_digest(beekeeper: Beekeeper, wallet: WalletInfo, account: AccountCredentials) -> None: # noqa: ARG001 def test_empty_sign_digest(beekeeper: Beekeeper, wallet: WalletInfo, account: AccountCredentials) -> None: # noqa: ARG001
......
...@@ -7,10 +7,10 @@ from local_tools.beekeepy.network import raw_http_call ...@@ -7,10 +7,10 @@ from local_tools.beekeepy.network import raw_http_call
from schemas.jsonrpc import JSONRPCRequest from schemas.jsonrpc import JSONRPCRequest
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.account_credentials import AccountCredentials
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
from beekeepy.handle.runnable import Beekeeper from beekeepy.handle.runnable import Beekeeper
from beekeepy.interfaces import AccountCredentials
def test_sign_digest_response_uniques(beekeeper: Beekeeper, wallet: WalletInfo, account: AccountCredentials) -> None: # noqa: ARG001 def test_sign_digest_response_uniques(beekeeper: Beekeeper, wallet: WalletInfo, account: AccountCredentials) -> None: # noqa: ARG001
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ if TYPE_CHECKING: ...@@ -9,7 +9,7 @@ if TYPE_CHECKING:
from loguru import Logger from loguru import Logger
from beekeepy import Settings from beekeepy import Settings
from beekeepy._interface.account_credentials import AccountCredentials from local_tools.beekeepy.account_credentials import AccountCredentials
@dataclass @dataclass
......
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