Skip to content

Commit 9765364

Browse files
committed
refactor: update algokit utils dependency to v5
1 parent 2c80892 commit 9765364

File tree

9 files changed

+87
-106
lines changed

9 files changed

+87
-106
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies = [
5555
"pytest-mock>=3.10.0",
5656
"pytest-xdist[psutil]>=3.3",
5757
"py-algorand-sdk>=2.4.0",
58-
"algokit-utils>=4.0.0",
58+
"algokit-utils>=5.0.0a5",
5959
"pytest-cov>=4.1.0",
6060
"prettytable>=3.9.0",
6161
"mypy==1.10",
@@ -131,7 +131,7 @@ dependencies = [
131131
"pytest-xdist[psutil]>=3.3",
132132
"pytest-cov>=4.1.0",
133133
"py-algorand-sdk>=2.4.0",
134-
"algokit-utils>=4.0.0",
134+
"algokit-utils>=5.0.0a5",
135135
"puyapy>=5",
136136
]
137137

@@ -188,7 +188,7 @@ dependencies = [
188188
"pytest-mock>=3.10.0",
189189
"pytest-xdist[psutil]>=3.3",
190190
"py-algorand-sdk>=2.4.0",
191-
"algokit-utils>=4.0.0",
191+
"algokit-utils>=5.0.0a5",
192192
"pytest-cov>=4.1.0",
193193
"mypy==1.10",
194194
]

tests/arc4/test_arc4_method_signature.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pytest
1010
from algokit_utils import AlgoAmount, AlgorandClient, AssetCreateParams, PaymentParams
1111
from algopy import arc4
12-
from algosdk.atomic_transaction_composer import TransactionWithSigner
1312

1413
from tests.artifacts.Arc4ABIMethod.contract import (
1514
AnotherStruct,
@@ -43,10 +42,8 @@ def funded_account(algorand: AlgorandClient, context: _algopy_testing.AlgopyTest
4342
min_spending_balance=algokit_utils.AlgoAmount(micro_algo=_FUNDED_ACCOUNT_SPENDING),
4443
)
4544
# ensure context has the same account with matching balance
46-
context.any.account(
47-
account.address, balance=algopy.Global.min_balance + _FUNDED_ACCOUNT_SPENDING
48-
)
49-
return account.address
45+
context.any.account(account.addr, balance=algopy.Global.min_balance + _FUNDED_ACCOUNT_SPENDING)
46+
return account.addr
5047

5148

5249
@pytest.fixture()
@@ -130,15 +127,13 @@ def test_app_args_is_correct_with_txn(
130127
get_avm_result(
131128
"with_txn",
132129
value="hello",
133-
pay=TransactionWithSigner(
134-
txn=algorand.create_transaction.payment(
135-
PaymentParams(
136-
sender=localnet_creator_address,
137-
receiver=localnet_creator_address,
138-
amount=AlgoAmount(micro_algo=123),
139-
)
140-
),
141-
signer=algorand.account.get_signer(localnet_creator_address),
130+
pay=algorand.create_transaction.payment(
131+
PaymentParams(
132+
sender=localnet_creator_address,
133+
receiver=localnet_creator_address,
134+
amount=AlgoAmount(micro_algo=123),
135+
signer=algorand.account.get_signer(localnet_creator_address),
136+
)
142137
),
143138
arr=[1, 2],
144139
)
@@ -174,9 +169,7 @@ def test_app_args_is_correct_with_asset(
174169
sender=localnet_creator_address,
175170
total=123,
176171
)
177-
).confirmation[
178-
"asset-index"
179-
] # type: ignore[call-overload]
172+
).asset_id
180173

181174
# act
182175
get_avm_result("with_asset", value="hello", asset=asa_id, arr=[1, 2])
@@ -343,15 +336,13 @@ def test_prepare_txns_with_complex(
343336
get_avm_result(
344337
"complex_sig",
345338
struct1=((1, "2"), (1, "2"), 3, 4),
346-
txn=TransactionWithSigner(
347-
txn=algorand.create_transaction.payment(
348-
PaymentParams(
349-
sender=localnet_creator_address,
350-
receiver=localnet_creator_address,
351-
amount=AlgoAmount(micro_algo=123),
352-
)
339+
txn=algorand.create_transaction.payment(
340+
PaymentParams(
341+
sender=localnet_creator_address,
342+
receiver=localnet_creator_address,
343+
amount=AlgoAmount(micro_algo=123),
344+
signer=algorand.account.get_signer(localnet_creator_address),
353345
),
354-
signer=algorand.account.get_signer(localnet_creator_address),
355346
),
356347
acc=funded_account,
357348
five=[5],
@@ -394,9 +385,7 @@ def test_app_args_is_correct_with_index_resource_encoding( # noqa: PLR0913
394385
sender=localnet_creator_address,
395386
total=123,
396387
)
397-
).confirmation[
398-
"asset-index"
399-
] # type: ignore[call-overload]
388+
).asset_id
400389

401390
# act
402391
contract.echo_resource_by_index(
@@ -424,7 +413,7 @@ def test_app_args_is_correct_with_index_resource_encoding( # noqa: PLR0913
424413
]
425414
assert app_args[0] == arc4.arc4_signature(SignaturesContract.echo_resource_by_index)
426415

427-
assert result == [asa_id, other_app_id, funded_account]
416+
assert result == (asa_id, other_app_id, funded_account)
428417

429418

430419
def test_app_args_is_correct_with_value_resource_encoding( # noqa: PLR0913
@@ -444,9 +433,7 @@ def test_app_args_is_correct_with_value_resource_encoding( # noqa: PLR0913
444433
sender=localnet_creator_address,
445434
total=123,
446435
)
447-
).confirmation[
448-
"asset-index"
449-
] # type: ignore[call-overload]
436+
).asset_id
450437

451438
asset = context.any.asset(asset_id=asa_id, total=algopy.UInt64(123))
452439
app = context.ledger.get_app(other_app_id)
@@ -477,4 +464,4 @@ def test_app_args_is_correct_with_value_resource_encoding( # noqa: PLR0913
477464
]
478465
assert app_args[0] == arc4.arc4_signature(SignaturesContract.echo_resource_by_value)
479466

480-
assert result == [asset.id, app.id, acc]
467+
assert result == (asset.id, app.id, acc)

tests/arc4/test_emit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import base64
21
import typing
32
from collections.abc import Generator
43

@@ -83,7 +82,7 @@ def test_emit(get_avm_result: AVMInvoker, context: AlgopyTestContext) -> None:
8382
arc4.DynamicArray(arc4.UInt16(1), arc4.UInt16(2), arc4.UInt16(3)),
8483
arc4.Tuple((arc4.UInt32(1), arc4.UInt64(2), arc4.String("hello"))),
8584
)
86-
avm_result_ = get_avm_result(
85+
avm_result = get_avm_result(
8786
"verify_emit",
8887
a=_test_data.a.value,
8988
b=_test_data.b,
@@ -102,8 +101,7 @@ def test_emit(get_avm_result: AVMInvoker, context: AlgopyTestContext) -> None:
102101
s=_test_data_arc4.s.bytes.value,
103102
t=_test_data_arc4.t.bytes.value,
104103
)
105-
assert isinstance(avm_result_, list)
106-
avm_result = [base64.b64decode(b) for b in avm_result_]
104+
assert isinstance(avm_result, list)
107105

108106
arc4.emit(_test_data_arc4)
109107
arc4.emit(

tests/arc4/test_ufixednxm.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import typing
2+
from decimal import Decimal
23

34
import algokit_utils
45
import pytest
@@ -11,7 +12,7 @@
1112

1213

1314
def _invalid_bytes_length_error(length: int) -> str:
14-
return f"value string must be in bytes and correspond to a ufixed{length}"
15+
return f"expected {length // 8} bytes for uint{length}"
1516

1617

1718
@pytest.mark.parametrize(
@@ -71,7 +72,7 @@ def test_bigufixednxm_bytes(get_avm_result: AVMInvoker, value: str) -> None:
7172
def test_ufixednxm_from_bytes(get_avm_result: AVMInvoker, value: bytes) -> None:
7273
avm_result = get_avm_result("verify_ufixednxm_from_bytes", a=value)
7374
result = arc4.UFixedNxM[typing.Literal[32], typing.Literal[8]].from_bytes(value)
74-
assert avm_result == int.from_bytes(result.bytes.value)
75+
assert avm_result == int_to_decimal(int.from_bytes(result.bytes.value), 32, 8)
7576

7677

7778
@pytest.mark.parametrize(
@@ -103,7 +104,8 @@ def test_ufixednxm_from_bytes_invalid_length(get_avm_result: AVMInvoker, value:
103104
def test_bigufixednxm_from_bytes(get_avm_result: AVMInvoker, value: bytes) -> None:
104105
avm_result = get_avm_result("verify_bigufixednxm_from_bytes", a=value)
105106
result = arc4.BigUFixedNxM[typing.Literal[256], typing.Literal[16]].from_bytes(value)
106-
assert avm_result == int.from_bytes(result.bytes.value)
107+
108+
assert avm_result == int_to_decimal(int.from_bytes(result.bytes.value), 256, 16)
107109

108110

109111
@pytest.mark.parametrize(
@@ -137,8 +139,8 @@ def test_ufixednxm_from_log(get_avm_result: AVMInvoker, value: bytes, expected:
137139
result = arc4.UFixedNxM[typing.Literal[32], typing.Literal[8]].from_log(
138140
Bytes(ARC4_RETURN_PREFIX + value)
139141
)
140-
assert avm_result == expected
141-
assert avm_result == int.from_bytes(result.bytes.value)
142+
assert avm_result == int_to_decimal(expected, 32, 8)
143+
assert avm_result == int_to_decimal(int.from_bytes(result.bytes.value), 32, 8)
142144

143145

144146
@pytest.mark.parametrize(
@@ -192,8 +194,8 @@ def test_bigufixednxm_from_log(get_avm_result: AVMInvoker, value: bytes, expecte
192194
result = arc4.BigUFixedNxM[typing.Literal[256], typing.Literal[16]].from_log(
193195
Bytes(ARC4_RETURN_PREFIX + value)
194196
)
195-
assert avm_result == expected
196-
assert avm_result == int.from_bytes(result.bytes.value)
197+
assert avm_result == int_to_decimal(expected, 256, 16)
198+
assert avm_result == int_to_decimal(int.from_bytes(result.bytes.value), 256, 16)
197199

198200

199201
@pytest.mark.parametrize(
@@ -231,3 +233,9 @@ def test_bigufixednxm_from_log_invalid_length(get_avm_result: AVMInvoker, value:
231233
Bytes(ARC4_RETURN_PREFIX + value)
232234
)
233235
assert result.bytes == value
236+
237+
238+
def int_to_decimal(value: int, n: int, m: int) -> Decimal:
239+
s = str(value)
240+
d = n - m
241+
return Decimal(("0" * d + s[:-m])[-d:] + "." + ("0" * m + s[-m:])[-m:])

tests/arc4/test_uintn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def _invalid_bytes_length_error(length: int) -> str:
15-
return f"value string must be in bytes and correspond to a uint{length}"
15+
return f"expected {length // 8} bytes for uint{length}"
1616

1717

1818
@pytest.mark.parametrize(

tests/common.py

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import typing
55
from pathlib import Path
66

7-
import algosdk
87
from algokit_utils import (
8+
AddressWithSigners,
99
AlgorandClient,
1010
AppClient,
1111
AppClientMethodCallParams,
1212
AppFactory,
1313
AppFactoryCreateMethodCallParams,
1414
AppFactoryCreateParams,
1515
AppFactoryParams,
16-
SigningAccount,
16+
AssetCreateParams,
1717
)
18-
from algosdk.v2client.algod import AlgodClient
18+
from algokit_utils.transact import OnApplicationComplete
1919

2020
INITIAL_BALANCE_MICRO_ALGOS = int(20e6)
2121

@@ -31,7 +31,7 @@ def __init__(self, client: AppClient, factory: AppFactory):
3131
def __call__(
3232
self,
3333
method: str,
34-
on_complete: algosdk.transaction.OnComplete = algosdk.transaction.OnComplete.NoOpOC,
34+
on_complete: OnApplicationComplete | None = None,
3535
*,
3636
return_raw: bool = False,
3737
**kwargs: typing.Any,
@@ -53,13 +53,12 @@ def __call__(
5353
if return_raw and response.returns and len(response.returns) > 0:
5454
return response.returns[0].raw_value
5555
result = response.abi_return
56-
if result is None and response.returns and len(response.returns) > 0:
57-
assert response.returns[0].tx_info
58-
return response.returns[0].tx_info.get("logs", None)
56+
if result is None and response.confirmations and len(response.confirmations) > 0:
57+
return response.confirmations[0].logs
5958
if isinstance(result, list) and all(
6059
isinstance(i, int) and i >= 0 and i <= 255 for i in result
6160
):
62-
return bytes(result) # type: ignore[arg-type]
61+
return bytes(result)
6362
return result
6463

6564

@@ -73,7 +72,7 @@ def create_avm_invoker(app_spec: Path, algorand: AlgorandClient) -> AVMInvoker:
7372
AppFactoryParams(
7473
algorand=algorand,
7574
app_spec=app_spec.read_text(),
76-
default_sender=dispenser.address,
75+
default_sender=dispenser.addr,
7776
),
7877
)
7978
try:
@@ -90,8 +89,8 @@ def create_avm_invoker(app_spec: Path, algorand: AlgorandClient) -> AVMInvoker:
9089

9190
def generate_test_asset( # noqa: PLR0913
9291
*,
93-
algod_client: AlgodClient,
94-
sender: SigningAccount,
92+
algorand: AlgorandClient,
93+
sender: AddressWithSigners,
9594
total: int | None = None,
9695
decimals: int = 0,
9796
default_frozen: bool = False,
@@ -116,33 +115,24 @@ def generate_test_asset( # noqa: PLR0913
116115
f"${math.floor(random.random() * 100) + 1}_${total}"
117116
)
118117

119-
params = algod_client.suggested_params()
120-
121-
txn = algosdk.transaction.AssetConfigTxn(
122-
sender=sender.address,
123-
sp=params,
124-
total=total * 10**decimals,
125-
decimals=decimals,
126-
default_frozen=default_frozen,
127-
unit_name=unit_name,
128-
asset_name=asset_name,
129-
manager=manager,
130-
reserve=reserve,
131-
freeze=freeze,
132-
clawback=clawback,
133-
url=url,
134-
metadata_hash=metadata_hash,
135-
note=note or _random_note(),
136-
lease=lease,
137-
strict_empty_address_check=False,
138-
rekey_to=rekey_to,
139-
) # type: ignore[no-untyped-call, unused-ignore]
140-
141-
signed_transaction = txn.sign(sender.private_key) # type: ignore[no-untyped-call, unused-ignore]
142-
algod_client.send_transaction(signed_transaction)
143-
ptx = algod_client.pending_transaction_info(txn.get_txid()) # type: ignore[no-untyped-call, unused-ignore]
144-
145-
if isinstance(ptx, dict) and "asset-index" in ptx and isinstance(ptx["asset-index"], int):
146-
return ptx["asset-index"]
147-
else:
148-
raise ValueError("Unexpected response from pending_transaction_info")
118+
result = algorand.send.asset_create(
119+
AssetCreateParams(
120+
sender=sender.addr,
121+
total=total * 10**decimals,
122+
decimals=decimals,
123+
default_frozen=default_frozen,
124+
unit_name=unit_name,
125+
asset_name=asset_name,
126+
manager=manager,
127+
reserve=reserve,
128+
freeze=freeze,
129+
clawback=clawback,
130+
url=url,
131+
metadata_hash=metadata_hash,
132+
note=note or _random_note(),
133+
lease=lease,
134+
rekey_to=rekey_to,
135+
signer=sender.signer,
136+
)
137+
)
138+
return result.asset_id

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def algorand() -> AlgorandClient:
1616

1717
@pytest.fixture()
1818
def localnet_creator_address(algorand: AlgorandClient) -> str:
19-
return algorand.account.localnet_dispenser().address
19+
return algorand.account.localnet_dispenser().addr
2020

2121

2222
@pytest.fixture()

0 commit comments

Comments
 (0)