From 0ad10b264657386418f297270607e164b05afd58 Mon Sep 17 00:00:00 2001 From: "shiqi.zheng@algorand.com" Date: Fri, 24 Sep 2021 11:40:20 -0400 Subject: [PATCH 1/5] adding tests --- test/scripts/e2e_subs/e2e-logs.sh | 42 +++++++++++++++++++++++ test/scripts/e2e_subs/tealprogs/logs.teal | 19 ++++++++++ 2 files changed, 61 insertions(+) create mode 100755 test/scripts/e2e_subs/e2e-logs.sh create mode 100644 test/scripts/e2e_subs/tealprogs/logs.teal diff --git a/test/scripts/e2e_subs/e2e-logs.sh b/test/scripts/e2e_subs/e2e-logs.sh new file mode 100755 index 0000000000..05da1a4041 --- /dev/null +++ b/test/scripts/e2e_subs/e2e-logs.sh @@ -0,0 +1,42 @@ +#!/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" +} + +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 +} + +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 }') + +TXID=$(${gcmd} app create --creator "${ACCOUNT}" --approval-prog=${TEAL}/logs.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | app-txid) +#[ "$(rest "/v2/transactions/pending/$TXID" \ +# | jq '.["inner-txns"][0].txn.txn.amt')" = 20000 ] +logs= $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs[]') +#print ${logs} +#[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] + + +date "+${scriptname} OK %Y%m%d_%H%M%S" \ No newline at end of file diff --git a/test/scripts/e2e_subs/tealprogs/logs.teal b/test/scripts/e2e_subs/tealprogs/logs.teal new file mode 100644 index 0000000000..ab835003c2 --- /dev/null +++ b/test/scripts/e2e_subs/tealprogs/logs.teal @@ -0,0 +1,19 @@ +#pragma version 5 +byte "A" +loop: +int 0 +dup2 +getbyte +int 1 ++ +dup +int 97 //ascii code of last char +<= +bz end +setbyte +dup +log +b loop +end: +int 1 +return \ No newline at end of file From 21ad780d62d168c72793a55fb62ab126b255e151 Mon Sep 17 00:00:00 2001 From: "shiqi.zheng@algorand.com" Date: Fri, 24 Sep 2021 15:05:58 -0400 Subject: [PATCH 2/5] moving logs e2e to scripts --- test/e2e-go/restAPI/restClient_test.go | 126 ------------------------- test/scripts/e2e_subs/e2e-logs.sh | 33 +++++-- 2 files changed, 26 insertions(+), 133 deletions(-) diff --git a/test/e2e-go/restAPI/restClient_test.go b/test/e2e-go/restAPI/restClient_test.go index 49d05ae4a3..e8aff991d5 100644 --- a/test/e2e-go/restAPI/restClient_test.go +++ b/test/e2e-go/restAPI/restClient_test.go @@ -30,7 +30,6 @@ import ( "time" "unicode" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" algodclient "github.com/algorand/go-algorand/daemon/algod/api/client" @@ -935,131 +934,6 @@ func TestClientPrioritizesPendingTransactions(t *testing.T) { a.True(statusResponse.TruncatedTxns.Transactions[0].TxID == txHigh.ID().String()) } -func TestClientCanGetPendingTransactionInfo(t *testing.T) { - partitiontest.PartitionTest(t) - defer fixtures.ShutdownSynchronizedTest(t) - - a := require.New(fixtures.SynchronizedTest(t)) - var localFixture fixtures.RestClientFixture - localFixture.Setup(t, filepath.Join("nettemplates", "TwoNodes50EachFuture.json")) - defer localFixture.Shutdown() - - testClient := localFixture.LibGoalClient - - testClient.WaitForRound(1) - - testClient.SetAPIVersionAffinity(algodclient.APIVersionV2, kmdclient.APIVersionV1) - - wh, err := testClient.GetUnencryptedWalletHandle() - a.NoError(err) - addresses, err := testClient.ListAddresses(wh) - a.NoError(err) - _, someAddress := getMaxBalAddr(t, testClient, addresses) - if someAddress == "" { - t.Error("no addr with funds") - } - a.NoError(err) - addr, err := basics.UnmarshalChecksumAddress(someAddress) - - params, err := testClient.SuggestedParams() - a.NoError(err) - - firstRound := basics.Round(params.LastRound + 1) - lastRound := basics.Round(params.LastRound + 1000) - var gh crypto.Digest - copy(gh[:], params.GenesisHash) - - prog := `#pragma version 5 -byte "A" -loop: -int 0 -dup2 -getbyte -int 1 -+ -dup -int 97 //ascii code of last char -<= -bz end -setbyte -dup -log -b loop -end: -int 1 -return -` - ops, err := logic.AssembleString(prog) - approv := ops.Program - ops, err = logic.AssembleString("#pragma version 5 \nint 1") - clst := ops.Program - - gl := basics.StateSchema{ - NumByteSlice: 1, - } - lc := basics.StateSchema{ - NumByteSlice: 1, - } - minTxnFee, _, err := localFixture.CurrentMinFeeAndBalance() - - tx, err := testClient.MakeUnsignedApplicationCallTx(0, nil, addresses, nil, nil, transactions.NoOpOC, approv, clst, gl, lc, 0) - tx.Sender = addr - tx.Fee = basics.MicroAlgos{Raw: minTxnFee} - tx.FirstValid = firstRound - tx.LastValid = lastRound - tx.GenesisHash = gh - - txid, err := testClient.SignAndBroadcastTransaction(wh, nil, tx) - a.NoError(err) - _, err = waitForTransaction(t, testClient, someAddress, txid, 60*time.Second) - a.NoError(err) - txn, err := testClient.PendingTransactionInformationV2(txid) - a.NoError(err) - a.NotNil(txn.Logs) - a.Equal(32, len(*txn.Logs)) - for i, l := range *txn.Logs { - assert.Equal(t, []byte(string(rune('B'+i))), l) - } - - //check non-create app call - wh, err = testClient.GetUnencryptedWalletHandle() - a.NoError(err) - addresses, err = testClient.ListAddresses(wh) - a.NoError(err) - _, someAddress = getMaxBalAddr(t, testClient, addresses) - if someAddress == "" { - t.Error("no addr with funds") - } - a.NoError(err) - addr, err = basics.UnmarshalChecksumAddress(someAddress) - - params, err = testClient.SuggestedParams() - a.NoError(err) - - firstRound = basics.Round(params.LastRound + 1) - lastRound = basics.Round(params.LastRound + 1000) - - tx, err = testClient.MakeUnsignedAppNoOpTx(*txn.ApplicationIndex, nil, addresses, nil, nil) - tx.Sender = addr - tx.Fee = basics.MicroAlgos{Raw: minTxnFee} - tx.FirstValid = firstRound - tx.LastValid = lastRound - tx.GenesisHash = gh - - txid, err = testClient.SignAndBroadcastTransaction(wh, nil, tx) - a.NoError(err) - _, err = waitForTransaction(t, testClient, someAddress, txid, 60*time.Second) - a.NoError(err) - txn, err = testClient.PendingTransactionInformationV2(txid) - a.NoError(err) - a.NotNil(txn.Logs) - a.Equal(32, len(*txn.Logs)) - for i, l := range *txn.Logs { - assert.Equal(t, []byte(string(rune('B'+i))), l) - } - -} - func TestPendingTransactionInfoInnerTxnAssetCreate(t *testing.T) { partitiontest.PartitionTest(t) diff --git a/test/scripts/e2e_subs/e2e-logs.sh b/test/scripts/e2e_subs/e2e-logs.sh index 05da1a4041..bf7a89eadc 100755 --- a/test/scripts/e2e_subs/e2e-logs.sh +++ b/test/scripts/e2e_subs/e2e-logs.sh @@ -30,13 +30,32 @@ TEAL=test/scripts/e2e_subs/tealprogs gcmd="goal -w ${WALLET}" ACCOUNT=$(${gcmd} account list|awk '{ print $3 }') - +# app create TXID=$(${gcmd} app create --creator "${ACCOUNT}" --approval-prog=${TEAL}/logs.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | app-txid) -#[ "$(rest "/v2/transactions/pending/$TXID" \ -# | jq '.["inner-txns"][0].txn.txn.amt')" = 20000 ] -logs= $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs[]') -#print ${logs} -#[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] - +# log len +[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] +# log content +EXP=(B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \\ ] ^ _ \` a b ) +i=0 +for log in $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs | .[]') + do + c=`echo -n "${log}" | base64 --decode` + [ "$c" = "${EXP[i]}" ] + ((i++)) + done + +APPID=$(rest "/v2/transactions/pending/$TXID" | jq '.["application-index"]') +# app call +TXID=$(${gcmd} app call --app-id "${APPID}" --from "$ACCOUNT" | app-txid) +# log len +[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] +# log content +i=0 +for log in $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs | .[]') + do + c=`echo -n "${log}" | base64 --decode` + [ "$c" = "${EXP[i]}" ] + ((i++)) + done date "+${scriptname} OK %Y%m%d_%H%M%S" \ No newline at end of file From 95ee038fe9c9dae11b80538b3b35754e6b3e41b8 Mon Sep 17 00:00:00 2001 From: "shiqi.zheng@algorand.com" Date: Fri, 24 Sep 2021 15:34:14 -0400 Subject: [PATCH 3/5] changes as per review --- test/scripts/e2e_subs/e2e-logs.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/scripts/e2e_subs/e2e-logs.sh b/test/scripts/e2e_subs/e2e-logs.sh index bf7a89eadc..5b83b495c9 100755 --- a/test/scripts/e2e_subs/e2e-logs.sh +++ b/test/scripts/e2e_subs/e2e-logs.sh @@ -11,7 +11,7 @@ function rest() { curl -q -s -H "Authorization: Bearer $PUB_TOKEN" "$NET$1" } -function app-txid { +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 @@ -30,28 +30,31 @@ TEAL=test/scripts/e2e_subs/tealprogs gcmd="goal -w ${WALLET}" ACCOUNT=$(${gcmd} account list|awk '{ print $3 }') +EXP=(B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \\ ] ^ _ \` a b ) + # app create -TXID=$(${gcmd} app create --creator "${ACCOUNT}" --approval-prog=${TEAL}/logs.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | app-txid) +TXID=$(${gcmd} app create --creator "${ACCOUNT}" --approval-prog=${TEAL}/logs.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | app_txid) +response=$(rest "/v2/transactions/pending/$TXID") # log len -[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] +[ "$(echo "$response" | jq '.logs | length')" = 32 ] # log content -EXP=(B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \\ ] ^ _ \` a b ) i=0 -for log in $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs | .[]') +for log in $(echo "$response" | jq -r '.logs | .[]') do c=`echo -n "${log}" | base64 --decode` [ "$c" = "${EXP[i]}" ] ((i++)) done -APPID=$(rest "/v2/transactions/pending/$TXID" | jq '.["application-index"]') # app call -TXID=$(${gcmd} app call --app-id "${APPID}" --from "$ACCOUNT" | app-txid) +APPID=$(echo "$response" | jq '.["application-index"]') +TXID=$(${gcmd} app call --app-id "${APPID}" --from "$ACCOUNT" | app_txid) +response=$(rest "/v2/transactions/pending/$TXID") # log len -[ "$(rest "/v2/transactions/pending/$TXID" | jq '.logs | length')" = 32 ] +[ "$(echo "$response" | jq '.logs | length')" = 32 ] # log content i=0 -for log in $(rest "/v2/transactions/pending/$TXID" | jq -r '.logs | .[]') +for log in $(echo "$response" | jq -r '.logs | .[]') do c=`echo -n "${log}" | base64 --decode` [ "$c" = "${EXP[i]}" ] From 5157959241d65728e362301c654cf63d749af98f Mon Sep 17 00:00:00 2001 From: "shiqi.zheng@algorand.com" Date: Fri, 24 Sep 2021 15:35:07 -0400 Subject: [PATCH 4/5] update description --- test/scripts/e2e_subs/e2e-logs.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/scripts/e2e_subs/e2e-logs.sh b/test/scripts/e2e_subs/e2e-logs.sh index 5b83b495c9..33685a0f9d 100755 --- a/test/scripts/e2e_subs/e2e-logs.sh +++ b/test/scripts/e2e_subs/e2e-logs.sh @@ -13,8 +13,7 @@ function rest() { 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 + # printed. grep -o -E 'txid [A-Z0-9]{52}' | cut -c 6- | head -1 } From 76c968a790b7d708d6ece9888b6be32655497930 Mon Sep 17 00:00:00 2001 From: "shiqi.zheng@algorand.com" Date: Fri, 24 Sep 2021 17:02:25 -0400 Subject: [PATCH 5/5] syntax fix --- test/scripts/e2e_subs/e2e-logs.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/scripts/e2e_subs/e2e-logs.sh b/test/scripts/e2e_subs/e2e-logs.sh index 33685a0f9d..7d40a62e1f 100755 --- a/test/scripts/e2e_subs/e2e-logs.sh +++ b/test/scripts/e2e_subs/e2e-logs.sh @@ -29,7 +29,7 @@ TEAL=test/scripts/e2e_subs/tealprogs gcmd="goal -w ${WALLET}" ACCOUNT=$(${gcmd} account list|awk '{ print $3 }') -EXP=(B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \\ ] ^ _ \` a b ) +EXP=(B C D E F G H I J K L M N O P Q R S T U V W X Y Z \[ \\ \] ^ _ \` a b ) # app create TXID=$(${gcmd} app create --creator "${ACCOUNT}" --approval-prog=${TEAL}/logs.teal --global-byteslices 4 --global-ints 0 --local-byteslices 0 --local-ints 1 --clear-prog=${TEAL}/approve-all.teal | app_txid) @@ -42,7 +42,7 @@ for log in $(echo "$response" | jq -r '.logs | .[]') do c=`echo -n "${log}" | base64 --decode` [ "$c" = "${EXP[i]}" ] - ((i++)) + i=$((i+1)) done # app call @@ -57,7 +57,7 @@ for log in $(echo "$response" | jq -r '.logs | .[]') do c=`echo -n "${log}" | base64 --decode` [ "$c" = "${EXP[i]}" ] - ((i++)) + i=$((i+1)) done date "+${scriptname} OK %Y%m%d_%H%M%S" \ No newline at end of file