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

e2e tests for log #2950

Merged
merged 5 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
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
126 changes: 0 additions & 126 deletions test/e2e-go/restAPI/restClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
63 changes: 63 additions & 0 deletions test/scripts/e2e_subs/e2e-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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.
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 }')
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)
response=$(rest "/v2/transactions/pending/$TXID")
# log len
[ "$(echo "$response" | jq '.logs | length')" = 32 ]
# log content
i=0
for log in $(echo "$response" | jq -r '.logs | .[]')
do
c=`echo -n "${log}" | base64 --decode`
[ "$c" = "${EXP[i]}" ]
i=$((i+1))
done

# app call
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
[ "$(echo "$response" | jq '.logs | length')" = 32 ]
# log content
i=0
for log in $(echo "$response" | jq -r '.logs | .[]')
do
c=`echo -n "${log}" | base64 --decode`
[ "$c" = "${EXP[i]}" ]
i=$((i+1))
done

date "+${scriptname} OK %Y%m%d_%H%M%S"
19 changes: 19 additions & 0 deletions test/scripts/e2e_subs/tealprogs/logs.teal
Original file line number Diff line number Diff line change
@@ -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