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

go-algorand 3.2.1-stable #3279

Merged
merged 146 commits into from
Dec 7, 2021
Merged
Changes from 1 commit
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
9fe1bf4
Fix dryrun crash on rewards calculation (#2894)
algorandskiy Sep 15, 2021
bc46c94
use matrix for CircleCI config (#2864)
cce Sep 16, 2021
4b67562
Enable debugging itxn programs (#2900)
algorandskiy Sep 16, 2021
275e1f3
Add `indexerLedgerForEval` interface (#2897)
tolikzinovyev Sep 17, 2021
dbab85f
Fix random failures TestWaitAndAddConnectionTimeLongtWindow (#2903)
algonautshant Sep 17, 2021
83837ac
Fix unit test (#2926)
tsachiherman Sep 20, 2021
5c0de9c
ledger: move account totals calculation to StateDelta (#2922)
tsachiherman Sep 21, 2021
e9900a3
Support arm cross compile (#2923)
bricerisingalgorand Sep 21, 2021
01d853f
Rotate Travis Env Variables and Remove codecov Env variable (#2934)
algobarb Sep 21, 2021
e4842fc
TestRequestBlockBytesErrors: Various fixes (#2928)
algonautshant Sep 22, 2021
8b0dda7
Remove time ledger tracker as not used (#2937)
algorandskiy Sep 22, 2021
e69b10d
readme grammar change (#2938)
yaovi-a Sep 22, 2021
e4fbb1d
fix EvalForIndexer (#2941)
tsachiherman Sep 23, 2021
a196929
Cache creators in cow base. (#2939)
tolikzinovyev Sep 23, 2021
ee0a715
testing: fix TestLatestSigsFromThisNode (#2940)
algonautshant Sep 23, 2021
7451e3e
Add ABI encoding support (#2807)
ahangsu Sep 25, 2021
2faace9
e2e tests for log (#2950)
shiqizng Sep 25, 2021
073717e
Add application account into a dryrun req created by goal (#2945)
algorandskiy Sep 25, 2021
7991a84
e2e tests for axfer, acfg, and afrz inner txns (#2947)
shiqizng Sep 27, 2021
96b16ff
Lots of testing convenience improvements, including e2e python (#2936)
jannotti Sep 27, 2021
e40b7ef
Enable cost and fee pooling in tealdbg (#2954)
algorandskiy Sep 28, 2021
412aef5
testing: metrics_delta.py fixes (#2962)
brianolson Sep 28, 2021
1202d32
ledger: refactor the ledger Totals (#2846)
tsachiherman Sep 29, 2021
7f3180a
Merge branch 'rel/stable' into release3.0.1-mergeback-manual
algojack Sep 29, 2021
16de1d8
Remove buildnumber.dat and genesistimestamp.dat files.
algojack Sep 29, 2021
734e727
Merge pull request #2971 from algorand/release3.0.1-mergeback-manual
algojohnlee Sep 29, 2021
4ed1d8e
fix flaky axfer txn e2e test (#2973)
shiqizng Sep 30, 2021
fbd75f7
Extended logic eval error (#2975)
algorandskiy Sep 30, 2021
f17f73e
Start work on Teal 6 (AVM 1.1) (#2974)
jannotti Oct 2, 2021
69aace5
transaction sync (#2718)
tsachiherman Oct 4, 2021
0b99cf8
Update the Version, BuildNumber, genesistimestamp.data
Algo-devops-service Oct 5, 2021
c579bf6
Inner groups (#3009)
jannotti Oct 7, 2021
6887d0e
Disable the participation key refresh on the TestPartitionHalfOffline…
tsachiherman Oct 7, 2021
c59326f
Added Participation Key Expiration Check (#2924)
AlgoStephenAkiki Oct 7, 2021
ff8139a
ledger: preload resources argument in EvalForIndexer (#3019)
tsachiherman Oct 8, 2021
32e131c
Move accountdb schema migration to trackerdb.go (#2984)
algorandskiy Oct 8, 2021
7357acf
Increase machine size to large and use consistent parallelism for cir…
egieseke Oct 8, 2021
e00cde0
Don't set dontReportFailures for Fail (#3018)
algonautshant Oct 8, 2021
83740b4
Increase machine size to large and use consistent parallelism for cir…
egieseke Oct 8, 2021
239921a
ledger: refactor evaluator into an internal package (#2983)
tsachiherman Oct 8, 2021
3c9e9e9
fix bug in rekey test. (#3026)
tsachiherman Oct 8, 2021
0d5b66e
fix regression (#3029)
tsachiherman Oct 9, 2021
e490f05
testing: make the TestMultiThreaded run at a constant time (#3035)
tsachiherman Oct 11, 2021
8568442
txnsync: fix potential race during TestBasicCatchpointCatchup (#3033)
tsachiherman Oct 11, 2021
4c45443
ledger: move StartEvaluator parameters into a parameters object (#3030)
tsachiherman Oct 11, 2021
6f96443
Fix regression in TestReproducibleCatchpointLabels (#3037)
tsachiherman Oct 11, 2021
a516544
Removing integration tests from travis steps (#3023)
algojack Oct 11, 2021
c4bbdf8
Adjust TenNodesDistributedMultiWallet.json to use smaller key dilutio…
tsachiherman Oct 12, 2021
e86c53f
testing: remove redundant checking from TestParticipationAccountsExpi…
AlgoStephenAkiki Oct 12, 2021
da60399
handle is left open in importRootKeys (#3039)
algonautshant Oct 12, 2021
83bcaaa
Fix global-state-schema key name in REST API spec (#2972)
algorandskiy Oct 13, 2021
a957519
ledger: Implement LookupAgreement (#3046)
algorandskiy Oct 13, 2021
c4bfc26
Use LookupAgreement AlgorandFullNode.VotingKeys() (#3050)
algorandskiy Oct 13, 2021
3572e1f
Reorder round query and transaction sending. (#3049)
tsachiherman Oct 13, 2021
44e85be
testing: remove account balance checks (#3054)
AlgoStephenAkiki Oct 14, 2021
754276b
fixed off-by-one error in the assembler's typeDig() and improved unit…
algoidurovic Oct 14, 2021
507eb53
Allow all trackers committing into DB (#3014)
algorandskiy Oct 14, 2021
5c7e273
Move deploy from TravisCI to CircleCI (#3075)
algojack Oct 14, 2021
1e87c71
Move deploy from TravisCI to CircleCI (#3075)
algojack Oct 14, 2021
019571e
ledger: remove duplicate testing of accounts totals (#3053)
tsachiherman Oct 14, 2021
abd31a2
Merge pull request #2995 from Algo-devops-service/relbeta3.1.0
algojohnlee Oct 14, 2021
ffb49ef
Fixing CircleCI deploy for Betanet and Stablenet (#3077)
algojack Oct 15, 2021
98d25e2
Fixing CircleCI deploy for Betanet and Stablenet (#3077)
algojack Oct 15, 2021
fd82cd9
Merge branch 'rel/beta' into relbeta3.1.0
algojohnlee Oct 15, 2021
a4cfa1f
Merge pull request #3079 from Algo-devops-service/relbeta3.1.0
algojohnlee Oct 15, 2021
b9c6032
Fix missing TX registration (#3080)
tsachiherman Oct 16, 2021
bcd77ee
changing circleci workflow name (#2887)
algojack Oct 18, 2021
78317e8
Make bytes and pushbytes check their immediate better (and similarly)…
jannotti Oct 18, 2021
d286fd2
Fix missing TX registration (#3080)
tsachiherman Oct 16, 2021
9d0cedb
Bumping buildnumber.dat to 1 for 3.1.1
algojack Oct 18, 2021
dbd0ec9
Merge pull request #3090 from algorand/rel/beta-3.1.1
algojohnlee Oct 18, 2021
f0017f3
catchup: avoid requesting blocks that aren't needed by the ledger (#3…
tsachiherman Oct 19, 2021
bd4cd9a
Optimize circleci machine sizes and parallelism (#3095)
algojack Oct 19, 2021
48d4075
network: add initial support for latency tracking (#3028)
tsachiherman Oct 19, 2021
e853e2e
txnsync: implement missing bridge between txnsync and classic transac…
tsachiherman Oct 20, 2021
facfb03
txnsync: implement missing bridge between txnsync and classic transac…
tsachiherman Oct 20, 2021
2eb56bb
Bump build number
onetechnical Oct 20, 2021
1e5603c
Refactoring ABI encoding feature (#3055)
ahangsu Oct 20, 2021
c2054e5
Increase wait time for the transaction to be included. (#3098)
tsachiherman Oct 20, 2021
53cf013
Merge pull request #3103 from algorand/rel/beta-3.1.2
algojohnlee Oct 20, 2021
38b08a0
tealdbg: use associated group index instead of global (#3111)
barnjamin Oct 21, 2021
473fa37
skip fields that cant be displayed anyway (#3119)
barnjamin Oct 21, 2021
57a3306
Add buildpulse (#3051)
cce Oct 21, 2021
f17f8f6
Add err to solicitedAsyncTxHandler.loop log message (#3123)
cce Oct 21, 2021
28e9eca
Make fields in ledger.Creatable public. (#3125)
tolikzinovyev Oct 21, 2021
17429d5
Enable totals calculation in eval for indexer. (#3124)
tolikzinovyev Oct 21, 2021
2c79cfd
update the websocket library. (#3131)
tsachiherman Oct 22, 2021
b93ad64
Improve Bandwidth Estimation in Txnsync (#3096)
Oct 24, 2021
ff71d92
txnsync: fix potential race during TestBasicCatchpointCatchup (#3033)
tsachiherman Oct 11, 2021
83031f6
network: add initial support for latency tracking (#3028)
tsachiherman Oct 19, 2021
f65e269
Add err to solicitedAsyncTxHandler.loop log message (#3123)
cce Oct 21, 2021
5fc9a5e
update the websocket library. (#3131)
tsachiherman Oct 22, 2021
05673ad
Improve Bandwidth Estimation in Txnsync (#3096)
Oct 24, 2021
72a1717
catchup: ignore benign evaluator failures (#3135)
tsachiherman Oct 25, 2021
9c3f403
Trim the whitespaces before/after each line of TEAL code (#3128)
ahangsu Oct 25, 2021
ca3e877
txnsync: delete-able incoming message queue (#3126)
tsachiherman Oct 25, 2021
cc801ba
txnsync: delete-able incoming message queue (#3126)
tsachiherman Oct 25, 2021
b79856f
catchup: ignore benign evaluator failures (#3135)
tsachiherman Oct 25, 2021
615fee2
Bump buildnumber.dat
onetechnical Oct 25, 2021
378816d
Merge pull request #3139 from algorand/rel/beta-3.1.3
algojohnlee Oct 26, 2021
9bb4154
Allow getting versions for any package. (#2935)
winder Oct 26, 2021
e2d6349
Disabling re-building of binaries in circleci during upload stage (#3…
algojack Oct 26, 2021
729e597
ledger: refactor ledger internal tests (#3149)
tsachiherman Oct 27, 2021
024eddb
update sys to resolve go1.17 build error (#3157)
ahangsu Oct 28, 2021
c56ecc2
Make heapwatch.py port configurable (#3143)
bricerisingalgorand Oct 28, 2021
246ac13
Reverse the network protocols ordering to de-prioritize the txnsync u…
tsachiherman Oct 28, 2021
465c191
Removing all but windows builds from Travis (#3154)
algojack Oct 28, 2021
175c1f4
Add c5d.4xlarge and c5d.18xlarge us-east-2 to hosttemplates.json (#3160)
algobarb Oct 29, 2021
9ca31f8
Move Local structure definition to localTemplate (#3161)
tsachiherman Oct 29, 2021
b8ac4ba
ledger: refactor maxPaysetHint -> avarageEncodedTxnSizeHint (#3162)
tsachiherman Oct 29, 2021
5eb09af
ledger: do final validation in `endOfBlock()` (#3132)
tolikzinovyev Oct 29, 2021
21c752e
txnsync: Use dynamic maxEncodedTransactionGroups (#3168)
Oct 29, 2021
385afd5
Add unit test to avoid new `string` fields (#3101)
jasonpaulos Oct 30, 2021
168cfe5
make proposal assembly time configurable (#3165)
tsachiherman Nov 1, 2021
009b798
Fix panic on closing nil db (#3175)
algonautshant Nov 3, 2021
8ff58cb
Participation keys interface: Removed Register handler (#3130)
AlgoStephenAkiki Nov 3, 2021
3a6238d
Fix typo in batchverifier.go (#3176)
StylishTriangles Nov 3, 2021
e10fe1c
txnsync: rollback (#3177)
tsachiherman Nov 3, 2021
9b39c66
roundCowBase: use lookup() instead of going to ledger directly. (#3173)
tolikzinovyev Nov 3, 2021
f72764b
ledger: create catchpoint tracker (#3085)
tsachiherman Nov 4, 2021
63e16ed
Report assembly error strings for compile API endpoint (#3190)
algochoi Nov 6, 2021
d3bbe62
Add ABI support to goal (#3088)
ahangsu Nov 9, 2021
3937401
Clarify get_ex opcode docs (#3208)
barnjamin Nov 13, 2021
387f6a6
Participation Key Interface (#3164)
winder Nov 15, 2021
8441d91
use large VMs for integration tests (#3201)
cce Nov 15, 2021
eea0a75
ledger refactoring: fix catchpoint tracker (#3214)
tsachiherman Nov 16, 2021
e44bdd6
update go mod/sum to include updated algorand/websocket (#3221)
tsachiherman Nov 17, 2021
38329e1
agreement: handle pseudonode enqueueing failures (#2741)
tsachiherman Nov 17, 2021
83ca8ec
goal abi method outfile checking (#3204)
barnjamin Nov 18, 2021
c0d7822
Merge branch 'rel/beta'
onetechnical Nov 18, 2021
4634e98
Merge pull request #3230 from algorand/update-master-relbeta3.1.3
algojohnlee Nov 18, 2021
32d3f3d
Update the Version, BuildNumber, genesistimestamp.data
Algo-devops-service Nov 18, 2021
9905421
Adding-clean-target-to-ci-build-target (#2948)
algojack Nov 19, 2021
0b0f97b
Fix OnCompletion flag for `goal app method` (#3228)
jasonpaulos Nov 19, 2021
116c06e
Support transaction arguments for `goal app method` (#3233)
jasonpaulos Nov 22, 2021
9807eab
CI: use libboost-math-dev instead of libboost-all-dev (#3223)
cce Nov 22, 2021
6cb3a52
testing: fixes to rest-participation-key e2e test (#3238)
algonautshant Nov 23, 2021
52b528b
testing: interactive mode for e2e testing (#3227)
algonautshant Nov 23, 2021
8aa0728
Merge pull request #3231 from Algo-devops-service/relbeta3.2.0
algojohnlee Nov 23, 2021
597fc63
Make dev-mode tests less flaky. (#3252)
winder Nov 29, 2021
5339cf0
adding libtool to ubuntu deps (#3251)
barnjamin Nov 29, 2021
715f511
Fix error shadowing in Eval (#3258)
algorandskiy Nov 30, 2021
54db1c7
Disable flaky test. (#3256)
winder Nov 30, 2021
4e34eba
Merge branch 'master' into relbeta3.2.1
Algo-devops-service Nov 30, 2021
305d7ab
Update the Version, BuildNumber, genesistimestamp.data
Algo-devops-service Nov 30, 2021
2baf39b
Merge pull request #3260 from Algo-devops-service/relbeta3.2.1
algojohnlee Dec 2, 2021
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
e2e tests for axfer, acfg, and afrz inner txns (#2947)
Similar to app-accounts test, but tests all sorts of asset txns instead of pays.
shiqizng authored Sep 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7991a84925b7840b36dd81e7c1949d6c6ccbaac2
267 changes: 267 additions & 0 deletions test/scripts/e2e_subs/app-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
#!/bin/bash

filename=$(basename "$0")
scriptname="${filename%.*}"
date "+${scriptname} start %Y%m%d_%H%M%S"


my_dir="$(dirname "$0")"
source "$my_dir/rest.sh" "$@"
function rest() {
curl -q -s -H "Authorization: Bearer $PUB_TOKEN" "$NET$1"
}

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

WALLET=$1

TEAL=test/scripts/e2e_subs/tealprogs

gcmd="goal -w ${WALLET}"

ACCOUNT=$(${gcmd} account list|awk '{ print $3 }')
# Create a smaller account so rewards won't change balances.
SMALL=$(${gcmd} account new | awk '{ print $6 }')
# Under one algo receives no rewards
${gcmd} clerk send -a 1000000 -f "$ACCOUNT" -t "$SMALL"

function balance {
acct=$1; shift
goal account balance -a "$acct" | awk '{print $1}'
}

[ "$(balance "$ACCOUNT")" = 999998999000 ]
[ "$(balance "$SMALL")" = 1000000 ]

function created_assets {
acct=$1;
goal account info -a "$acct" | awk '/Created Assets:/,/Held Assets:/' | grep "ID*" | awk -F'[, ]' '{print $4}'
}

function created_supply {
acct=$1;
goal account info -a "$acct" | awk '/Created Assets:/,/Held Assets:/' | grep "ID*" | awk -F'[, ]' '{print $7}'
}

function asset_bal {
acct=$1;
goal account info -a "$acct" | awk '/Held Assets:/,/Created Apps:/' | grep "ID*" | awk -F'[, ]' '{print $7}'
}

function asset_ids {
acct=$1;
goal account info -a "$acct" | awk '/Held Assets:/,/Created Apps:/' | grep "ID*" | awk -F'[, ]' '{print $2}'
}
#
function assets {
acct=$1;
goal account info -a "$acct" | awk '/Held Assets:/,/Created Apps:/' | grep "ID*" | awk -F'[, ]' '{print $4}'
}

APPID=$(${gcmd} app create --creator "${SMALL}" --approval-prog=${TEAL}/assets-escrow.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | grep Created | awk '{ print $6 }')
[ "$(balance "$SMALL")" = 999000 ] # 1000 fee

function appl {
method=$1; shift
${gcmd} app call --app-id="$APPID" --app-arg="str:$method" "$@"
}

function app-txid {
# When app (call or optin) submits, this is how the txid is
# printed. Not in appl() because appl is also used with -o to
# create tx
grep -o -E 'txid [A-Z0-9]{52}' | cut -c 6- | head -1
}

function asset-id {
grep -o -E 'index [A-Z0-9]+'| cut -c 7-
}

APPACCT=$(python -c "import algosdk.encoding as e; print(e.encode_address(e.checksum(b'appID'+($APPID).to_bytes(8, 'big'))))")
[ "$(balance "$SMALL")" = 999000 ] # 1000 fee

function asset-create {
amount=$1; shift
${gcmd} asset create --creator "$SMALL" --total "$amount" --decimals 0 "$@"
}

function asset-deposit {
amount=$1;shift
ID=$1; shift
${gcmd} asset send -f "$SMALL" -t "$APPACCT" -a "$amount" --assetid "$ID" "$@"
}

function asset-optin {
${gcmd} asset send -a 0 "$@"
}

function clawback_addr {
grep -o -E 'Clawback address: [A-Z0-9]{58}' | awk '{print $3}'
}

function payin {
amount=$1; shift
${gcmd} clerk send -f "$SMALL" -t "$APPACCT" -a "$amount" "$@"
}

T=$TEMPDIR

function sign {
${gcmd} clerk sign -i "$T/$1.tx" -o "$T/$1.stx"
}

TXID=$(${gcmd} app optin --app-id "$APPID" --from "${SMALL}" | app-txid)
# Rest succeeds, no stray inner-txn array
[ "$(rest "/v2/transactions/pending/$TXID" | jq '.["inner-txn"]')" == null ]
[ "$(balance "$SMALL")" = 998000 ] # 1000 fee

ASSETID=$(asset-create 1000000 --name "e2e" --unitname "e" | asset-id)
[ "$(balance "$SMALL")" = 997000 ] # 1000 fee

${gcmd} clerk send -a 1000000 -f "$ACCOUNT" -t "$APPACCT"
appl "optin():void" --foreign-asset="$ASSETID" --from="$SMALL"
[ "$(balance "$APPACCT")" = 999000 ] # 1000 fee
[ "$(balance "$SMALL")" = 996000 ]

appl "deposit():void" -o "$T/deposit.tx" --from="$SMALL"
asset-deposit 1000 $ASSETID -o "$T/axfer1.tx"
cat "$T/deposit.tx" "$T/axfer1.tx" | ${gcmd} clerk group -i - -o "$T/group.tx"
sign group
${gcmd} clerk rawsend -f "$T/group.stx"

[ "$(asset_ids "$SMALL")" = $ASSETID ] # asset ID
[ "$(asset_bal "$SMALL")" = 999000 ] # asset balance
[ "$(asset_ids "$APPACCT")" = $ASSETID ]
[ "$(asset_bal "$APPACCT")" = 1000 ]
[ "$(balance "$SMALL")" = 994000 ] # 2 fees
[ "$(balance "$APPACCT")" = 999000 ]

# Withdraw 100 in app. Confirm that inner txn is visible to transaction API.
TXID=$(appl "withdraw(uint64):void" --app-arg="int:100" --foreign-asset="$ASSETID" --from="$SMALL" | app-txid)
[ "$(rest "/v2/transactions/pending/$TXID" \
| jq '.["inner-txns"][0].txn.txn.aamt')" = 100 ]
[ "$(rest "/v2/transactions/pending/$TXID?format=msgpack" | msgpacktool -d \
| jq '.["inner-txns"][0].txn.txn.type')" = '"axfer"' ]
# Now confirm it's in blocks API (this time in our internal form)
ROUND=$(rest "/v2/transactions/pending/$TXID" | jq '.["confirmed-round"]')
rest "/v2/blocks/$ROUND" | jq .block.txns[0].dt.itx

[ "$(asset_bal "$SMALL")" = 999100 ] # 100 asset withdrawn
[ "$(asset_bal "$APPACCT")" = 900 ] # 100 asset withdrawn
[ "$(balance "$SMALL")" = 993000 ] # 1 fee
[ "$(balance "$APPACCT")" = 998000 ] # fee paid by app

appl "withdraw(uint64):void" --app-arg="int:100" --foreign-asset="$ASSETID" --fee 2000 --from="$SMALL"
[ "$(asset_bal "$SMALL")" = 999200 ] # 100 asset withdrawn
[ "$(balance "$SMALL")" = 991000 ] # 2000 fee
[ "$(asset_bal "$APPACCT")" = 800 ] # 100 asset withdrawn
[ "$(balance "$APPACCT")" = 998000 ] # fee credit used

# Try to withdraw too much
appl "withdraw(uint64):void" --app-arg="int:1000" --foreign-asset="$ASSETID" --from="$SMALL" && exit 1
[ "$(asset_bal "$SMALL")" = 999200 ] # no change
[ "$(asset_bal "$APPACCT")" = 800 ] # no change
[ "$(balance "$SMALL")" = 991000 ]
[ "$(balance "$APPACCT")" = 998000 ]

# Show that it works AT exact asset balance
appl "withdraw(uint64):void" --app-arg="int:800" --foreign-asset="$ASSETID" --from="$SMALL"
[ "$(asset_bal "$SMALL")" = 1000000 ]
[ "$(asset_bal "$APPACCT")" = 0 ]
[ "$(balance "$SMALL")" = 990000 ]
[ "$(balance "$APPACCT")" = 997000 ]

USER=$(${gcmd} account new | awk '{ print $6 }') #new account
${gcmd} clerk send -a 1000000 -f "$ACCOUNT" -t "$USER" #fund account
asset-optin -f "$USER" -t "$USER" --assetid "$ASSETID" #opt in to asset
# SET $USER as clawback address
${gcmd} asset config --manager $SMALL --assetid $ASSETID --new-clawback $USER
cb_addr=$(${gcmd} asset info --assetid $ASSETID | clawback_addr)
[ "$cb_addr" = "$USER" ]
${gcmd} asset send -f "$SMALL" -t "$USER" -a "1000" --assetid "$ASSETID" --clawback "$USER"
[ $(asset_bal "$USER") = 1000 ]
[ $(asset_bal "$SMALL") = 999000 ]
# rekey $USER to "$APPACCT"
${gcmd} clerk send --from "$USER" --to "$USER" -a 0 --rekey-to "$APPACCT"
# $USER should still have clawback auth. should have been authorized by "$APPACCT"
${gcmd} asset send -f "$SMALL" -t "$USER" -a "1000" --assetid "$ASSETID" --clawback "$USER" && exit 1

USER2=$(${gcmd} account new | awk '{ print $6 }') #new account
${gcmd} clerk send -a 1000000 -f "$ACCOUNT" -t "$USER2" #fund account
asset-optin -f "$USER2" -t "$USER2" --assetid "$ASSETID" #opt in to asset
# set $APPACCT as clawback address on asset
${gcmd} asset config --manager $SMALL --assetid $ASSETID --new-clawback $APPACCT
cb_addr=$(${gcmd} asset info --assetid $ASSETID | clawback_addr)
[ "$cb_addr" = "$APPACCT" ] #app is set as clawback address
# transfer asset from $SMALL to $USER
appl "transfer(uint64):void" --app-arg="int:1000" --foreign-asset="$ASSETID" --from="$SMALL" --app-account="$USER2"
[ $(asset_bal "$USER2") = 1000 ]
[ $(asset_bal "$SMALL") = 998000 ]
# transfer asset from $USER to $SMALL
appl "transfer(uint64):void" --app-arg="int:100" --foreign-asset="$ASSETID" --from="$USER2" --app-account="$SMALL"
[ $(asset_bal "$USER2") = 900 ]
[ $(asset_bal "$SMALL") = 998100 ]

# opt in more assets
ASSETID2=$(asset-create 1000000 --name "alpha" --unitname "a" | asset-id)
appl "optin():void" --foreign-asset="$ASSETID2" --from="$SMALL"
ASSETID3=$(asset-create 1000000 --name "beta" --unitname "b" | asset-id)
appl "optin():void" --foreign-asset="$ASSETID3" --from="$SMALL"

IDs="$ASSETID
$ASSETID2
$ASSETID3"
[[ "$(asset_ids "$APPACCT")" = $IDs ]] # account has 3 assets

# opt out of assets
appl "close():void" --foreign-asset="$ASSETID2" --from="$SMALL"
IDs="$ASSETID
$ASSETID3"
[[ "$(asset_ids "$APPACCT")" = $IDs ]] # account has 2 assets
appl "close():void" --foreign-asset="$ASSETID" --from="$SMALL"
appl "close():void" --foreign-asset="$ASSETID3" --from="$SMALL"
[[ "$(asset_ids "$APPACCT")" = "" ]] # account has no assets

# app creates asset
appl "create(uint64):void" --app-arg="int:1000000" --from="$SMALL"
[ "$(created_assets "$APPACCT")" = "X" ]
[ "$(created_supply "$APPACCT")" = 1000000 ]

# mint asset
APPASSETID=$(asset_ids "$APPACCT")
asset-optin -f "$SMALL" -t "$SMALL" --assetid "$APPASSETID" #opt in to asset
appl "mint():void" --from="$SMALL" --foreign-asset="$APPASSETID" -o "$T/mint.tx"
payin 1000 -o "$T/pay1.tx"
cat "$T/mint.tx" "$T/pay1.tx" | ${gcmd} clerk group -i - -o "$T/group.tx"
sign group
${gcmd} clerk rawsend -f "$T/group.stx"

IDs="$ASSETID
$ASSETID2
$ASSETID3
$APPASSETID"
[[ "$(asset_ids "$SMALL")" = $IDs ]] # has new asset
[ "$(asset_bal "$SMALL" | awk 'FNR==4{print $0}')" = 1000 ] # correct balances
[ "$(asset_bal "$APPACCT")" = 999000 ] # 1k sent

# freeze asset
appl "freeze(uint64):void" --app-arg="int:1" --foreign-asset="$APPASSETID" --from="$SMALL"
# fail since asset is frozen on $SMALL
appl "mint():void" --from="$SMALL" -o "$T/mint.tx" --foreign-asset="$APPASSETID"
payin 1000 -o "$T/pay1.tx"
cat "$T/mint.tx" "$T/pay1.tx" | ${gcmd} clerk group -i - -o "$T/group.tx"
sign group
${gcmd} clerk rawsend -f "$T/group.stx" && exit 1
# unfreeze asset
appl "freeze(uint64):void" --app-arg="int:0" --foreign-asset="$APPASSETID" --from="$SMALL"
appl "mint():void" --from="$SMALL" -o "$T/mint.tx" --foreign-asset="$APPASSETID"
payin 1000 -o "$T/pay1.tx"
cat "$T/mint.tx" "$T/pay1.tx" | ${gcmd} clerk group -i - -o "$T/group.tx"
sign group
${gcmd} clerk rawsend -f "$T/group.stx"
[ "$(asset_bal "$SMALL" | awk 'FNR==4{print $0}')" = 2000 ] # minted 1000

date "+${scriptname} OK %Y%m%d_%H%M%S"
328 changes: 328 additions & 0 deletions test/scripts/e2e_subs/tealprogs/assets-escrow.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
#pragma version 5
// This application accepts these actions on assets
// optin():void - opt in the app to an asset
// close():void - opt out the app from an asset
// deposit():void - deposit assets on app and hold until withdraw is requested;
// update the asset balance in app's local state
// withdraw(uint64):void - withdraw assets from and update the asset balance in app's local state.
// approve if withdraw amount < balance
// transfer(uint64):void - app has clawback auth to transfer assets between accounts
// create(uint64):void - app creates assets
// mint():void - withdraw assets created by app
// freeze(uint64):void - freeze/unfreeze an asset on an account

// ApplicationID is zero in inital creation txn
txn ApplicationID
bz handle_createapp

// Handle possible OnCompletion type. We don't have to
// worry about handling ClearState, because the
// ClearStateProgram will execute in that case, not the
// ApprovalProgram.

txn OnCompletion
int NoOp
==
bnz handle_noop

txn OnCompletion
int OptIn
==
bnz handle_optin

txn OnCompletion
int CloseOut
==
bnz handle_closeout

txn OnCompletion
int UpdateApplication
==
bnz handle_updateapp

txn OnCompletion
int DeleteApplication
==
bnz handle_deleteapp
// Unexpected OnCompletion value. Should be unreachable.
err

handle_createapp:
int 1
return

handle_optin:
// Let anyone optin with a single txn, with no arguments. If
// it's not a single txn, fall through to handle_noop, so that
// a deposit can be made while opting in.
// We should standardize a behaviour like this in ABI.
global GroupSize
int 1
==
bz handle_noop
int 1
return

handle_noop:
// opt in app to asset to enable axfer
txn ApplicationArgs 0
byte "optin():void"
==
bz not_optin
byte "optin"
callsub debug

itxn_begin
int axfer
itxn_field TypeEnum

int 0
itxn_field AssetAmount

txna Assets 0
itxn_field XferAsset

global CurrentApplicationAddress
itxn_field AssetReceiver
itxn_submit

int 1
return
not_optin:
txn ApplicationArgs 0
byte "deposit():void"
==
bz not_deposit

byte "deposit"
callsub debug

// Handle a deposit. Next txn slot must axfer our app account
txn GroupIndex
int 1
+
dup
dup

gtxns TypeEnum
int axfer
==
assert

gtxns AssetReceiver
global CurrentApplicationAddress
==
assert

gtxns AssetAmount

// Track the amount this sender deposited in their local state
int 0
byte "balance"
dup2
app_local_get
uncover 3 // pull up the Amount
+
app_local_put

int 1
return
not_deposit:
txn ApplicationArgs 0
byte "withdraw(uint64):void"
==
bz not_withdraw

// Handle withdraw.

int 0
byte "balance"
dup2
app_local_get

// Subtract the request and replace. Rejects on underflow
txn ApplicationArgs 1
btoi
-
app_local_put

itxn_begin
int axfer
itxn_field TypeEnum

txna Assets 0
itxn_field XferAsset

txn ApplicationArgs 1
btoi
itxn_field AssetAmount

txn Sender
itxn_field AssetReceiver
itxn_submit

int 1
return
not_withdraw:
txn ApplicationArgs 0
byte "close():void"
==
bz not_close

// Handle close.
itxn_begin
int axfer
itxn_field TypeEnum

txna Assets 0
itxn_field XferAsset

int 0
itxn_field AssetAmount

txn Sender
itxn_field AssetReceiver

txn Sender
itxn_field AssetCloseTo
itxn_submit

int 1
return
not_close:
txn ApplicationArgs 0
byte "transfer(uint64):void"
==
bz not_transfer

// Handle transfer.
itxn_begin
int axfer
itxn_field TypeEnum

txna Assets 0
itxn_field XferAsset

txn ApplicationArgs 1
btoi
itxn_field AssetAmount

txn Sender
itxn_field AssetSender

txna Accounts 1
itxn_field AssetReceiver

itxn_submit

int 1
return

not_transfer:
txn ApplicationArgs 0
byte "create(uint64):void"
==
bz not_create
// Handle create.
itxn_begin
int acfg
itxn_field TypeEnum

txn ApplicationArgs 1
btoi
itxn_field ConfigAssetTotal
int 0
itxn_field ConfigAssetDecimals
byte "x"
itxn_field ConfigAssetUnitName
byte "X"
itxn_field ConfigAssetName
global CurrentApplicationAddress
itxn_field ConfigAssetFreeze

itxn_submit
int 1
return
not_create:
txn ApplicationArgs 0
byte "mint():void"
==
bz not_mint
// Handle mint. Next txn slot must pay our app account
txn GroupIndex
int 1
+
dup
dup

gtxns TypeEnum
int pay
==
assert

gtxns Receiver
global CurrentApplicationAddress
==
assert

// mint asset
itxn_begin
int axfer
itxn_field TypeEnum

txna Assets 0
itxn_field XferAsset

gtxns Amount
itxn_field AssetAmount

txn Sender
itxn_field AssetReceiver
itxn_submit

int 1
return
not_mint:
txn ApplicationArgs 0
byte "freeze(uint64):void"
==
bz not_freeze

//Handle freeze
itxn_begin
int afrz
itxn_field TypeEnum

txna Assets 0
itxn_field FreezeAsset

txn ApplicationArgs 1
btoi
itxn_field FreezeAssetFrozen

txn Sender
itxn_field FreezeAssetAccount

itxn_submit

int 1
return
not_freeze:
// Unknown call "method"
err

handle_closeout:
int 1
return

handle_updateapp:
handle_deleteapp:
txn Sender
global CreatorAddress
==
return
debug:
byte "debug"
swap
app_global_put
retsub