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

fix flaky axfer txn e2e test #2973

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Changes from all commits
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
43 changes: 21 additions & 22 deletions test/scripts/e2e_subs/app-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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"
${gcmd} clerk send -a 999000 -f "$ACCOUNT" -t "$SMALL"

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

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

function created_assets {
acct=$1;
Expand Down Expand Up @@ -62,7 +62,7 @@ function assets {
}

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
[ "$(balance "$SMALL")" = 998000 ] # 1000 fee

function appl {
method=$1; shift
Expand All @@ -81,7 +81,6 @@ function asset-id {
}

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
Expand Down Expand Up @@ -116,15 +115,15 @@ function sign {
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
[ "$(balance "$SMALL")" = 997000 ] # 1000 fee

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

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

appl "deposit():void" -o "$T/deposit.tx" --from="$SMALL"
asset-deposit 1000 $ASSETID -o "$T/axfer1.tx"
Expand All @@ -136,8 +135,8 @@ ${gcmd} clerk rawsend -f "$T/group.stx"
[ "$(asset_bal "$SMALL")" = 999000 ] # asset balance
[ "$(asset_ids "$APPACCT")" = $ASSETID ]
[ "$(asset_bal "$APPACCT")" = 1000 ]
[ "$(balance "$SMALL")" = 994000 ] # 2 fees
[ "$(balance "$APPACCT")" = 999000 ]
[ "$(balance "$SMALL")" = 993000 ] # 2 fees
[ "$(balance "$APPACCT")" = 998000 ]

# 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)
Expand All @@ -151,31 +150,31 @@ 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
[ "$(balance "$SMALL")" = 992000 ] # 1 fee
[ "$(balance "$APPACCT")" = 997000 ] # 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
[ "$(balance "$SMALL")" = 990000 ] # 2000 fee
[ "$(asset_bal "$APPACCT")" = 800 ] # 100 asset withdrawn
[ "$(balance "$APPACCT")" = 998000 ] # fee credit used
[ "$(balance "$APPACCT")" = 997000 ] # 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 ]
[ "$(balance "$SMALL")" = 990000 ]
[ "$(balance "$APPACCT")" = 997000 ]

# 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 ]
[ "$(balance "$SMALL")" = 989000 ]
[ "$(balance "$APPACCT")" = 996000 ]

USER=$(${gcmd} account new | awk '{ print $6 }') #new account
${gcmd} clerk send -a 1000000 -f "$ACCOUNT" -t "$USER" #fund account
${gcmd} clerk send -a 999000 -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
Expand All @@ -190,7 +189,7 @@ ${gcmd} clerk send --from "$USER" --to "$USER" -a 0 --rekey-to "$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
${gcmd} clerk send -a 999000 -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
Expand Down