Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic teal #2126

Merged
merged 19 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test that v4 teal is not available early
  • Loading branch information
jannotti committed May 11, 2021
commit 0430d1c75f4b8b7f99c8d569fb284e7b22f9d815
4 changes: 2 additions & 2 deletions test/scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ python3 -m venv "${TEMPDIR}/ve"
. "${TEMPDIR}/ve/bin/activate"
"${TEMPDIR}/ve/bin/pip3" install --upgrade pip
"${TEMPDIR}/ve/bin/pip3" install --upgrade py-algorand-sdk cryptography
"${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} "$SRCROOT"/test/scripts/e2e_subs/*.sh
#"${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} "$SRCROOT"/test/scripts/e2e_subs/*.sh
for vdir in "$SRCROOT"/test/scripts/e2e_subs/v??; do
"${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} --version "$(basename "$vdir")" "$vdir"/*.sh
done
Expand All @@ -111,7 +111,7 @@ export TESTDIR=${TEMPDIR}
export TESTDATADIR=${SRCROOT}/test/testdata
export SRCROOT=${SRCROOT}

./e2e_go_tests.sh ${GO_TEST_ARGS}
#./e2e_go_tests.sh ${GO_TEST_ARGS}

rm -rf "${TEMPDIR}"

Expand Down
101 changes: 101 additions & 0 deletions test/scripts/e2e_subs/v26/teal-v3-only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

date '+teal-v2-only start %Y%m%d_%H%M%S'
jannotti marked this conversation as resolved.
Show resolved Hide resolved

set -e
set -x
set -o pipefail
export SHELLOPTS

WALLET=$1

gcmd="goal -w ${WALLET}"

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

# prints:
# Created new account with address UCTHHNBEAUWHDQWQI5DGQCTB7AR4CSVNU5YNPROAYQIT3Y3LKVDFAA5M6Q
ACCOUNTB=$(${gcmd} account new|awk '{ print $6 }')

cat >${TEMPDIR}/true.teal<<EOF
#pragma version 3
int 1
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right this is a remnant from the teal-v2 test, where I wanted to be clear that I had v3 code (where return was introduced). I think it still makes some sense here because of that, but the one below should be changed to some v4 opcode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I'm wrong. return was in v2. So it's entirely extraneous. I guess I got in the habit of doing that in tests when I wasn't sure of the stack.

EOF

${gcmd} clerk compile -o ${TEMPDIR}/true.lsig -s -a ${ACCOUNT} ${TEMPDIR}/true.teal

${gcmd} clerk send -f ${ACCOUNT} -t ${ACCOUNTB} -a 1000000 -L ${TEMPDIR}/true.lsig

${gcmd} clerk send -f ${ACCOUNT} -t ${ACCOUNTB} -a 1000000 -o ${TEMPDIR}/one.tx

${gcmd} clerk sign -L ${TEMPDIR}/true.lsig -i ${TEMPDIR}/one.tx -o ${TEMPDIR}/one.stx

${gcmd} clerk rawsend -f ${TEMPDIR}/one.stx

${gcmd} clerk dryrun -t ${TEMPDIR}/one.stx

ACCOUNT_TRUE=$(${gcmd} clerk compile -n ${TEMPDIR}/true.teal|awk '{ print $2 }')

${gcmd} clerk send --amount 1000000 --from ${ACCOUNT} --to ${ACCOUNT_TRUE}

${gcmd} clerk send --amount 10 --from-program ${TEMPDIR}/true.teal --to ${ACCOUNTB}

${gcmd} clerk send --amount 10 --from ${ACCOUNT_TRUE} --to ${ACCOUNTB} -o ${TEMPDIR}/true.tx

${gcmd} clerk sign -i ${TEMPDIR}/true.tx -o ${TEMPDIR}/true.stx --program ${TEMPDIR}/true.teal

${gcmd} clerk rawsend -f ${TEMPDIR}/true.stx

${gcmd} clerk inspect ${TEMPDIR}/true.stx

${gcmd} clerk compile -D ${TEMPDIR}/true.lsig

echo "#pragma version 1" | ${gcmd} clerk compile -
echo "#pragma version 2" | ${gcmd} clerk compile -
echo "#pragma version 3" | ${gcmd} clerk compile -



set +o pipefail
# v4 opcodes with v3 pragma fails
printf "#pragma version 3\nbegin: int 1\nb begin" | ${gcmd} clerk compile - 2>&1 | grep "back jump support"
set -o pipefail

# Although we are in an earlier version, v4 can be compiled, it just can't be used.
cat >${TEMPDIR}/true4.teal<<EOF
#pragma version 4
int 1
return
jannotti marked this conversation as resolved.
Show resolved Hide resolved
EOF


ACCOUNT_TRUE=$(${gcmd} clerk compile -n ${TEMPDIR}/true4.teal|awk '{ print $2 }')

${gcmd} clerk send --amount 1000000 --from ${ACCOUNT} --to ${ACCOUNT_TRUE}

set +o pipefail
${gcmd} clerk send --amount 10 --from-program ${TEMPDIR}/true4.teal --to ${ACCOUNTB} 2>&1 | grep "LogicSig.Logic version too new"
set -o pipefail


# Now, ensure it still fails, even if using the v3 program, if the
# retsub opcode is added. (That is, failure based on opcode choice,
# not just on the version marker.)

${gcmd} clerk compile ${TEMPDIR}/true.teal -o ${TEMPDIR}/true.lsig
# append "retsub" opcode to the true program (won't execute the opcode, but presence should cause fail)
# we can't assemble this, because it would be rejected
(cat ${TEMPDIR}/true.lsig; printf '\x89') > ${TEMPDIR}/retsub.lsig
# compute the escrow account for the retsub program
ACCOUNT_TRUE=$(python -c 'import algosdk, sys; print(algosdk.logic.address(sys.stdin.buffer.read()))' < ${TEMPDIR}/retsub.lsig)
# fund that escrow account
${gcmd} clerk send --amount 1000000 --from ${ACCOUNT} --to ${ACCOUNT_TRUE}
# try, and fail, to lsig with the retsub program
set +o pipefail
${gcmd} clerk send --amount 10 --from-program-bytes ${TEMPDIR}/retsub.lsig --to ${ACCOUNTB} 2>&1 | grep "illegal opcode"
set -o pipefail



date '+teal-v3-only OK %Y%m%d_%H%M%S'
29 changes: 29 additions & 0 deletions test/testdata/nettemplates/TwoNodes50EachV26.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Genesis": {
"NetworkName": "tbd",
"ConsensusProtocol": "https://github.com/algorandfoundation/specs/tree/ac2255d586c4474d4ebcf3809acccb59b7ef34ff",
"Wallets": [
{
"Name": "Wallet1",
"Stake": 50,
"Online": true
},
{
"Name": "Wallet2",
"Stake": 50,
"Online": true
}
]
},
"Nodes": [
{
"Name": "Primary",
"IsRelay": true,
"Wallets": [{ "Name": "Wallet1", "ParticipationOnly": false }]
},
{
"Name": "Node",
"Wallets": [{ "Name": "Wallet2", "ParticipationOnly": false }]
}
]
}