Skip to content

Commit

Permalink
fix: add tests for transfer with rekey
Browse files Browse the repository at this point in the history
  • Loading branch information
inaie-makerx committed May 13, 2024
1 parent 0ee4b83 commit b0b3be9
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
transfer,
transfer_asset,
)
from algokit_utils.application_client import ApplicationClient
from algokit_utils.application_specification import ApplicationSpecification
from algokit_utils.dispenser_api import DispenserApiConfig
from algokit_utils.network_clients import get_algod_client, get_algonode_config
from algosdk.atomic_transaction_composer import AccountTransactionSigner
from algosdk.transaction import PaymentTxn
from algosdk.util import algos_to_microalgos
from pytest_httpx import HTTPXMock

Expand All @@ -28,16 +32,73 @@
if TYPE_CHECKING:
from algosdk.kmd import KMDClient
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient


MINIMUM_BALANCE = 100_000 # see https://developer.algorand.org/docs/get-details/accounts/#minimum-balance


@pytest.fixture(scope="module")
def client_fixture(
algod_client: "AlgodClient",
indexer_client: "IndexerClient",
app_spec: ApplicationSpecification,
funded_account: Account,
) -> ApplicationClient:
return ApplicationClient(algod_client, app_spec, creator=funded_account, indexer_client=indexer_client)


@pytest.fixture()
def to_account(kmd_client: "KMDClient") -> Account:
return create_kmd_wallet_account(kmd_client, get_unique_name())


@pytest.fixture()
def rekeyed_account(algod_client: "AlgodClient", kmd_client: "KMDClient") -> Account:
account = create_kmd_wallet_account(kmd_client, get_unique_name())
rekey_account = create_kmd_wallet_account(kmd_client, get_unique_name())

ensure_funded(
algod_client,
EnsureBalanceParameters(
account_to_fund=account,
min_spending_balance_micro_algos=300000,
min_funding_increment_micro_algos=1,
),
)

rekey_txn = PaymentTxn(
sender=account.address,
receiver=account.address,
amt=0,
note="rekey account",
rekey_to=rekey_account.address,
sp=algod_client.suggested_params(),
) # type: ignore[no-untyped-call]
signed_rekey_txn = rekey_txn.sign(account.private_key) # type: ignore[no-untyped-call]
algod_client.send_transaction(signed_rekey_txn)

return Account(address=account.address, private_key=rekey_account.private_key)


@pytest.fixture()
def account_transaction_signer(
kmd_client: "KMDClient",
algod_client: "AlgodClient",
) -> AccountTransactionSigner:
account = create_kmd_wallet_account(kmd_client, get_unique_name())
ensure_funded(
algod_client,
EnsureBalanceParameters(
account_to_fund=account,
min_spending_balance_micro_algos=300000,
min_funding_increment_micro_algos=1,
),
)

return AccountTransactionSigner(private_key=account.private_key)


@pytest.fixture()
def clawback_account(kmd_client: "KMDClient") -> Account:
return create_kmd_wallet_account(kmd_client, get_unique_name())
Expand All @@ -59,6 +120,43 @@ def test_transfer_algo(algod_client: "AlgodClient", to_account: Account, funded_
actual_amount = to_account_info.get("amount")
assert actual_amount == requested_amount

def test_transfer_algo_rekey_account(
algod_client: "AlgodClient", to_account: Account, rekeyed_account: Account
) -> None:
requested_amount = 100_000
transfer(
algod_client,
TransferParameters(
from_account=rekeyed_account,
to_address=to_account.address,
micro_algos=requested_amount,
),
)

to_account_info = algod_client.account_info(to_account.address)
assert isinstance(to_account_info, dict)
actual_amount = to_account_info.get("amount")
assert actual_amount == requested_amount


def test_transfer_algo_transaction_signer_account(
algod_client: "AlgodClient", to_account: Account, account_transaction_signer: AccountTransactionSigner
) -> None:
requested_amount = 100_000
transfer(
algod_client,
TransferParameters(
from_account=account_transaction_signer,
to_address=to_account.address,
micro_algos=requested_amount,
),
)

to_account_info = algod_client.account_info(to_account.address)
assert isinstance(to_account_info, dict)
actual_amount = to_account_info.get("amount")
assert actual_amount == requested_amount


def test_transfer_algo_max_fee_fails(algod_client: "AlgodClient", to_account: Account, funded_account: Account) -> None:
requested_amount = 100_000
Expand Down

0 comments on commit b0b3be9

Please sign in to comment.