Skip to content

Commit

Permalink
fix non sdk mypy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed Apr 15, 2024
1 parent 452d97d commit 80a1cf5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/algokit_utils/beta/account_manager.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down
41 changes: 33 additions & 8 deletions src/algokit_utils/beta/algorand_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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).
Expand All @@ -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.
Expand All @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions tests/test_algorand_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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")

Expand All @@ -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))
Expand All @@ -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()
Expand All @@ -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
)
Expand All @@ -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]
Expand All @@ -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"),
Expand Down

0 comments on commit 80a1cf5

Please sign in to comment.