From 80a1cf5696ce9a92fbbce5dcc91a92e342aa6ddf Mon Sep 17 00:00:00 2001 From: Joe Polny Date: Mon, 15 Apr 2024 08:32:13 -0400 Subject: [PATCH] fix non sdk mypy stuff --- src/algokit_utils/beta/account_manager.py | 7 ++-- src/algokit_utils/beta/algorand_client.py | 41 ++++++++++++++++++----- tests/test_algorand_client.py | 18 +++++----- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/algokit_utils/beta/account_manager.py b/src/algokit_utils/beta/account_manager.py index b68a6d1c..9b8be5d2 100644 --- a/src/algokit_utils/beta/account_manager.py +++ b/src/algokit_utils/beta/account_manager.py @@ -1,10 +1,11 @@ from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Self +from typing import Any from algokit_utils.account import get_dispenser_account, get_kmd_wallet_account, get_localnet_default_account from algosdk.account import generate_account from algosdk.atomic_transaction_composer import AccountTransactionSigner, TransactionSigner +from typing_extensions import Self from .client_manager import ClientManager @@ -81,7 +82,9 @@ def get_information(self, sender: str) -> dict[str, Any]: return info def get_asset_information(self, sender: str, asset_id: int) -> dict[str, Any]: - return self._client_manager.algod.account_asset_info(sender, asset_id) + info = self._client_manager.algod.account_asset_info(sender, asset_id) + assert isinstance(info, dict) + return info # TODO # def from_mnemonic(self, mnemonic_secret: str, sender: Optional[str] = None) -> AddrAndSigner: diff --git a/src/algokit_utils/beta/algorand_client.py b/src/algokit_utils/beta/algorand_client.py index 91551204..f17e9c53 100644 --- a/src/algokit_utils/beta/algorand_client.py +++ b/src/algokit_utils/beta/algorand_client.py @@ -2,7 +2,7 @@ import time from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Self +from typing import Any from algokit_utils.beta.account_manager import AccountManager from algokit_utils.beta.client_manager import AlgoSdkClients, ClientManager @@ -29,7 +29,32 @@ ) from algosdk.atomic_transaction_composer import AtomicTransactionResponse, TransactionSigner from algosdk.transaction import SuggestedParams, Transaction, wait_for_confirmation - +from typing_extensions import Self + + # payment: Callable[[PayParams], Transaction] + # asset_create: Callable[[AssetCreateParams], Transaction] + # asset_config: Callable[[AssetConfigParams], Transaction] + # asset_freeze: Callable[[AssetFreezeParams], Transaction] + # asset_destroy: Callable[[AssetDestroyParams], Transaction] + # asset_transfer: Callable[[AssetTransferParams], Transaction] + # app_call: Callable[[AppCallParams], Transaction] + # online_key_reg: Callable[[OnlineKeyRegParams], Transaction] + # method_call: Callable[[MethodCallParams], list[Transaction]] + # asset_opt_in: Callable[[AssetOptInParams], Transaction] + +__all__ = [ + "AlgorandClient", + "AssetCreateParams", + "AssetOptInParams", + "MethodCallParams", + "PayParams", + "AssetFreezeParams", + "AssetConfigParams", + "AssetDestroyParams", + "AppCallParams", + "OnlineKeyRegParams", + "AssetTransferParams" +] @dataclass class AlgorandClientSendMethods: @@ -220,7 +245,7 @@ def transactions(self) -> AlgorandClientTransactionMethods: ) @staticmethod - def default_local_net() -> Self: + def default_local_net() -> "AlgorandClient": """ Returns an `AlgorandClient` pointing at default LocalNet ports and API token. @@ -235,7 +260,7 @@ def default_local_net() -> Self: ) @staticmethod - def test_net() -> Self: + def test_net() -> "AlgorandClient": """ Returns an `AlgorandClient` pointing at TestNet using AlgoNode. @@ -250,7 +275,7 @@ def test_net() -> Self: ) @staticmethod - def main_net() -> Self: + def main_net() -> "AlgorandClient": """ Returns an `AlgorandClient` pointing at MainNet using AlgoNode. @@ -265,7 +290,7 @@ def main_net() -> Self: ) @staticmethod - def from_clients(clients: AlgoSdkClients) -> Self: + def from_clients(clients: AlgoSdkClients) -> "AlgorandClient": """ Returns an `AlgorandClient` pointing to the given client(s). @@ -275,7 +300,7 @@ def from_clients(clients: AlgoSdkClients) -> Self: return AlgorandClient(clients) @staticmethod - def from_environment() -> Self: + def from_environment() -> "AlgorandClient": """ Returns an `AlgorandClient` loading the configuration from environment variables. @@ -294,7 +319,7 @@ def from_environment() -> Self: ) @staticmethod - def from_config(config: AlgoClientConfigs) -> Self: + def from_config(config: AlgoClientConfigs) -> "AlgorandClient": """ Returns an `AlgorandClient` from the given config. diff --git a/tests/test_algorand_client.py b/tests/test_algorand_client.py index 4b82cb48..5f258640 100644 --- a/tests/test_algorand_client.py +++ b/tests/test_algorand_client.py @@ -54,7 +54,7 @@ def contract() -> Contract: return Contract.from_json(json.dumps(json.load(f)["contract"])) -def test_send_payment(algorand: AlgorandClient, alice: AddressAndSigner, bob: AddressAndSigner): +def test_send_payment(algorand: AlgorandClient, alice: AddressAndSigner, bob: AddressAndSigner) -> None: amount = 100_000 alice_pre_balance = algorand.account.get_information(alice.address)["amount"] @@ -68,7 +68,7 @@ def test_send_payment(algorand: AlgorandClient, alice: AddressAndSigner, bob: Ad assert bob_post_balance == bob_pre_balance + amount -def test_send_asset_create(algorand: AlgorandClient, alice: AddressAndSigner): +def test_send_asset_create(algorand: AlgorandClient, alice: AddressAndSigner) -> None: total = 100 result = algorand.send.asset_create(AssetCreateParams(sender=alice.address, total=total)) @@ -77,7 +77,7 @@ def test_send_asset_create(algorand: AlgorandClient, alice: AddressAndSigner): assert asset_index > 0 -def test_asset_opt_in(algorand: AlgorandClient, alice: AddressAndSigner, bob: AddressAndSigner): +def test_asset_opt_in(algorand: AlgorandClient, alice: AddressAndSigner, bob: AddressAndSigner) -> None: total = 100 result = algorand.send.asset_create(AssetCreateParams(sender=alice.address, total=total)) @@ -91,7 +91,7 @@ def test_asset_opt_in(algorand: AlgorandClient, alice: AddressAndSigner, bob: Ad DO_MATH_VALUE = 3 -def test_add_atc(algorand: AlgorandClient, app_client: ApplicationClient, alice: AddressAndSigner): +def test_add_atc(algorand: AlgorandClient, app_client: ApplicationClient, alice: AddressAndSigner) -> None: atc = AtomicTransactionComposer() app_client.compose_call(atc, call_abi_method="doMath", a=1, b=2, operation="sum") @@ -106,7 +106,7 @@ def test_add_atc(algorand: AlgorandClient, app_client: ApplicationClient, alice: def test_add_method_call( algorand: AlgorandClient, contract: Contract, alice: AddressAndSigner, app_client: ApplicationClient -): +) -> None: result = ( algorand.new_group() .add_payment(PayParams(sender=alice.address, amount=0, receiver=alice.address)) @@ -125,7 +125,7 @@ def test_add_method_call( def test_add_method_with_txn_arg( algorand: AlgorandClient, contract: Contract, alice: AddressAndSigner, app_client: ApplicationClient -): +) -> None: pay_arg = PayParams(sender=alice.address, receiver=alice.address, amount=1) result = ( algorand.new_group() @@ -145,7 +145,7 @@ def test_add_method_with_txn_arg( def test_add_method_call_with_method_call_arg( algorand: AlgorandClient, contract: Contract, alice: AddressAndSigner, app_client: ApplicationClient -): +) -> None: hello_world_call = MethodCallParams( method=contract.get_method_by_name("helloWorld"), sender=alice.address, app_id=app_client.app_id ) @@ -167,7 +167,7 @@ def test_add_method_call_with_method_call_arg( def test_add_method_call_with_method_call_arg_with_txn_arg( algorand: AlgorandClient, contract: Contract, alice: AddressAndSigner, app_client: ApplicationClient -): +) -> None: pay_arg = PayParams(sender=alice.address, receiver=alice.address, amount=1) txn_arg_call = MethodCallParams( method=contract.get_method_by_name("txnArg"), sender=alice.address, app_id=app_client.app_id, args=[pay_arg] @@ -190,7 +190,7 @@ def test_add_method_call_with_method_call_arg_with_txn_arg( def test_add_method_call_with_two_method_call_args_with_txn_arg( algorand: AlgorandClient, contract: Contract, alice: AddressAndSigner, app_client: ApplicationClient -): +) -> None: pay_arg_1 = PayParams(sender=alice.address, receiver=alice.address, amount=1) txn_arg_call_1 = MethodCallParams( method=contract.get_method_by_name("txnArg"),