Skip to content

Commit fd83ee8

Browse files
feat: include ARC4 results in log, and handle > 15 ARC4 arguments (#18)
1 parent 94e529f commit fd83ee8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+386
-302
lines changed

docs/testing-guide/arc4-types.md

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ For all `algopy.arc4` types with and without respective _value generator_, insta
1212

1313
```{testsetup}
1414
import algopy
15-
import algopy_testing
1615
from algopy_testing import algopy_testing_context
1716
1817
# Create the context manager for snippets below

docs/testing-guide/avm-types.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ For 'primitive `algopy` types such as `Account`, `Application`, `Asset`, `UInt64
88

99
```{testsetup}
1010
import algopy
11-
import algopy_testing
1211
from algopy_testing import algopy_testing_context
1312
1413
# Create the context manager for snippets below

docs/testing-guide/opcodes.md

+23-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ The [coverage](coverage.md) file provides a comprehensive list of all opcodes an
66

77
```{testsetup}
88
import algopy
9-
import algopy_testing
109
from algopy_testing import algopy_testing_context
1110
1211
# Create the context manager for snippets below
@@ -29,7 +28,7 @@ The following opcodes are demonstrated:
2928
- `op.ecdsa_verify`
3029

3130
```{testcode}
32-
import algopy.op as op
31+
from algopy import op
3332
3433
# SHA256 hash
3534
data = algopy.Bytes(b"Hello, World!")
@@ -59,7 +58,7 @@ The following opcodes are demonstrated:
5958
- `op.setbit_uint64`
6059

6160
```{testcode}
62-
import algopy.op as op
61+
from algopy import op
6362
6463
# Addition with carry
6564
result, carry = op.addw(algopy.UInt64(2**63), algopy.UInt64(2**63))
@@ -80,7 +79,7 @@ These types necessitate interaction with the transaction context:
8079
### algopy.op.Global
8180

8281
```{testcode}
83-
import algopy.op as op
82+
from algopy import op
8483
8584
class MyContract(algopy.ARC4Contract):
8685
@algopy.arc4.abimethod
@@ -102,12 +101,12 @@ assert result == algopy.UInt64(101000)
102101
### algopy.op.Txn
103102

104103
```{testcode}
105-
import algopy.op as op
104+
from algopy import op
106105
107106
class MyContract(algopy.ARC4Contract):
108107
@algopy.arc4.abimethod
109-
def check_txn_fields(self) -> algopy.Bytes:
110-
return op.Txn.sender
108+
def check_txn_fields(self) -> algopy.arc4.Address:
109+
return algopy.arc4.Address(op.Txn.sender)
111110
112111
... # setup context (below assumes available under 'ctx' variable)
113112
@@ -121,7 +120,7 @@ assert result == custom_sender
121120
### algopy.op.AssetHoldingGet
122121

123122
```{testcode}
124-
import algopy.op as op
123+
from algopy import op
125124
126125
class AssetContract(algopy.ARC4Contract):
127126
@algopy.arc4.abimethod
@@ -141,7 +140,7 @@ assert result == algopy.UInt64(5000)
141140
### algopy.op.AppGlobal
142141

143142
```{testcode}
144-
import algopy.op as op
143+
from algopy import op
145144
146145
class StateContract(algopy.ARC4Contract):
147146
@algopy.arc4.abimethod
@@ -162,7 +161,7 @@ assert stored_value == 42
162161
### algopy.op.Block
163162

164163
```{testcode}
165-
import algopy.op as op
164+
from algopy import op
166165
167166
class BlockInfoContract(algopy.ARC4Contract):
168167
@algopy.arc4.abimethod
@@ -180,7 +179,7 @@ assert seed == algopy.op.itob(123456)
180179
### algopy.op.AcctParamsGet
181180

182181
```{testcode}
183-
import algopy.op as op
182+
from algopy import op
184183
185184
class AccountParamsContract(algopy.ARC4Contract):
186185
@algopy.arc4.abimethod
@@ -205,7 +204,7 @@ class AppParamsContract(algopy.ARC4Contract):
205204
def get_app_creator(self, app_id: algopy.Application) -> algopy.arc4.Address:
206205
creator, exists = algopy.op.AppParamsGet.app_creator(app_id)
207206
assert exists
208-
return creator
207+
return algopy.arc4.Address(creator)
209208
210209
... # setup context (below assumes available under 'ctx' variable)
211210
@@ -218,8 +217,7 @@ assert creator == context.default_sender
218217
### algopy.op.AssetParamsGet
219218

220219
```{testcode}
221-
from algopy_testing import algopy_testing_context
222-
import algopy.op as op
220+
from algopy import op
223221
224222
class AssetParamsContract(algopy.ARC4Contract):
225223
@algopy.arc4.abimethod
@@ -239,8 +237,7 @@ assert total == algopy.UInt64(1000000)
239237
### algopy.op.Box
240238

241239
```{testcode}
242-
from algopy_testing import algopy_testing_context
243-
import algopy.op as op
240+
from algopy import op
244241
245242
class BoxStorageContract(algopy.ARC4Contract):
246243
@algopy.arc4.abimethod
@@ -329,23 +326,22 @@ assert result == 11
329326
```{testcode}
330327
from unittest.mock import patch, MagicMock
331328
import algopy
332-
from algopy_testing.primitives import Bytes
333329
334330
def test_mock_vrf_verify():
335-
mock_result = (Bytes(b'mock_output'), True)
331+
mock_result = (algopy.Bytes(b'mock_output'), True)
336332
with patch('algopy.op.vrf_verify', return_value=mock_result) as mock_vrf_verify:
337333
result = algopy.op.vrf_verify(
338334
algopy.op.VrfVerify.VrfAlgorand,
339-
Bytes(b'proof'),
340-
Bytes(b'message'),
341-
Bytes(b'public_key')
335+
algopy.Bytes(b'proof'),
336+
algopy.Bytes(b'message'),
337+
algopy.Bytes(b'public_key')
342338
)
343339
assert result == mock_result
344340
mock_vrf_verify.assert_called_once_with(
345341
algopy.op.VrfVerify.VrfAlgorand,
346-
Bytes(b'proof'),
347-
Bytes(b'message'),
348-
Bytes(b'public_key')
342+
algopy.Bytes(b'proof'),
343+
algopy.Bytes(b'message'),
344+
algopy.Bytes(b'public_key')
349345
)
350346
351347
test_mock_vrf_verify()
@@ -356,19 +352,18 @@ test_mock_vrf_verify()
356352
```{testcode}
357353
from unittest.mock import patch, MagicMock
358354
import algopy
359-
from algopy_testing.primitives import Bytes
360355
361356
def test_mock_elliptic_curve_decompress():
362-
mock_result = (Bytes(b'x_coord'), Bytes(b'y_coord'))
357+
mock_result = (algopy.Bytes(b'x_coord'), algopy.Bytes(b'y_coord'))
363358
with patch('algopy.op.EllipticCurve.decompress', return_value=mock_result) as mock_decompress:
364359
result = algopy.op.EllipticCurve.decompress(
365360
algopy.op.EC.BN254g1,
366-
Bytes(b'compressed_point')
361+
algopy.Bytes(b'compressed_point')
367362
)
368363
assert result == mock_result
369364
mock_decompress.assert_called_once_with(
370365
algopy.op.EC.BN254g1,
371-
Bytes(b'compressed_point')
366+
algopy.Bytes(b'compressed_point')
372367
)
373368
374369
test_mock_elliptic_curve_decompress()

docs/testing-guide/signature-testing.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Test Algorand smart signatures (LogicSigs) with ease using the Algorand Python T
44

55
```{testsetup}
66
import algopy
7-
import algopy_testing
87
from algopy_testing import algopy_testing_context
98
109
# Create the context manager for snippets below

docs/testing-guide/state-management.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
```{testsetup}
66
import algopy
7-
import algopy_testing
87
from algopy_testing import algopy_testing_context
98
109
# Create the context manager for snippets below

docs/testing-guide/transactions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ from algopy_testing import AlgopyTestContext, algopy_testing_context
115115
116116
class SimpleContract(algopy.ARC4Contract):
117117
@algopy.arc4.abimethod
118-
def check_sender(self) -> algopy.Bytes:
119-
return algopy.Txn.sender
118+
def check_sender(self) -> algopy.arc4.Address:
119+
return algopy.arc4.Address(algopy.Txn.sender)
120120
...
121121
122122
# Create a contract instance

pyproject.toml

+8-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Source = "https://github.com/algorandfoundation/puya/tree/main/algopy_testing"
4141
allow-direct-references = true
4242

4343
[tool.hatch.build.targets.wheel]
44-
packages = ["src/algopy", 'src/algopy_testing']
44+
packages = ["src/algopy", 'src/algopy_testing', 'src/_algopy_testing']
4545

4646
[[tool.hatch.envs.all.matrix]]
4747
python = ["3.12"]
@@ -126,7 +126,6 @@ clean_dist = "rm -rf dist"
126126

127127
# docs environment
128128
[tool.hatch.envs.docs]
129-
detached = true
130129
path = ".venv.docs"
131130
type = "virtual"
132131
python = "3.12"
@@ -141,13 +140,13 @@ dependencies = [
141140
"ipykernel",
142141
"pytest",
143142
"py-algorand-sdk",
144-
"algokit-utils",
145-
"pycryptodomex>=3.6.0,<4",
146-
"pynacl>=1.4.0,<2",
147-
"ecdsa>=0.17.0",
148-
"coincurve>=19.0.1",
149-
"algorand-python",
150-
"algorand-python-testing @ {root:uri}",
143+
]
144+
# environment has algopy_testing included as an editable dependency
145+
# however it also includes the package dependencies
146+
# the stubs can't be in the same as the project when it is editable
147+
# so explicitly remove them
148+
post-install-commands = [
149+
"hatch run docs:pip uninstall -y algorand-python",
151150
]
152151

153152
[tool.hatch.envs.docs.scripts]

src/_algopy_testing/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from _algopy_testing import arc4, gtxn, itxn
2-
from _algopy_testing._context_helpers.context_storage import algopy_testing_context
3-
from _algopy_testing._context_helpers.ledger_context import LedgerContext
4-
from _algopy_testing._context_helpers.txn_context import TransactionContext
5-
from _algopy_testing._itxn_loader import ITxnGroupLoader, ITxnLoader
6-
from _algopy_testing._value_generators.arc4 import ARC4ValueGenerator
7-
from _algopy_testing._value_generators.avm import AVMValueGenerator
8-
from _algopy_testing._value_generators.txn import TxnValueGenerator
92
from _algopy_testing.context import AlgopyTestContext
3+
from _algopy_testing.context_helpers.context_storage import algopy_testing_context
4+
from _algopy_testing.context_helpers.ledger_context import LedgerContext
5+
from _algopy_testing.context_helpers.txn_context import TransactionContext
106
from _algopy_testing.decorators.subroutine import subroutine
117
from _algopy_testing.enums import OnCompleteAction, TransactionType
8+
from _algopy_testing.itxn_loader import ITxnGroupLoader, ITxnLoader
129
from _algopy_testing.models import (
1310
Account,
1411
Application,
@@ -24,6 +21,9 @@
2421
)
2522
from _algopy_testing.primitives import BigUInt, Bytes, String, UInt64
2623
from _algopy_testing.state import Box, BoxMap, BoxRef, GlobalState, LocalState
24+
from _algopy_testing.value_generators.arc4 import ARC4ValueGenerator
25+
from _algopy_testing.value_generators.avm import AVMValueGenerator
26+
from _algopy_testing.value_generators.txn import TxnValueGenerator
2727

2828
# TODO: clean up and ensure only algopy_testing namespace specific user facing abstractions
2929
# are exposed Only keep the _value_generators, ledger_context, txn_context,

src/_algopy_testing/_context_helpers/__init__.py

-13
This file was deleted.

0 commit comments

Comments
 (0)