55import algopy_testing
66import algosdk
77import pytest
8+ from algokit_utils .beta .algorand_client import AlgorandClient , AssetCreateParams , PayParams
89from algopy import arc4
10+ from algopy_testing .primitives .uint64 import UInt64
11+ from algosdk .atomic_transaction_composer import TransactionWithSigner
912from algosdk .v2client .algod import AlgodClient
1013
1114from 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 \x05 hello" ,
104128 b"\x00 \x02 \x01 \x02 " ,
105129 ]
106130
107131
108132def 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 \x05 hello" ,
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
0 commit comments