Skip to content

Commit c1b17d9

Browse files
authored
Create a quine to test app_params_get AppApprovalProgram (#2682)
I made a TEAL quine to test the output of app_params_get AppApprovalProgram for the current program. It's mostly for fun but this does strengthen the tests for app_params_get.
1 parent 5fd3fcb commit c1b17d9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

test/scripts/e2e_subs/teal-app-params.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ gcmd="goal -w ${WALLET}"
1717

1818
ACCOUNT=$(${gcmd} account list|awk '{ print $3 }')
1919

20-
APPID=$(${gcmd} app create --creator "$ACCOUNT" --approval-prog=${TEAL}/app-params.teal --clear-prog=${TEAL}/approve-all.teal --global-byteslices 1 --global-ints 2 --local-byteslices 3 --local-ints 4 --extra-pages 2 --app-arg "addr:$ACCOUNT" | grep Created | awk '{ print $6 }')
20+
APPID=$(${gcmd} app create --creator "$ACCOUNT" --approval-prog=${TEAL}/app-params.teal --clear-prog=${TEAL}/approve-all.teal --global-byteslices 1 --global-ints 2 --local-byteslices 3 --local-ints 4 --extra-pages 2 --app-arg "addr:$ACCOUNT" | grep Created | awk '{ print $6 }')
2121

2222
ACCOUNTB=$(${gcmd} account new|awk '{ print $6 }')
2323
${gcmd} clerk send -f "$ACCOUNT" -t "$ACCOUNTB" -a 1000000
2424

2525
# Now call from a different account
2626
${gcmd} app call --app-id="$APPID" --from="$ACCOUNTB" --app-arg "addr:$ACCOUNT"
2727

28+
# The below checks use quine.teal to test "app_params_get AppApprovalProgram"
2829

30+
# Verify "app_params_get AppApprovalProgram" works on create
31+
APPID_2=$(${gcmd} app create --creator "$ACCOUNTB" --approval-prog=${TEAL}/quine.teal --clear-prog=${TEAL}/approve-all.teal --global-byteslices 0 --global-ints 0 --local-byteslices 0 --local-ints 0 --extra-pages 0 | grep Created | awk '{ print $6 }')
32+
33+
# Verify "app_params_get AppApprovalProgram" works on regular app call
34+
${gcmd} app call --app-id="$APPID_2" --from="$ACCOUNTB"
35+
36+
# Verify "app_params_get AppApprovalProgram" works on update
37+
${gcmd} app update --app-id="$APPID_2" --from="$ACCOUNTB" --approval-prog=${TEAL}/approve-all.teal --clear-prog=${TEAL}/approve-all.teal
2938

3039
date "+${scriptname} OK %Y%m%d_%H%M%S"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma version 5
2+
// To modify the program:
3+
// 1. Replace the first line with `pushbytes ""`.
4+
// 2. Compile the program.
5+
// 3. Replace the first line with `pushbytes <compiled bytecode>`
6+
// 4. Update the varuint length of the new bytecode (line 11)
7+
// 5. The quine is complete. Compile again.
8+
pushbytes 0x0580004957000280011a504f0149570300505081007200441243
9+
dup
10+
extract 0 2
11+
pushbytes 0x1a // the varuint length of 0x0580...
12+
concat
13+
uncover 1
14+
dup
15+
extract 3 0 // the range here must be updated if the varuint length is longer than 1 byte
16+
concat
17+
concat // after this line the whole program is on the stack
18+
pushint 0
19+
app_params_get AppApprovalProgram
20+
assert
21+
==
22+
return

0 commit comments

Comments
 (0)