Skip to content

Commit b14c635

Browse files
committed
refactor: note that @subroutine is optional for contract methods
1 parent 32a2787 commit b14c635

File tree

8 files changed

+61
-75
lines changed

8 files changed

+61
-75
lines changed

docs/testing-guide/subroutines.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ context = ctx_manager.__enter__()
1818

1919
The `@algopy.subroutine` decorator exposes contract methods for isolated testing within the Algorand Python Testing framework. This enables focused validation of core business logic without the overhead of full application deployment and execution.
2020

21+
`@algopy.subroutine` decorator is optional for the methods in a contract which are not callable externally.
22+
2123
## Usage
2224

2325
1. Decorate internal methods with `@algopy.subroutine`:
@@ -26,7 +28,7 @@ The `@algopy.subroutine` decorator exposes contract methods for isolated testing
2628
from algopy import subroutine, UInt64
2729
2830
class MyContract:
29-
@subroutine
31+
@subroutine # optional
3032
def calculate_value(self, input: UInt64) -> UInt64:
3133
return input * UInt64(2)
3234
```

examples/marketplace/contract.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
gtxn,
1010
itxn,
1111
op,
12-
subroutine,
1312
)
1413
from algopy.arc4 import abimethod
1514

@@ -32,7 +31,6 @@ class DigitalMarketplace(ARC4Contract):
3231
def __init__(self) -> None:
3332
self.listings = BoxMap(ListingKey, ListingValue)
3433

35-
@subroutine
3634
def listings_box_mbr(self) -> UInt64:
3735
return (
3836
2_500
@@ -55,7 +53,6 @@ def listings_box_mbr(self) -> UInt64:
5553
* 400
5654
)
5755

58-
@subroutine
5956
def quantity_price(self, quantity: UInt64, price: UInt64, asset_decimals: UInt64) -> UInt64:
6057
amount_not_scaled_high, amount_not_scaled_low = op.mulw(price, quantity)
6158
scaling_factor_high, scaling_factor_low = op.expw(10, asset_decimals)

examples/simple_voting/contract.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Txn,
99
UInt64,
1010
op,
11-
subroutine,
1211
)
1312

1413
VOTE_PRICE = 10_000
@@ -24,11 +23,9 @@ def __init__(self) -> None:
2423
)
2524
self.voted = LocalState(UInt64, key="voted", description="Tracks if an account has voted")
2625

27-
@subroutine
2826
def set_topic(self, topic: Bytes) -> None:
2927
self.topic.value = topic
3028

31-
@subroutine
3229
def vote(self, voter: Account) -> bool:
3330
assert op.Global.group_size == UInt64(2)
3431
assert op.GTxn.amount(1) == UInt64(VOTE_PRICE)
@@ -40,7 +37,6 @@ def vote(self, voter: Account) -> bool:
4037
self.voted[voter] = UInt64(1)
4138
return True
4239

43-
@subroutine
4440
def get_votes(self) -> UInt64:
4541
return self.votes.value
4642

tests/artifacts/Arrays/data/StaticSizeContract.approval.teal

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ test_array_after_for@5:
308308
pushbytes "a"
309309
swap
310310
box_put
311-
// tests/artifacts/Arrays/static_size.py:169
311+
// tests/artifacts/Arrays/static_size.py:168
312312
// last_point = path[0]
313313
extract 0 144 // on error: index access is out of bounds
314314
dup
@@ -319,24 +319,24 @@ test_array_after_for@5:
319319
intc_2 // 8
320320
extract_uint64
321321
bury 6
322-
// tests/artifacts/Arrays/static_size.py:170
322+
// tests/artifacts/Arrays/static_size.py:169
323323
// length = UInt64()
324324
intc_0 // 0
325325
bury 5
326-
// tests/artifacts/Arrays/static_size.py:171
326+
// tests/artifacts/Arrays/static_size.py:170
327327
// for point_idx in urange(1, path.length):
328328
intc_1 // 1
329329
bury 3
330330

331331
test_array_for_header@7:
332-
// tests/artifacts/Arrays/static_size.py:171
332+
// tests/artifacts/Arrays/static_size.py:170
333333
// for point_idx in urange(1, path.length):
334334
dig 2
335335
dig 8
336336
<
337337
bz test_array_after_for@15
338338
dig 1
339-
// tests/artifacts/Arrays/static_size.py:172
339+
// tests/artifacts/Arrays/static_size.py:171
340340
// point = path[point_idx]
341341
dig 3
342342
intc 4 // 144
@@ -349,45 +349,45 @@ test_array_for_header@7:
349349
intc_2 // 8
350350
extract_uint64
351351
bury 6
352-
// tests/artifacts/Arrays/static_size.py:173
352+
// tests/artifacts/Arrays/static_size.py:172
353353
// if point.x < last_point.x:
354354
dig 10
355355
b<
356356
bz test_array_else_body@10
357-
// tests/artifacts/Arrays/static_size.py:174
357+
// tests/artifacts/Arrays/static_size.py:173
358358
// dx = last_point.x.as_uint64() - point.x.as_uint64()
359359
dig 10
360-
// tests/artifacts/Arrays/static_size.py:169
360+
// tests/artifacts/Arrays/static_size.py:168
361361
// last_point = path[0]
362362
intc_0 // 0
363-
// tests/artifacts/Arrays/static_size.py:174
363+
// tests/artifacts/Arrays/static_size.py:173
364364
// dx = last_point.x.as_uint64() - point.x.as_uint64()
365365
extract_uint64
366366
swap
367-
// tests/artifacts/Arrays/static_size.py:172
367+
// tests/artifacts/Arrays/static_size.py:171
368368
// point = path[point_idx]
369369
intc_0 // 0
370-
// tests/artifacts/Arrays/static_size.py:174
370+
// tests/artifacts/Arrays/static_size.py:173
371371
// dx = last_point.x.as_uint64() - point.x.as_uint64()
372372
extract_uint64
373373
-
374374
bury 7
375375

376376
test_array_after_if_else@11:
377-
// tests/artifacts/Arrays/static_size.py:177
377+
// tests/artifacts/Arrays/static_size.py:176
378378
// if point.y < last_point.y:
379379
dig 3
380380
dig 6
381381
<
382382
bz test_array_else_body@13
383-
// tests/artifacts/Arrays/static_size.py:178
383+
// tests/artifacts/Arrays/static_size.py:177
384384
// dy = last_point.y - point.y
385385
dig 5
386386
dig 4
387387
-
388388

389389
test_array_after_if_else@14:
390-
// tests/artifacts/Arrays/static_size.py:181
390+
// tests/artifacts/Arrays/static_size.py:180
391391
// length += op.sqrt(dx * dx + dy * dy)
392392
dig 7
393393
dup
@@ -400,7 +400,7 @@ test_array_after_if_else@14:
400400
dig 5
401401
+
402402
bury 5
403-
// tests/artifacts/Arrays/static_size.py:171
403+
// tests/artifacts/Arrays/static_size.py:170
404404
// for point_idx in urange(1, path.length):
405405
dig 2
406406
intc_1 // 1
@@ -409,25 +409,25 @@ test_array_after_if_else@14:
409409
b test_array_for_header@7
410410

411411
test_array_else_body@13:
412-
// tests/artifacts/Arrays/static_size.py:180
412+
// tests/artifacts/Arrays/static_size.py:179
413413
// dy = point.y - last_point.y
414414
dig 3
415415
dig 6
416416
-
417417
b test_array_after_if_else@14
418418

419419
test_array_else_body@10:
420-
// tests/artifacts/Arrays/static_size.py:172
420+
// tests/artifacts/Arrays/static_size.py:171
421421
// point = path[point_idx]
422422
intc_0 // 0
423-
// tests/artifacts/Arrays/static_size.py:176
423+
// tests/artifacts/Arrays/static_size.py:175
424424
// dx = point.x.as_uint64() - last_point.x.as_uint64()
425425
extract_uint64
426426
dig 10
427-
// tests/artifacts/Arrays/static_size.py:169
427+
// tests/artifacts/Arrays/static_size.py:168
428428
// last_point = path[0]
429429
intc_0 // 0
430-
// tests/artifacts/Arrays/static_size.py:176
430+
// tests/artifacts/Arrays/static_size.py:175
431431
// dx = point.x.as_uint64() - last_point.x.as_uint64()
432432
extract_uint64
433433
-
@@ -842,7 +842,7 @@ sum_array_after_for@5:
842842

843843
// tests.artifacts.Arrays.static_size.StaticSizeContract.test_arc4_bool[routing]() -> void:
844844
test_arc4_bool:
845-
// tests/artifacts/Arrays/static_size.py:143
845+
// tests/artifacts/Arrays/static_size.py:142
846846
// arr.append(arc4.Bool(Txn.sender == Txn.receiver))
847847
txn Sender
848848
txn Receiver
@@ -851,7 +851,7 @@ test_arc4_bool:
851851
intc_0 // 0
852852
uncover 2
853853
setbit
854-
// tests/artifacts/Arrays/static_size.py:144
854+
// tests/artifacts/Arrays/static_size.py:143
855855
// arr.append(arc4.Bool(Txn.sender != Txn.receiver))
856856
txn Sender
857857
txn Receiver
@@ -862,21 +862,21 @@ test_arc4_bool:
862862
setbit
863863
concat // on error: max array length exceeded
864864
dupn 2
865-
// tests/artifacts/Arrays/static_size.py:147
865+
// tests/artifacts/Arrays/static_size.py:146
866866
// dyn_arr.extend(arr)
867867
len
868-
// tests/artifacts/Arrays/static_size.py:146
868+
// tests/artifacts/Arrays/static_size.py:145
869869
// dyn_arr = arc4.DynamicArray[arc4.Bool]()
870870
bytec 4 // 0x0000
871-
// tests/artifacts/Arrays/static_size.py:147
871+
// tests/artifacts/Arrays/static_size.py:146
872872
// dyn_arr.extend(arr)
873873
dig 2
874874
uncover 2
875875
intc_2 // 8
876876
callsub dynamic_array_concat_bits
877877
dup
878878
cover 2
879-
// tests/artifacts/Arrays/static_size.py:148
879+
// tests/artifacts/Arrays/static_size.py:147
880880
// assert dyn_arr.length == 2, "expected correct length"
881881
dup
882882
intc_0 // 0
@@ -887,14 +887,14 @@ test_arc4_bool:
887887
pushint 2
888888
==
889889
assert // expected correct length
890-
// tests/artifacts/Arrays/static_size.py:149
890+
// tests/artifacts/Arrays/static_size.py:148
891891
// assert dyn_arr.bytes.length == 3, "expected 3 bytes"
892892
dig 1
893893
len
894894
pushint 3
895895
==
896896
assert // expected 3 bytes
897-
// tests/artifacts/Arrays/static_size.py:150
897+
// tests/artifacts/Arrays/static_size.py:149
898898
// assert dyn_arr[0] == (Txn.sender == Txn.receiver), "expected correct value at 0"
899899
dup
900900
assert // index access is out of bounds
@@ -912,7 +912,7 @@ test_arc4_bool:
912912
==
913913
==
914914
assert // expected correct value at 0
915-
// tests/artifacts/Arrays/static_size.py:151
915+
// tests/artifacts/Arrays/static_size.py:150
916916
// assert dyn_arr[1] == (Txn.sender != Txn.receiver), "expected correct value at 1"
917917
intc_1 // 1
918918
>
@@ -933,7 +933,7 @@ test_arc4_bool:
933933
intc_0 // 0
934934

935935
test_arc4_bool_for_header@2:
936-
// tests/artifacts/Arrays/static_size.py:154-156
936+
// tests/artifacts/Arrays/static_size.py:153-155
937937
// # note: not supported currently
938938
// # arr2.extend(dyn_array)
939939
// for b in dyn_arr:
@@ -952,7 +952,7 @@ test_arc4_bool_for_header@2:
952952
uncover 2
953953
setbit
954954
dig 3
955-
// tests/artifacts/Arrays/static_size.py:157
955+
// tests/artifacts/Arrays/static_size.py:156
956956
// arr2.append(b)
957957
swap
958958
concat // on error: max array length exceeded
@@ -964,14 +964,14 @@ test_arc4_bool_for_header@2:
964964

965965
test_arc4_bool_after_for@5:
966966
dig 1
967-
// tests/artifacts/Arrays/static_size.py:158
967+
// tests/artifacts/Arrays/static_size.py:157
968968
// assert arr2.length == 4, "expected correct length"
969969
dup
970970
len
971971
pushint 4
972972
==
973973
assert // expected correct length
974-
// tests/artifacts/Arrays/static_size.py:159
974+
// tests/artifacts/Arrays/static_size.py:158
975975
// assert arr2[0] == (Txn.sender == Txn.receiver), "expected correct value at 0"
976976
dup
977977
extract 0 1 // on error: index access is out of bounds
@@ -982,7 +982,7 @@ test_arc4_bool_after_for@5:
982982
==
983983
==
984984
assert // expected correct value at 0
985-
// tests/artifacts/Arrays/static_size.py:160
985+
// tests/artifacts/Arrays/static_size.py:159
986986
// assert arr2[1] == (Txn.sender != Txn.receiver), "expected correct value at 1"
987987
dup
988988
extract 1 1 // on error: index access is out of bounds
@@ -993,7 +993,7 @@ test_arc4_bool_after_for@5:
993993
!=
994994
==
995995
assert // expected correct value at 1
996-
// tests/artifacts/Arrays/static_size.py:161
996+
// tests/artifacts/Arrays/static_size.py:160
997997
// assert arr2[2] == (Txn.sender == Txn.receiver), "expected correct value at 2"
998998
dup
999999
extract 2 1 // on error: index access is out of bounds
@@ -1004,7 +1004,7 @@ test_arc4_bool_after_for@5:
10041004
==
10051005
==
10061006
assert // expected correct value at 2
1007-
// tests/artifacts/Arrays/static_size.py:162
1007+
// tests/artifacts/Arrays/static_size.py:161
10081008
// assert arr2[3] == (Txn.sender != Txn.receiver), "expected correct value at 3"
10091009
extract 3 1 // on error: index access is out of bounds
10101010
intc_0 // 0
@@ -1015,15 +1015,15 @@ test_arc4_bool_after_for@5:
10151015
==
10161016
assert // expected correct value at 3
10171017
dig 4
1018-
// tests/artifacts/Arrays/static_size.py:164
1018+
// tests/artifacts/Arrays/static_size.py:163
10191019
// return arr.freeze()
10201020
dup
10211021
len
10221022
bytec 4 // 0x0000
10231023
cover 2
10241024
intc_2 // 8
10251025
callsub dynamic_array_concat_bits
1026-
// tests/artifacts/Arrays/static_size.py:140
1026+
// tests/artifacts/Arrays/static_size.py:139
10271027
// @arc4.abimethod()
10281028
bytec_1 // 0x151f7c75
10291029
swap
@@ -1035,7 +1035,7 @@ test_arc4_bool_after_for@5:
10351035

10361036
// tests.artifacts.Arrays.static_size.StaticSizeContract.xtra() -> uint64, uint64, bytes, bytes, bytes:
10371037
xtra:
1038-
// tests/artifacts/Arrays/static_size.py:127
1038+
// tests/artifacts/Arrays/static_size.py:126
10391039
// self.count += 1
10401040
intc_0 // 0
10411041
bytec_2 // "count"
@@ -1046,23 +1046,23 @@ xtra:
10461046
bytec_2 // "count"
10471047
dig 1
10481048
app_global_put
1049-
// tests/artifacts/Arrays/static_size.py:129
1049+
// tests/artifacts/Arrays/static_size.py:128
10501050
// a=Txn.num_app_args,
10511051
txn NumAppArgs
1052-
// tests/artifacts/Arrays/static_size.py:131
1052+
// tests/artifacts/Arrays/static_size.py:130
10531053
// c=Txn.sender,
10541054
txn Sender
1055-
// tests/artifacts/Arrays/static_size.py:132
1055+
// tests/artifacts/Arrays/static_size.py:131
10561056
// d=self.more(),
10571057
callsub more
1058-
// tests/artifacts/Arrays/static_size.py:133
1058+
// tests/artifacts/Arrays/static_size.py:132
10591059
// e=BigUInt(self.count),
10601060
intc_0 // 0
10611061
bytec_2 // "count"
10621062
app_global_get_ex
10631063
assert // check self.count exists
10641064
itob
1065-
// tests/artifacts/Arrays/static_size.py:128-134
1065+
// tests/artifacts/Arrays/static_size.py:127-133
10661066
// return Xtra(
10671067
// a=Txn.num_app_args,
10681068
// b=self.count,
@@ -1077,7 +1077,7 @@ xtra:
10771077

10781078
// tests.artifacts.Arrays.static_size.StaticSizeContract.more() -> bytes:
10791079
more:
1080-
// tests/artifacts/Arrays/static_size.py:138
1080+
// tests/artifacts/Arrays/static_size.py:137
10811081
// return More(foo=arc4.UInt64(self.count + 1), bar=arc4.UInt64(self.count * self.count))
10821082
intc_0 // 0
10831083
bytec_2 // "count"

0 commit comments

Comments
 (0)