Skip to content

Commit c033b93

Browse files
aorumbayevdaniel-makerx
authored andcommitted
test: extra tests for signatures contract against avm
1 parent dcd6f02 commit c033b93

File tree

6 files changed

+199
-84
lines changed

6 files changed

+199
-84
lines changed

tests/arc4/test_arc4_method_signature.py

Lines changed: 106 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import algopy_testing
66
import algosdk
77
import pytest
8+
from algokit_utils.beta.algorand_client import AlgorandClient, AssetCreateParams, PayParams
89
from algopy import arc4
10+
from algopy_testing.primitives.uint64 import UInt64
11+
from algosdk.atomic_transaction_composer import TransactionWithSigner
912
from algosdk.v2client.algod import AlgodClient
1013

1114
from tests.artifacts.Arc4ABIMethod.contract import (
@@ -83,38 +86,69 @@ def test_app_args_is_correct_with_alias(
8386
]
8487

8588

86-
def test_app_args_is_correct_with_txn(context: algopy_testing.AlgopyTestContext) -> None:
89+
def test_app_args_is_correct_with_txn(
90+
context: algopy_testing.AlgopyTestContext,
91+
get_avm_result: AVMInvoker,
92+
localnet_creator_address: str,
93+
algorand: AlgorandClient,
94+
) -> None:
8795
# arrange
8896
contract = SignaturesContract()
8997
contract.create()
9098

9199
# act
100+
101+
get_avm_result(
102+
"with_txn",
103+
value="hello",
104+
pay=TransactionWithSigner(
105+
txn=algorand.transactions.payment(
106+
PayParams(
107+
sender=localnet_creator_address,
108+
receiver=localnet_creator_address,
109+
amount=123,
110+
)
111+
),
112+
signer=algorand.account.get_signer("default"),
113+
),
114+
arr=[1, 2],
115+
)
92116
contract.with_txn(
93117
arc4.String("hello"),
94-
context.any.txn.asset_config(total=algopy.UInt64(123)),
118+
context.any.txn.payment(amount=algopy.UInt64(123)),
95119
UInt8Array(arc4.UInt8(1), arc4.UInt8(2)),
96120
)
97121

98122
# asset
99123
txn = context.txn.last_active
100124
app_args = [txn.app_args(i) for i in range(3)]
101125
assert app_args == [
102-
algosdk.abi.Method.from_signature("with_txn(string,acfg,uint8[])void").get_selector(),
126+
algosdk.abi.Method.from_signature("with_txn(string,pay,uint8[])void").get_selector(),
103127
b"\x00\x05hello",
104128
b"\x00\x02\x01\x02",
105129
]
106130

107131

108132
def test_app_args_is_correct_with_asset(
109133
context: algopy_testing.AlgopyTestContext,
134+
localnet_creator_address: str,
135+
algorand: AlgorandClient,
136+
get_avm_result: AVMInvoker,
110137
) -> None: # arrange
111138
contract = SignaturesContract()
112139
contract.create()
113140

114141
# act
142+
asa_id = algorand.send.asset_create(
143+
AssetCreateParams(
144+
sender=localnet_creator_address,
145+
total=123,
146+
)
147+
)["confirmation"]["asset-index"]
148+
get_avm_result("with_asset", value="hello", asset=asa_id, arr=[1, 2])
115149
contract.with_asset(
116150
arc4.String("hello"),
117-
context.any.asset(total=algopy.UInt64(123)),
151+
context.any.asset(total=UInt64(123)),
118152
UInt8Array(arc4.UInt8(1), arc4.UInt8(2)),
119153
)
120154

@@ -129,7 +163,44 @@ def test_app_args_is_correct_with_asset(
129163
]
130164

131165

132-
def test_app_args_is_correct_with_application(context: algopy_testing.AlgopyTestContext) -> None:
166+
def test_app_args_is_correct_with_account(
167+
context: algopy_testing.AlgopyTestContext,
168+
localnet_creator_address: str,
169+
get_avm_result: AVMInvoker,
170+
) -> None: # arrange
171+
contract = SignaturesContract()
172+
contract.create()
173+
174+
# act
175+
test_account = context.any.account(total_apps_created=UInt64(1))
176+
contract.with_acc(
177+
arc4.String("hello"),
178+
test_account,
179+
UInt8Array(arc4.UInt8(1), arc4.UInt8(2)),
180+
)
181+
get_avm_result(
182+
"with_acc",
183+
value="hello",
184+
acc=localnet_creator_address,
185+
arr=[1, 2],
186+
accounts=[localnet_creator_address, localnet_creator_address],
187+
)
188+
189+
# assert
190+
txn = context.txn.last_active
191+
app_args = [txn.app_args(i) for i in range(int(txn.num_app_args))]
192+
assert app_args == [
193+
algosdk.abi.Method.from_signature("with_acc(string,account,uint8[])void").get_selector(),
194+
b"\x00\x05hello",
195+
b"\x01",
196+
b"\x00\x02\x01\x02",
197+
]
198+
199+
200+
def test_app_args_is_correct_with_application(
201+
context: algopy_testing.AlgopyTestContext,
202+
get_avm_result: AVMInvoker,
203+
) -> None:
133204
# arrange
134205
contract = SignaturesContract()
135206
contract.create()
@@ -138,6 +209,13 @@ def test_app_args_is_correct_with_application(context: algopy_testing.AlgopyTest
138209
other_app = context.any.application(id=1234)
139210

140211
# act
212+
get_avm_result(
213+
"with_app",
214+
value="hello",
215+
app=get_avm_result.client.app_id,
216+
arr=[1, 2],
217+
foreign_apps=[get_avm_result.client.app_id, get_avm_result.client.app_id],
218+
)
141219
contract.with_app(
142220
arc4.String("hello"),
143221
other_app,
@@ -195,7 +273,12 @@ def test_app_args_is_correct_with_complex(context: algopy_testing.AlgopyTestCont
195273
assert result[1].bytes == struct.bytes
196274

197275

198-
def test_prepare_txns_with_complex(context: algopy_testing.AlgopyTestContext) -> None:
276+
def test_prepare_txns_with_complex(
277+
context: algopy_testing.AlgopyTestContext,
278+
# get_avm_result: AVMInvoker,
279+
# algorand: AlgorandClient,
280+
# localnet_creator_address: str,
281+
) -> None:
199282
# arrange
200283
contract = SignaturesContract()
201284
contract.create()
@@ -214,6 +297,23 @@ def test_prepare_txns_with_complex(context: algopy_testing.AlgopyTestContext) ->
214297
)
215298

216299
# act
300+
# TODO: 1.0 Figure out proper way to pass encoded struct
301+
# get_avm_result(
302+
# "complex_sig",
303+
# struct1=struct.bytes.value,
304+
# txn=TransactionWithSigner(
305+
# txn=algorand.transactions.payment(
306+
# PayParams(
307+
# sender=localnet_creator_address,
308+
# receiver=localnet_creator_address,
309+
# amount=123,
310+
# )
311+
# ),
312+
# signer=algorand.account.get_signer("default"),
313+
# ),
314+
# acc=localnet_creator_address,
315+
# five=[5],
316+
# )
217317
with context.txn.create_group(gtxns=[deferred_app_call]):
218318
result = deferred_app_call.submit()
219319

tests/artifacts/Arc4ABIMethod/contract.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ def sink2(self, value: arc4.String, arr: UInt8Array) -> None:
4444
assert arr
4545

4646
@arc4.abimethod
47-
def with_txn(
48-
self, value: arc4.String, acfg: gtxn.AssetConfigTransaction, arr: UInt8Array
49-
) -> None:
47+
def with_txn(self, value: arc4.String, pay: gtxn.PaymentTransaction, arr: UInt8Array) -> None:
5048
assert value
5149
assert arr
52-
assert acfg.group_index == 0
50+
assert pay.group_index == 0
5351
assert Txn.group_index == 1
54-
assert acfg.total == 123
52+
assert pay.amount == 123
5553

5654
@arc4.abimethod
5755
def with_asset(self, value: arc4.String, asset: Asset, arr: UInt8Array) -> None:
@@ -64,7 +62,7 @@ def with_asset(self, value: arc4.String, asset: Asset, arr: UInt8Array) -> None:
6462
def with_app(self, value: arc4.String, app: Application, arr: UInt8Array) -> None:
6563
assert value
6664
assert arr
67-
assert app.id == 1234
65+
assert app.id >= 1001
6866
app_txn = gtxn.ApplicationCallTransaction(0)
6967
assert app_txn.apps(0) == op.Global.current_application_id
7068
assert Txn.applications(0) == op.Global.current_application_id
@@ -75,7 +73,7 @@ def with_app(self, value: arc4.String, app: Application, arr: UInt8Array) -> Non
7573
def with_acc(self, value: arc4.String, acc: Account, arr: UInt8Array) -> None:
7674
assert value
7775
assert arr
78-
assert acc.total_apps_created == 123
76+
assert acc.total_apps_created >= 1
7977
assert Txn.accounts(0) == Txn.sender
8078
assert Txn.accounts(1) == acc
8179

@@ -97,7 +95,7 @@ def complex_sig(
9795

9896
# acc
9997
assert Txn.application_args(2) == arc4.UInt8(1).bytes # acc array ref
100-
assert acc.balance == 123
98+
assert acc.balance >= 123
10199
assert five[0] == 5
102100

103101
return struct1.another_struct.copy(), struct1.copy()

0 commit comments

Comments
 (0)