From dad6d1e2270791a889a0d6ce01856e18ac4ee230 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Tue, 16 Aug 2022 17:47:22 -0500 Subject: [PATCH 01/16] Enhancement: Use Sandbox for Testing --- .test-env | 8 ++++++ Makefile | 16 ++++++++++-- test-harness.sh | 52 +++++++++++++++++++++++++++++++++++++++ test/docker/run_docker.sh | 25 ------------------- test/docker/sdk.py | 21 ---------------- 5 files changed, 74 insertions(+), 48 deletions(-) create mode 100644 .test-env create mode 100755 test-harness.sh delete mode 100755 test/docker/run_docker.sh delete mode 100644 test/docker/sdk.py diff --git a/.test-env b/.test-env new file mode 100644 index 00000000..3abc5e33 --- /dev/null +++ b/.test-env @@ -0,0 +1,8 @@ +# Configs for testing repo download: +SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing" +SDK_TESTING_BRANCH="trim-indexer" +SDK_TESTING_HARNESS="test-harness" + +# WARNING: Be careful when turning on the next variable. +# In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env` +OVERWRITE_TESTING_ENVIRONMENT=0 \ No newline at end of file diff --git a/Makefile b/Makefile index 0d881e7e..87476ee5 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SRCPATH := $(shell pwd) TEST_SOURCES := $(shell cd $(SRCPATH) && go list ./...) TEST_SOURCES_NO_CUCUMBER := $(shell cd $(SRCPATH) && go list ./... | grep -v test) +GO_IMAGE := golang:$(subst go,,$(shell go version | cut -d' ' -f 3 | cut -d'.' -f 1,2))-stretch lint: golint `go list ./... | grep -v /vendor/` @@ -25,7 +26,18 @@ integration: go test $(TEST_SOURCES_NO_CUCUMBER) cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" --test.v . -docker-test: - ./test/docker/run_docker.sh +harness: + ./test-harness.sh + +docker-gosdk-build: + echo "Building docker image from base $(GO_IMAGE)" + docker build -t go-sdk-testing --build-arg GO_IMAGE="$(GO_IMAGE)" -f test/docker/Dockerfile $(shell pwd) + +docker-gosdk-run: + docker ps -a + docker run -it --network host go-sdk-testing:latest + +docker-test: harness docker-gosdk-build docker-gosdk-run + .PHONY: test fmt diff --git a/test-harness.sh b/test-harness.sh new file mode 100755 index 00000000..e739a850 --- /dev/null +++ b/test-harness.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -euo pipefail + +START=$(date "+%s") + +THIS=$(basename "$0") +ENV_FILE=".test-env" + +set -a +source "$ENV_FILE" +set +a + +rootdir=$(dirname "$0") +pushd "$rootdir" + +## Reset test harness +if [ -d "$SDK_TESTING_HARNESS" ]; then + pushd "$SDK_TESTING_HARNESS" + ./scripts/down.sh + popd + rm -rf "$SDK_TESTING_HARNESS" +else + echo "$THIS: directory $SDK_TESTING_HARNESS does not exist - NOOP" +fi + +git clone --depth 1 --single-branch --branch "$SDK_TESTING_BRANCH" "$SDK_TESTING_URL" "$SDK_TESTING_HARNESS" + + +if [[ $OVERWRITE_TESTING_ENVIRONMENT == 1 ]]; then + echo "$THIS: OVERWRITE downloaded $SDK_TESTING_HARNESS/.env with $ENV_FILE:" + cp "$ENV_FILE" "$SDK_TESTING_HARNESS"/.env +fi + +## Copy feature files into the project resources +rm -rf test/features +mkdir -p test/features +cp -r "$SDK_TESTING_HARNESS"/features/* test/features +echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s" + + +## Start test harness environment +pushd "$SDK_TESTING_HARNESS" +./scripts/up.sh +popd +echo "$THIS: seconds it took to finish testing sdk's up.sh: $(($(date "+%s") - START))s" +echo "" +echo "--------------------------------------------------------------------------------" +echo "|" +echo "| To run sandbox commands, cd into $SDK_TESTING_HARNESS/.sandbox " +echo "|" +echo "--------------------------------------------------------------------------------" diff --git a/test/docker/run_docker.sh b/test/docker/run_docker.sh deleted file mode 100755 index 462a57fd..00000000 --- a/test/docker/run_docker.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# reset test harness -rm -rf test-harness -rm -rf test/features -git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness -#copy feature files into project -mv test-harness/features test/features - -GO_VERSION=$(go version | cut -d' ' -f 3 | cut -d'.' -f 1,2) -GO_IMAGE=golang:${GO_VERSION:2}-stretch - -echo "Building docker image from base \"$GO_IMAGE\"" - -#build test environment -docker build -t go-sdk-testing --build-arg GO_IMAGE="$GO_IMAGE" -f test/docker/Dockerfile "$(pwd)" - -# Start test harness environment -./test-harness/scripts/up.sh -p - -docker run -it \ - --network host \ - go-sdk-testing:latest diff --git a/test/docker/sdk.py b/test/docker/sdk.py deleted file mode 100644 index 5b9ff84b..00000000 --- a/test/docker/sdk.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess -import sys - -default_dirs = { - 'features_dir': '/opt/go/src/github.com/algorand/go-algorand-sdk/test/features', - 'source': '/opt/go/src/github.com/algorand/go-algorand-sdk', - 'docker': '/opt/go/src/github.com/algorand/go-algorand-sdk/test/docker', - 'test': '/opt/go/src/github.com/algorand/go-algorand-sdk/test' -} - -def setup_sdk(): - """ - Setup go cucumber environment. - """ - subprocess.check_call(['go generate %s/...' % default_dirs['source']], shell=True) - -def test_sdk(): - sys.stdout.flush() - subprocess.check_call(['go test'], shell=True, cwd=default_dirs['test']) \ No newline at end of file From ffb2347f261ad5e62f00aeb49bdc96ed011b732d Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Tue, 16 Aug 2022 23:04:46 -0500 Subject: [PATCH 02/16] almost passing --- test/applications_integration_test.go | 118 +---- test/indexer_integration_test.go | 674 -------------------------- test/steps_test.go | 34 +- 3 files changed, 6 insertions(+), 820 deletions(-) delete mode 100644 test/indexer_integration_test.go diff --git a/test/applications_integration_test.go b/test/applications_integration_test.go index 5215e69b..035a6d7c 100644 --- a/test/applications_integration_test.go +++ b/test/applications_integration_test.go @@ -12,7 +12,6 @@ import ( "regexp" "strconv" "strings" - "time" "github.com/cucumber/godog" @@ -448,124 +447,11 @@ func theTransientAccountShouldHave(appCreated string, byteSlices, uints int, } } if !found { - fmt.Errorf("Could not find key '%s'", key) + return fmt.Errorf("Could not find key '%s'", key) } return nil } -func theUnconfirmedPendingTransactionByIDShouldHaveNoApplyDataFields() error { - status, _, err := algodV2client.PendingTransactionInformation(txid).Do(context.Background()) - if err != nil { - return err - } - if status.ConfirmedRound == 0 { - if len(status.GlobalStateDelta) != 0 { - return fmt.Errorf("unexpected global state delta, there should be none: %v", status.GlobalStateDelta) - } - if len(status.LocalStateDelta) != 0 { - return fmt.Errorf("unexpected local state delta, there should be none: %v", status.LocalStateDelta) - } - } - return nil -} - -func getAccountDelta(addr string, data []models.AccountStateDelta) []models.EvalDeltaKeyValue { - for _, v := range data { - if v.Address == addr { - return v.Delta - } - } - return nil -} -func theConfirmedPendingTransactionByIDShouldHaveAStateChangeForToIndexerShouldAlsoConfirmThis(stateLocation, key, newValue string, indexer int) error { - status, _, err := algodV2client.PendingTransactionInformation(txid).Do(context.Background()) - if err != nil { - return err - } - - c1 := make(chan models.Transaction, 1) - - go func() { - for true { - indexerResponse, _ := indexerClients[indexer].SearchForTransactions().TXID(txid).Do(context.Background()) - if len(indexerResponse.Transactions) == 1 { - c1 <- indexerResponse.Transactions[0] - } - time.Sleep(time.Second) - } - }() - - var indexerTx models.Transaction - select { - case res := <-c1: - indexerTx = res - case <-time.After(5 * time.Second): - return fmt.Errorf("timeout waiting for indexer trasaction") - } - - var algodKeyValues []models.EvalDeltaKeyValue - var indexerKeyValues []models.EvalDeltaKeyValue - - switch stateLocation { - case "local": - addr := indexerTx.Sender - algodKeyValues = getAccountDelta(addr, status.LocalStateDelta) - indexerKeyValues = getAccountDelta(addr, indexerTx.LocalStateDelta) - case "global": - algodKeyValues = status.GlobalStateDelta - indexerKeyValues = indexerTx.GlobalStateDelta - default: - return fmt.Errorf("unknown location: " + stateLocation) - } - - // algod - if len(algodKeyValues) != 1 { - return fmt.Errorf("expected 1 key value, found: %d", len(algodKeyValues)) - } - if algodKeyValues[0].Key != key { - return fmt.Errorf("wrong key in algod: %s != %s", algodKeyValues[0].Key, key) - } - - // indexer - if len(indexerKeyValues) != 1 { - return fmt.Errorf("expected 1 key value, found: %d", len(indexerKeyValues)) - } - if indexerKeyValues[0].Key != key { - return fmt.Errorf("wrong key in indexer: %s != %s", indexerKeyValues[0].Key, key) - } - - if indexerKeyValues[0].Value.Action != algodKeyValues[0].Value.Action { - return fmt.Errorf("action mismatch between algod and indexer") - } - - switch algodKeyValues[0].Value.Action { - case uint64(1): - // bytes - if algodKeyValues[0].Value.Bytes != newValue { - return fmt.Errorf("algod value mismatch: %s != %s", algodKeyValues[0].Value.Bytes, newValue) - } - if indexerKeyValues[0].Value.Bytes != newValue { - return fmt.Errorf("indexer value mismatch: %s != %s", indexerKeyValues[0].Value.Bytes, newValue) - } - case uint64(2): - // int - newValueInt, err := strconv.ParseUint(newValue, 10, 64) - if err != nil { - return fmt.Errorf("problem parsing new int value: %s", newValue) - } - - if algodKeyValues[0].Value.Uint != newValueInt { - return fmt.Errorf("algod value mismatch: %d != %s", algodKeyValues[0].Value.Uint, newValue) - } - if indexerKeyValues[0].Value.Uint != newValueInt { - return fmt.Errorf("indexer value mismatch: %d != %s", indexerKeyValues[0].Value.Uint, newValue) - } - default: - return fmt.Errorf("unexpected action: %d", algodKeyValues[0].Value.Action) - } - - return nil -} func suggestedParamsAlgodV2() error { var err error @@ -883,8 +769,6 @@ func ApplicationsContext(s *godog.Suite) { s.Step(`^I get the account address for the current application and see that it matches the app id\'s hash$`, iGetTheAccountAddressForTheCurrentApp) s.Step(`^The transient account should have the created app "([^"]*)" and total schema byte-slices (\d+) and uints (\d+), the application "([^"]*)" state contains key "([^"]*)" with value "([^"]*)"$`, theTransientAccountShouldHave) - s.Step(`^the unconfirmed pending transaction by ID should have no apply data fields\.$`, theUnconfirmedPendingTransactionByIDShouldHaveNoApplyDataFields) - s.Step(`^the confirmed pending transaction by ID should have a "([^"]*)" state change for "([^"]*)" to "([^"]*)", indexer (\d+) should also confirm this\.$`, theConfirmedPendingTransactionByIDShouldHaveAStateChangeForToIndexerShouldAlsoConfirmThis) s.Step(`^suggested transaction parameters from the algod v2 client$`, suggestedParamsAlgodV2) s.Step(`^I add the current transaction with signer to the composer\.$`, iAddTheCurrentTransactionWithSignerToTheComposer) s.Step(`^I clone the composer\.$`, iCloneTheComposer) diff --git a/test/indexer_integration_test.go b/test/indexer_integration_test.go deleted file mode 100644 index caa593f5..00000000 --- a/test/indexer_integration_test.go +++ /dev/null @@ -1,674 +0,0 @@ -package test - -import ( - "context" - "encoding/base64" - "fmt" - "path" - "strconv" - "strings" - "time" - - "github.com/cucumber/godog" - - "github.com/algorand/go-algorand-sdk/client/v2/common/models" - "github.com/algorand/go-algorand-sdk/client/v2/indexer" - "github.com/algorand/go-algorand-sdk/encoding/json" -) - -func IndexerIntegrationTestContext(s *godog.Suite) { - s.Step(`^indexer client (\d+) at "([^"]*)" port (\d+) with token "([^"]*)"$`, indexerClientAtPortWithToken) - s.Step(`^I use (\d+) to check the services health$`, iUseToCheckTheServicesHealth) - s.Step(`^I receive status code (\d+)$`, iReceiveStatusCode) - s.Step(`^I use (\d+) to lookup block (\d+)$`, iUseToLookupBlock) - s.Step(`^The block was confirmed at (\d+), contains (\d+) transactions, has the previous block hash "([^"]*)"$`, theBlockWasConfirmedAtContainsTransactionsHasThePreviousBlockHash) - s.Step(`^I use (\d+) to lookup account "([^"]*)" at round (\d+)$`, iUseToLookupAccountAtRound) - s.Step(`^The account has (\d+) assets, the first is asset (\d+) has a frozen status of "([^"]*)" and amount (\d+)\.$`, theAccountHasAssetsTheFirstIsAssetHasAFrozenStatusOfAndAmount) - s.Step(`^The account created (\d+) assets, the first is asset (\d+) is named "([^"]*)" with a total amount of (\d+) "([^"]*)"$`, theAccountCreatedAssetsTheFirstIsAssetIsNamedWithATotalAmountOf) - s.Step(`^The account has (\d+) μalgos and (\d+) assets, (\d+) has (\d+)$`, theAccountHasAlgosAndAssetsHas) - s.Step(`^I use (\d+) to lookup asset (\d+)$`, iUseToLookupAsset) - s.Step(`^The asset found has: "([^"]*)", "([^"]*)", "([^"]*)", (\d+), "([^"]*)", (\d+), "([^"]*)"$`, theAssetFoundHas) - s.Step(`^I use (\d+) to lookup asset balances for (\d+) with (\d+), (\d+), (\d+) and token "([^"]*)"$`, iUseToLookupAssetBalancesForWithAndToken) - s.Step(`^There are (\d+) with the asset, the first is "([^"]*)" has "([^"]*)" and (\d+)$`, thereAreWithTheAssetTheFirstIsHasAnd) - s.Step(`^I get the next page using (\d+) to lookup asset balances for (\d+) with (\d+), (\d+), (\d+)$`, iGetTheNextPageUsingToLookupAssetBalancesForWith) - s.Step(`^I use (\d+) to search for an account with (\d+), (\d+), (\d+), (\d+) and token "([^"]*)"$`, iUseToSearchForAnAccountWithAndToken) - s.Step(`^There are (\d+), the first has (\d+), (\d+), (\d+), (\d+), "([^"]*)", (\d+), "([^"]*)", "([^"]*)"$`, thereAreTheFirstHas) - s.Step(`^The first account is online and has "([^"]*)", (\d+), (\d+), (\d+), "([^"]*)", "([^"]*)"$`, theFirstAccountIsOnlineAndHas) - s.Step(`^I get the next page using (\d+) to search for an account with (\d+), (\d+), (\d+) and (\d+)$`, iGetTheNextPageUsingToSearchForAnAccountWithAnd) - s.Step(`^I use (\d+) to search for transactions with (\d+), "([^"]*)", "([^"]*)", "([^"]*)", "([^"]*)", (\d+), (\d+), (\d+), (\d+), "([^"]*)", "([^"]*)", (\d+), (\d+), "([^"]*)", "([^"]*)", "([^"]*)" and token "([^"]*)"$`, iUseToSearchForTransactionsWithAndToken) - s.Step(`^there are (\d+) transactions in the response, the first is "([^"]*)"\.$`, thereAreTransactionsInTheResponseTheFirstIs) - s.Step(`^Every transaction has tx-type "([^"]*)"$`, everyTransactionHasTxtype) - s.Step(`^Every transaction has sig-type "([^"]*)"$`, everyTransactionHasSigtype) - s.Step(`^Every transaction has round (\d+)$`, everyTransactionHasRoundEqual) - s.Step(`^Every transaction has round >= (\d+)$`, everyTransactionHasRoundGreaterThan) - s.Step(`^Every transaction has round <= (\d+)$`, everyTransactionHasRoundLessThan) - s.Step(`^Every transaction works with asset-id (\d+)$`, everyTransactionWorksWithAssetid) - s.Step(`^Every transaction is older than "([^"]*)"$`, everyTransactionIsOlderThan) - s.Step(`^Every transaction is newer than "([^"]*)"$`, everyTransactionIsNewerThan) - s.Step(`^Every transaction moves between (\d+) and (\d+) currency$`, everyTransactionMovesBetweenAndCurrency) - s.Step(`^I use (\d+) to search for all "([^"]*)" transactions$`, iUseToSearchForAllTransactions) - s.Step(`^I use (\d+) to search for all (\d+) asset transactions$`, iUseToSearchForAllAssetTransactions) - s.Step(`^I get the next page using (\d+) to search for transactions with (\d+) and (\d+)$`, iGetTheNextPageUsingToSearchForTransactionsWithAnd) - s.Step(`^I use (\d+) to search for assets with (\d+), (\d+), "([^"]*)", "([^"]*)", "([^"]*)", and token "([^"]*)"$`, iUseToSearchForAssetsWithAndToken) - s.Step(`^there are (\d+) assets in the response, the first is (\d+)\.$`, thereAreAssetsInTheResponseTheFirstIs) - - //@indexer.applications - s.Step(`^I use (\d+) to search for applications with (\d+), (\d+), and token "([^"]*)"$`, deprecatedIUseToSearchForApplicationsWithAndToken) - s.Step(`^the parsed response should equal "([^"]*)"\.$`, theParsedResponseShouldEqual) - s.Step(`^I use (\d+) to lookup application with (\d+)$`, deprecatedIUseToLookupApplicationWith) - s.Step(`^I use (\d+) to search for transactions with (\d+), "([^"]*)", "([^"]*)", "([^"]*)", "([^"]*)", (\d+), (\d+), (\d+), (\d+), "([^"]*)", "([^"]*)", (\d+), (\d+), "([^"]*)", "([^"]*)", "([^"]*)", (\d+) and token "([^"]*)"$`, iUseToSearchForTransactionsWithAppIdAndToken) - s.Step(`^I use (\d+) to search for an account with (\d+), (\d+), (\d+), (\d+), "([^"]*)", (\d+) and token "([^"]*)"$`, deprecatedIUseToSearchForAnAccountWithAppIdAndToken) - - //@indexer.231 - s.Step(`^I use (\d+) to search for applications with (\d+), (\d+), "([^"]*)" and token "([^"]*)"$`, iUseToSearchForApplicationsWithAndToken) - s.Step(`^I use (\d+) to lookup application with (\d+) and "([^"]*)"$`, iUseToLookupApplicationWithAnd) - s.Step(`^I use (\d+) to search for an account with (\d+), (\d+), (\d+), (\d+), "([^"]*)", (\d+), "([^"]*)" and token "([^"]*)"$`, iUseToSearchForAnAccount) - - s.BeforeScenario(func(interface{}) { - }) -} - -var indexerClients = make(map[int]*indexer.Client) - -func indexerClientAtPortWithToken(clientNum int, host string, port int, token string) error { - portAsString := strconv.Itoa(port) - fullHost := "http://" + host + ":" + portAsString - ic, err := indexer.MakeClient(fullHost, token) - indexerClients[clientNum] = ic - return err -} - -var indexerHealthCheckResponse models.HealthCheckResponse -var indexerHealthCheckError error - -func iUseToCheckTheServicesHealth(clientNum int) error { - ic := indexerClients[clientNum] - indexerHealthCheckResponse, indexerHealthCheckError = ic.HealthCheck().Do(context.Background()) - return nil -} - -func iReceiveStatusCode(code int) error { - if code == 200 && indexerHealthCheckError == nil { - return nil - } - return fmt.Errorf("Did not receive expected error code: %v", indexerHealthCheckError) -} - -var indexerBlockResponse models.Block - -func iUseToLookupBlock(clientNum, blockNum int) error { - ic := indexerClients[clientNum] - var err error - indexerBlockResponse, err = ic.LookupBlock(uint64(blockNum)).Do(context.Background()) - return err -} - -func theBlockWasConfirmedAtContainsTransactionsHasThePreviousBlockHash(timestamp, numTransactions int, prevBlockHash string) error { - err := comparisonCheck("timestamp", uint64(timestamp), indexerBlockResponse.Timestamp) - if err != nil { - return err - } - err = comparisonCheck("number of transactions", numTransactions, len(indexerBlockResponse.Transactions)) - if err != nil { - return err - } - err = comparisonCheck("previous blockhash", prevBlockHash, base64.StdEncoding.EncodeToString(indexerBlockResponse.PreviousBlockHash)) - return err -} - -var indexerAccountResponse models.Account - -func iUseToLookupAccountAtRound(clientNum int, account string, round int) error { - ic := indexerClients[clientNum] - var err error - _, indexerAccountResponse, err = ic.LookupAccountByID(account).Round(uint64(round)).Do(context.Background()) - return err -} - -func theAccountHasAssetsTheFirstIsAssetHasAFrozenStatusOfAndAmount(numAssets, firstAssetIndex int, firstAssetFrozenStatus string, firstAssetAmount int) error { - err := comparisonCheck("number of asset holdings", numAssets, len(indexerAccountResponse.Assets)) - if err != nil { - return err - } - assetUnderScrutiny := indexerAccountResponse.Assets[0] - err = comparisonCheck("first asset index", uint64(firstAssetIndex), assetUnderScrutiny.AssetId) - if err != nil { - return err - } - frozen, err := strconv.ParseBool(firstAssetFrozenStatus) - if err != nil { - frozen = false - } - err = comparisonCheck("first asset frozen status", frozen, assetUnderScrutiny.IsFrozen) - if err != nil { - return err - } - err = comparisonCheck("first asset amount", uint64(firstAssetAmount), assetUnderScrutiny.Amount) - return err -} - -func theAccountCreatedAssetsTheFirstIsAssetIsNamedWithATotalAmountOf(numCreatedAssets, firstAssetIndex int, assetName string, assetIssuance int, assetUnitName string) error { - err := comparisonCheck("number of created assets", numCreatedAssets, len(indexerAccountResponse.CreatedAssets)) - if err != nil { - return err - } - assetUnderScrutiny := indexerAccountResponse.CreatedAssets[0] - err = comparisonCheck("first created asset index", uint64(firstAssetIndex), assetUnderScrutiny.Index) - if err != nil { - return err - } - err = comparisonCheck("first created asset name", assetName, assetUnderScrutiny.Params.Name) - if err != nil { - return err - } - err = comparisonCheck("first created asset issuance", uint64(assetIssuance), assetUnderScrutiny.Params.Total) - if err != nil { - return err - } - err = comparisonCheck("first created asset unit name", assetUnitName, assetUnderScrutiny.Params.UnitName) - return err -} - -func theAccountHasAlgosAndAssetsHas(microAlgos, numAssets, assetIndex, assetAmount int) error { - err := comparisonCheck("microalgo balance", uint64(microAlgos), indexerAccountResponse.Amount) - if err != nil { - return err - } - err = comparisonCheck("number of asset holdings", numAssets, len(indexerAccountResponse.Assets)) - if err != nil { - return err - } - if numAssets == 0 || assetIndex == 0 { - return nil - } - assetUnderScrutiny, err := findAssetInHoldingsList(indexerAccountResponse.Assets, uint64(assetIndex)) - if err != nil { - return err - } - err = comparisonCheck(fmt.Sprintf("amount for asset %d", uint64(assetIndex)), uint64(assetAmount), assetUnderScrutiny.Amount) - return err -} - -var indexerAssetResponse models.Asset - -func iUseToLookupAsset(clientNum, assetId int) error { - ic := indexerClients[clientNum] - var err error - _, indexerAssetResponse, err = ic.LookupAssetByID(uint64(assetId)).Do(context.Background()) - return err -} - -func theAssetFoundHas(assetName, assetUnits, assetCreator string, assetDecimals int, assetDefaultFrozen string, assetIssuance int, assetClawbackAddress string) error { - err := comparisonCheck("asset name", assetName, indexerAssetResponse.Params.Name) - if err != nil { - return err - } - err = comparisonCheck("asset units", assetUnits, indexerAssetResponse.Params.UnitName) - if err != nil { - return err - } - err = comparisonCheck("asset creator", assetCreator, indexerAssetResponse.Params.Creator) - if err != nil { - return err - } - err = comparisonCheck("asset decimals", uint64(assetDecimals), indexerAssetResponse.Params.Decimals) - if err != nil { - return err - } - frozen, err := strconv.ParseBool(assetDefaultFrozen) - if err != nil { - frozen = false - } - err = comparisonCheck("asset default frozen state", frozen, indexerAssetResponse.Params.DefaultFrozen) - if err != nil { - return err - } - err = comparisonCheck("asset issuance", uint64(assetIssuance), indexerAssetResponse.Params.Total) - if err != nil { - return err - } - err = comparisonCheck("asset clawback address", assetClawbackAddress, indexerAssetResponse.Params.Clawback) - return err -} - -var indexerAssetBalancesResponse models.AssetBalancesResponse - -func iUseToLookupAssetBalancesForWithAndToken(clientNum, assetId, currencyGreater, currencyLesser, limit int, token string) error { - ic := indexerClients[clientNum] - var err error - indexerAssetBalancesResponse, err = ic.LookupAssetBalances(uint64(assetId)). - CurrencyGreaterThan(uint64(currencyGreater)). - CurrencyLessThan(uint64(currencyLesser)). - Limit(uint64(limit)). - NextToken(token). - Do(context.Background()) - return err -} - -func thereAreWithTheAssetTheFirstIsHasAnd(numAccountsWithAsset int, firstHolder, firstHolderIsFrozen string, firstHolderAmount int) error { - err := comparisonCheck("number of asset holders", numAccountsWithAsset, len(indexerAssetBalancesResponse.Balances)) - if err != nil { - return err - } - if numAccountsWithAsset == 0 { - return nil - } - accountUnderScrutiny := indexerAssetBalancesResponse.Balances[0] - err = comparisonCheck("first account holder", firstHolder, accountUnderScrutiny.Address) - if err != nil { - return err - } - frozen, err := strconv.ParseBool(firstHolderIsFrozen) - if err != nil { - frozen = false - } - err = comparisonCheck("first account holder frozen state", frozen, accountUnderScrutiny.IsFrozen) - if err != nil { - return err - } - err = comparisonCheck("first account holder asset balance", uint64(firstHolderAmount), accountUnderScrutiny.Amount) - return err -} - -func iGetTheNextPageUsingToLookupAssetBalancesForWith(clientNum, assetId, currencyGreater, currencyLesser, limit int) error { - ic := indexerClients[clientNum] - var err error - indexerAssetBalancesResponse, err = ic.LookupAssetBalances(uint64(assetId)).CurrencyGreaterThan(uint64(currencyGreater)).CurrencyLessThan(uint64(currencyLesser)).Limit(uint64(limit)).NextToken(indexerAssetBalancesResponse.NextToken).Do(context.Background()) - return err -} - -var indexerSearchAccountsResponse models.AccountsResponse - -// Saves the response in a separate type so that we can capture the next token. -func iUseToSearchForAnAccountWithAndToken(clientNum, assetIndex, limit, currencyGreater, currencyLesser int, token string) error { - ic := indexerClients[clientNum] - var err error - query := ic.SearchAccounts(). - AssetID(uint64(assetIndex)). - Limit(uint64(limit)). - CurrencyGreaterThan(uint64(currencyGreater)). - CurrencyLessThan(uint64(currencyLesser)). - NextToken(token) - indexerSearchAccountsResponse, err = query.Do(context.Background()) - return err -} - -// Pass the captured next token into the SearchAccounts function. -func iGetTheNextPageUsingToSearchForAnAccountWithAnd(clientNum, assetId, limit, currencyGreater, currencyLesser int) error { - next := indexerSearchAccountsResponse.NextToken - return iUseToSearchForAnAccountWithAndToken(clientNum, assetId, limit, currencyGreater, currencyLesser, next) -} - -func thereAreTheFirstHas(numAccounts, firstAccountPendingRewards, rewardsBase, rewards, withoutRewards int, address string, amount int, accountStatus, accountType string) error { - err := comparisonCheck("number of found accounts", numAccounts, len(indexerSearchAccountsResponse.Accounts)) - if err != nil { - return err - } - if numAccounts == 0 { - return nil - } - accountUnderScrutiny := indexerSearchAccountsResponse.Accounts[0] - err = comparisonCheck("first account pending rewards", uint64(firstAccountPendingRewards), accountUnderScrutiny.PendingRewards) - if err != nil { - return err - } - err = comparisonCheck("first account rewards base", uint64(rewardsBase), accountUnderScrutiny.RewardBase) - if err != nil { - return err - } - err = comparisonCheck("first account rewards", uint64(rewards), accountUnderScrutiny.Rewards) - if err != nil { - return err - } - err = comparisonCheck("first account without-rewards", uint64(withoutRewards), accountUnderScrutiny.AmountWithoutPendingRewards) - if err != nil { - return err - } - err = comparisonCheck("first account address", address, accountUnderScrutiny.Address) - if err != nil { - return err - } - err = comparisonCheck("first account balance", uint64(amount), accountUnderScrutiny.Amount) - if err != nil { - return err - } - err = comparisonCheck("first account status", accountStatus, accountUnderScrutiny.Status) - if err != nil { - return err - } - err = comparisonCheck("first account type", accountType, accountUnderScrutiny.SigType) - return err -} - -func theFirstAccountIsOnlineAndHas(address string, keyDilution, firstValid, lastValid int, voteKey, selKey string) error { - accountUnderScrutiny := indexerSearchAccountsResponse.Accounts[0] - err := comparisonCheck("first account online state", "Online", accountUnderScrutiny.Status) - if err != nil { - return err - } - err = comparisonCheck("first account address", address, accountUnderScrutiny.Address) - if err != nil { - return err - } - err = comparisonCheck("first account key dilution", uint64(keyDilution), accountUnderScrutiny.Participation.VoteKeyDilution) - if err != nil { - return err - } - err = comparisonCheck("first account partkey firstvalid", uint64(firstValid), accountUnderScrutiny.Participation.VoteFirstValid) - if err != nil { - return err - } - err = comparisonCheck("first account partkey lastvalid", uint64(lastValid), accountUnderScrutiny.Participation.VoteLastValid) - if err != nil { - return err - } - voteKeyString := base64.StdEncoding.EncodeToString(accountUnderScrutiny.Participation.VoteParticipationKey) - selKeyString := base64.StdEncoding.EncodeToString(accountUnderScrutiny.Participation.SelectionParticipationKey) - err = comparisonCheck("first account votekey b64", voteKey, voteKeyString) - if err != nil { - return err - } - err = comparisonCheck("first account selkey b64", selKey, selKeyString) - return err -} - -var indexerTransactionsResponse models.TransactionsResponse - -func iUseToSearchForTransactionsWithAndToken(clientNum, limit int, notePrefix, txType, sigType, txid string, round, minRound, maxRound, assetId int, beforeTime, afterTime string, currencyGreater, currencyLesser int, address, addressRole, excludeCloseTo, token string) error { - ic := indexerClients[clientNum] - var err error - notePrefixBytes, err := base64.StdEncoding.DecodeString(notePrefix) - if err != nil { - return err - } - excludeBool, err := strconv.ParseBool(excludeCloseTo) - if err != nil { - excludeBool = false - } - indexerTransactionsResponse, err = ic.SearchForTransactions().Limit(uint64(limit)).NotePrefix(notePrefixBytes).TxType(txType).SigType(sigType).TXID(txid).Round(uint64(round)).MinRound(uint64(minRound)).MaxRound(uint64(maxRound)).AssetID(uint64(assetId)).BeforeTimeString(beforeTime).AfterTimeString(afterTime).CurrencyGreaterThan(uint64(currencyGreater)).CurrencyLessThan(uint64(currencyLesser)).AddressString(address).AddressRole(addressRole).ExcludeCloseTo(excludeBool).NextToken(token).Do(context.Background()) - return err -} - -func thereAreTransactionsInTheResponseTheFirstIs(numTransactions int, firstTransactionTxid string) error { - err := comparisonCheck("number of transactions", numTransactions, len(indexerTransactionsResponse.Transactions)) - if err != nil { - return err - } - if numTransactions == 0 { - return nil - } - txnUnderScrutiny := indexerTransactionsResponse.Transactions[0] - err = comparisonCheck("first txn txid", firstTransactionTxid, txnUnderScrutiny.Id) - return err -} - -func everyTransactionHasTxtype(txType string) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - err := comparisonCheck(fmt.Sprintf("tx type for returned transaction %d", idx), txType, txn.Type) - if err != nil { - return err - } - } - return nil -} - -func everyTransactionHasSigtype(sigType string) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - err := comparisonCheck(fmt.Sprintf("sig type for returned transaction %d", idx), sigType, getSigtypeFromTransaction(txn)) - if err != nil { - return err - } - } - return nil -} - -func everyTransactionHasRoundEqual(round int) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - err := comparisonCheck(fmt.Sprintf("confirmed round for returned transaction %d", idx), uint64(round), txn.ConfirmedRound) - if err != nil { - return err - } - } - return nil -} - -func everyTransactionHasRoundGreaterThan(round int) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - if txn.ConfirmedRound < uint64(round) { - return fmt.Errorf("transaction number %d was confirmed in round %d, but expected a number higher than %d", idx, txn.ConfirmedRound, uint64(round)) - } - } - return nil -} - -func everyTransactionHasRoundLessThan(round int) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - if txn.ConfirmedRound > uint64(round) { - return fmt.Errorf("transaction number %d was confirmed in round %d, but expected a number lower than %d", idx, txn.ConfirmedRound, uint64(round)) - } - } - return nil -} - -func everyTransactionWorksWithAssetid(assetId int) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - actualId := uint64(0) - if txn.AssetTransferTransaction.AssetId != 0 { - actualId = txn.AssetTransferTransaction.AssetId - } - if txn.AssetFreezeTransaction.AssetId != 0 { - actualId = txn.AssetFreezeTransaction.AssetId - } - if txn.AssetConfigTransaction.AssetId != 0 { - actualId = txn.AssetConfigTransaction.AssetId - } - if txn.CreatedAssetIndex != 0 { - actualId = txn.CreatedAssetIndex - } - err := comparisonCheck(fmt.Sprintf("asset id for returned transaction %d", idx), uint64(assetId), actualId) - if err != nil { - return err - } - } - return nil -} - -func everyTransactionIsOlderThan(olderThan string) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - olderThanDateTime, err := time.Parse(time.RFC3339, olderThan) - if err != nil { - return err - } - olderThanUnixTime := uint64(olderThanDateTime.Unix()) - if txn.RoundTime > olderThanUnixTime { - return fmt.Errorf("txn number %d has round time of %d, but expected it to be older than unix time %d (RFC format: %s)", idx, txn.RoundTime, olderThanUnixTime, olderThan) - } - } - return nil -} - -func everyTransactionIsNewerThan(newerThan string) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - newerThanDateTime, err := time.Parse(time.RFC3339, newerThan) - if err != nil { - return err - } - newerThanUnixTime := uint64(newerThanDateTime.Unix()) - if txn.RoundTime < newerThanUnixTime { - return fmt.Errorf("txn number %d has round time of %d, but expected it to be newer than unix time %d (RFC format: %s)", idx, txn.RoundTime, newerThanUnixTime, newerThan) - } - } - return nil -} - -func everyTransactionMovesBetweenAndCurrency(currencyGreater, currencyLesser int) error { - for idx, txn := range indexerTransactionsResponse.Transactions { - if txn.Type == "pay" { - if txn.PaymentTransaction.Amount < uint64(currencyGreater) { - return fmt.Errorf("txn number %d moved %d microAlgos, but expected it to move more than %d", idx, txn.PaymentTransaction.Amount, currencyGreater) - } - if currencyLesser != 0 && txn.PaymentTransaction.Amount > uint64(currencyLesser) { - return fmt.Errorf("txn number %d moved %d microAlgos, but expected it to move less than %d", idx, txn.PaymentTransaction.Amount, currencyLesser) - } - } - if txn.Type == "axfer" { - if txn.AssetTransferTransaction.Amount < uint64(currencyGreater) { - return fmt.Errorf("txn number %d moved %d asset units, but expected it to move more than %d", idx, txn.AssetTransferTransaction.Amount, currencyGreater) - } - if currencyLesser != 0 && txn.AssetTransferTransaction.Amount > uint64(currencyLesser) { - return fmt.Errorf("txn number %d moved %d asset units, but expected it to move less than %d", idx, txn.AssetTransferTransaction.Amount, currencyLesser) - } - } - } - return nil -} - -func iUseToSearchForAllTransactions(clientNum int, account string) error { - ic := indexerClients[clientNum] - var err error - indexerTransactionsResponse, err = ic.LookupAccountTransactions(account).Do(context.Background()) - return err -} - -func iUseToSearchForAllAssetTransactions(clientNum, assetId int) error { - ic := indexerClients[clientNum] - var err error - indexerTransactionsResponse, err = ic.LookupAssetTransactions(uint64(assetId)).Do(context.Background()) - return err -} - -func iGetTheNextPageUsingToSearchForTransactionsWithAnd(clientNum, limit, maxRound int) error { - ic := indexerClients[clientNum] - var err error - indexerTransactionsResponse, err = ic.SearchForTransactions().Limit(uint64(limit)).MaxRound(uint64(maxRound)).NextToken(indexerTransactionsResponse.NextToken).Do(context.Background()) - return err -} - -var indexerSearchForAssetsResponse []models.Asset - -func iUseToSearchForAssetsWithAndToken(clientNum, zero, assetId int, creator, name, unit, token string) error { - ic := indexerClients[clientNum] - resp, err := ic.SearchForAssets().AssetID(uint64(assetId)).Creator(creator).Name(name).Unit(unit).NextToken(token).Do(context.Background()) - indexerSearchForAssetsResponse = resp.Assets - return err -} - -func thereAreAssetsInTheResponseTheFirstIs(numAssetsInResponse, assetIdFirstAsset int) error { - err := comparisonCheck("number assets in search for assets response", numAssetsInResponse, len(indexerSearchForAssetsResponse)) - if err != nil { - return err - } - if numAssetsInResponse == 0 { - return nil - } - assetUnderScrutiny := indexerSearchForAssetsResponse[0] - err = comparisonCheck("first asset's ID", uint64(assetIdFirstAsset), assetUnderScrutiny.Index) - return err -} - -// @indexer.applications -func deprecatedIUseToSearchForApplicationsWithAndToken(indexer, limit, appId int, token string) error { - return iUseToSearchForApplicationsWithAndToken(indexer, limit, appId, "false", token) -} - -func iUseToSearchForApplicationsWithAndToken(indexer, limit, appId int, includeAll, token string) error { - ic := indexerClients[indexer] - var err error - query := ic.SearchForApplications(). - ApplicationId(uint64(appId)). - Limit(uint64(limit)). - Next(token) - if ia, err := strconv.ParseBool(includeAll); err == nil && ia { - query.IncludeAll(ia) - } - response, err = query.Do(context.Background()) - return err -} - -func theParsedResponseShouldEqual(jsonfileName string) error { - var responseJson string - - baselinePath := path.Join("./features/resources/", jsonfileName) - if responseStr, ok := response.(string); ok { - responseJson = responseStr - } else { - responseJson = string(json.Encode(response)) - } - - return VerifyResponse(baselinePath, responseJson) -} - -func deprecatedIUseToLookupApplicationWith(indexer, appid int) error { - return iUseToLookupApplicationWithAnd(indexer, appid, "false") -} - -func iUseToLookupApplicationWithAnd(indexer, appid int, includeAll string) error { - ic := indexerClients[indexer] - var err error - query := ic.LookupApplicationByID(uint64(appid)) - if ia, err := strconv.ParseBool(includeAll); err == nil && ia { - query.IncludeAll(ia) - } - response, err = query.Do(context.Background()) - // allow 404... - if err != nil && strings.HasPrefix(err.Error(), "HTTP") { - err = nil - } - return nil -} - -func iUseToSearchForTransactionsWithAppIdAndToken( - indexer, limit int, notePrefix, txType, sigType, txId string, round, - minRound, maxRound, assetId int, beforeTime, afterTime string, - currencyGt, currencyLt int, address, addressRole, excludeCloseTo string, appId int, token string) error { - ic := indexerClients[indexer] - var err error - notePrefixBytes, err := base64.StdEncoding.DecodeString(notePrefix) - if err != nil { - return err - } - excludeBool, err := strconv.ParseBool(excludeCloseTo) - if err != nil { - excludeBool = false - } - response, err = ic.SearchForTransactions(). - ApplicationId(uint64(appId)). - Limit(uint64(limit)). - NotePrefix(notePrefixBytes). - TxType(txType).SigType(sigType). - TXID(txId).Round(uint64(round)). - MinRound(uint64(minRound)). - MaxRound(uint64(maxRound)). - AssetID(uint64(assetId)). - BeforeTimeString(beforeTime). - AfterTimeString(afterTime). - CurrencyGreaterThan(uint64(currencyGt)). - CurrencyLessThan(uint64(currencyLt)). - AddressString(address). - AddressRole(addressRole). - ExcludeCloseTo(excludeBool). - NextToken(token).Do(context.Background()) - return err -} - -func deprecatedIUseToSearchForAnAccountWithAppIdAndToken(indexer, assetIndex, limit, currencyGreater, currencyLesser int, authAddr string, appId int, token string) error { - return iUseToSearchForAnAccount(indexer, assetIndex, limit, currencyGreater, currencyLesser, authAddr, appId, "false", token) -} - -func iUseToSearchForAnAccount(clientNum, assetIndex, limit, currencyGreater, currencyLesser int, authAddr string, applicationId int, includeAll, token string) error { - ic := indexerClients[clientNum] - var err error - query := ic.SearchAccounts(). - AssetID(uint64(assetIndex)). - Limit(uint64(limit)). - CurrencyGreaterThan(uint64(currencyGreater)). - CurrencyLessThan(uint64(currencyLesser)). - AuthAddress(authAddr). - ApplicationId(uint64(applicationId)). - NextToken(token) - if ia, err := strconv.ParseBool(includeAll); err == nil && ia { - query.IncludeAll(ia) - } - response, err = query.Do(context.Background()) - return err -} diff --git a/test/steps_test.go b/test/steps_test.go index 9d581c9f..410e1f79 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -215,7 +215,6 @@ func TestMain(m *testing.M) { FeatureContext(s) AlgodClientV2Context(s) IndexerUnitTestContext(s) - IndexerIntegrationTestContext(s) TransactionsUnitContext(s) ApplicationsContext(s) ApplicationsUnitContext(s) @@ -318,14 +317,10 @@ func FeatureContext(s *godog.Suite) { s.Step(`^it should still be the same amount of microalgos (\d+)`, checkAlgos) s.Step(`I get account information`, accInfo) s.Step("I sign the bid", signBid) - s.Step("I get transactions by address only", txnsByAddrOnly) - s.Step("I get transactions by address and date", txnsByAddrDate) s.Step(`key registration transaction parameters (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)" "([^"]*)" (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)`, keyregTxnParams) s.Step("I create the key registration transaction", createKeyregTxn) s.Step(`default V2 key registration transaction "([^"]*)"`, createKeyregWithStateProof) - s.Step(`^I get recent transactions, limited by (\d+) transactions$`, getTxnsByCount) s.Step(`^I can get account information`, newAccInfo) - s.Step(`^I can get the transaction by ID$`, txnbyID) s.Step("asset test fixture", createAssetTestFixture) s.Step(`^default asset creation transaction with total issuance (\d+)$`, defaultAssetCreateTxn) s.Step(`^I update the asset index$`, getAssetIndex) @@ -404,7 +399,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the resulting source map is the same as the json "([^"]*)"$`, theResultingSourceMapIsTheSameAsTheJson) s.Step(`^getting the line associated with a pc "([^"]*)" equals "([^"]*)"$`, gettingTheLineAssociatedWithAPcEquals) s.Step(`^getting the last pc associated with a line "([^"]*)" equals "([^"]*)"$`, gettingTheLastPcAssociatedWithALineEquals) - + s.BeforeScenario(func(interface{}) { stxObj = types.SignedTxn{} abiMethods = nil @@ -1083,11 +1078,14 @@ func sendMsigTxn() error { } func checkTxn() error { + fmt.Print("ZZZZZZZ 1") waitForAlgodInDevMode() + fmt.Print("ZZZZZZZ 2") _, err := acl.PendingTransactionInformation(txid) if err != nil { return err } + fmt.Print("ZZZZZZZ 3") if txn.Sender.String() != "" && txn.Sender.String() != "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" { _, err = acl.TransactionInformation(txn.Sender.String(), txid) } else { @@ -1096,13 +1094,7 @@ func checkTxn() error { if err != nil { return err } - _, err = acl.TransactionByID(txid) - return err -} - -func txnbyID() error { - var err error - waitForAlgodInDevMode() + fmt.Print("ZZZZZZZ 4") _, err = acl.TransactionByID(txid) return err } @@ -1250,17 +1242,6 @@ func txnsByAddrRound() error { return err } -func txnsByAddrOnly() error { - _, err := acl.TransactionsByAddrLimit(accounts[0], 10) - return err -} - -func txnsByAddrDate() error { - fromDate := time.Now().Format("2006-01-02") - _, err := acl.TransactionsByAddrForDate(accounts[0], fromDate, fromDate) - return err -} - func txnsPending() error { _, err := acl.GetPendingTransactions(10) return err @@ -1534,11 +1515,6 @@ func createKeyregWithStateProof(keyregType string) (err error) { return err } -func getTxnsByCount(cnt int) error { - _, err := acl.TransactionsByAddrLimit(accounts[0], uint64(cnt)) - return err -} - func createAssetTestFixture() error { assetTestFixture.Creator = "" assetTestFixture.AssetIndex = 1 From 62ab5572b23c7d59848d59ac6ac8465306ff3218 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Tue, 16 Aug 2022 23:29:34 -0500 Subject: [PATCH 03/16] dependent 2nd order removals --- Makefile | 6 ++++-- test-harness.sh | 2 +- test/algodclientv2_test.go | 3 +-- test/applications_integration_test.go | 2 +- test/applications_unit_test.go | 20 ----------------- test/helpers.go | 31 --------------------------- test/steps_test.go | 24 ++++++++------------- test/transactions_test.go | 23 -------------------- 8 files changed, 16 insertions(+), 95 deletions(-) diff --git a/Makefile b/Makefile index 87476ee5..6c487400 100644 --- a/Makefile +++ b/Makefile @@ -18,13 +18,15 @@ build: generate test: go test $(TEST_SOURCES_NO_CUCUMBER) +UNITS = "@unit.sourcemap,@unit.offline,@unit.algod,@unit.indexer,@unit.transactions.keyreg,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231,@unit.responses.genesis,@unit.feetest,@unit.indexer.logs,@unit.abijson,@unit.abijson.byname,@unit.transactions.payment,@unit.atomic_transaction_composer,@unit.responses.unlimited_assets,@unit.indexer.ledger_refactoring,@unit.algod.ledger_refactoring,@unit.dryrun.trace.application" unit: go test $(TEST_SOURCES_NO_CUCUMBER) - cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@unit.sourcemap,@unit.offline,@unit.algod,@unit.indexer,@unit.transactions.keyreg,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231,@unit.responses.genesis,@unit.feetest,@unit.indexer.logs,@unit.abijson,@unit.abijson.byname,@unit.transactions.payment,@unit.atomic_transaction_composer,@unit.responses.unlimited_assets,@unit.indexer.ledger_refactoring,@unit.algod.ledger_refactoring,@unit.dryrun.trace.application" --test.v . + cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(UNITS) --test.v . +INTEGRATIONS = "@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" integration: go test $(TEST_SOURCES_NO_CUCUMBER) - cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" --test.v . + cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS) --test.v . harness: ./test-harness.sh diff --git a/test-harness.sh b/test-harness.sh index e739a850..8e318f86 100755 --- a/test-harness.sh +++ b/test-harness.sh @@ -28,7 +28,7 @@ git clone --depth 1 --single-branch --branch "$SDK_TESTING_BRANCH" "$SDK_TESTING if [[ $OVERWRITE_TESTING_ENVIRONMENT == 1 ]]; then - echo "$THIS: OVERWRITE downloaded $SDK_TESTING_HARNESS/.env with $ENV_FILE:" + echo "$THIS: OVERWRITE replaced $SDK_TESTING_HARNESS/.env with $ENV_FILE:" cp "$ENV_FILE" "$SDK_TESTING_HARNESS"/.env fi diff --git a/test/algodclientv2_test.go b/test/algodclientv2_test.go index db889d48..e804ad4c 100644 --- a/test/algodclientv2_test.go +++ b/test/algodclientv2_test.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/algorand/go-algorand-sdk/client/v2/algod" - "github.com/algorand/go-algorand-sdk/client/v2/common/models" modelsV2 "github.com/algorand/go-algorand-sdk/client/v2/common/models" "github.com/algorand/go-algorand-sdk/types" @@ -198,7 +197,7 @@ func weMakeAGetBlockCallAgainstBlockNumberWithFormat(blocknum int, format string return weMakeAGetBlockCallAgainstBlockNumber(blocknum) } -var dryrunResponse models.DryrunResponse +var dryrunResponse modelsV2.DryrunResponse func weMakeAnyDryrunCall() (err error) { algodClient, err := algod.MakeClient(mockServer.URL, "") diff --git a/test/applications_integration_test.go b/test/applications_integration_test.go index 035a6d7c..14f9ab06 100644 --- a/test/applications_integration_test.go +++ b/test/applications_integration_test.go @@ -210,7 +210,7 @@ func iBuildAnApplicationTransaction( } case "call": - tx, err = future.MakeApplicationCallTx(applicationId, args, accs, + tx, _ = future.MakeApplicationCallTx(applicationId, args, accs, fApp, fAssets, types.NoOpOC, approvalP, clearP, gSchema, lSchema, suggestedParams, transientAccount.Address, nil, types.Digest{}, [32]byte{}, types.Address{}) case "optin": diff --git a/test/applications_unit_test.go b/test/applications_unit_test.go index e0b8e442..060a5af2 100644 --- a/test/applications_unit_test.go +++ b/test/applications_unit_test.go @@ -2,9 +2,7 @@ package test import ( "context" - "encoding/base64" "fmt" - "github.com/algorand/go-algorand-sdk/types" "github.com/cucumber/godog" @@ -37,24 +35,6 @@ func feeFieldNotInTxn() error { return nil } -func getSuggestedParams( - fee, fv, lv uint64, - gen, ghb64 string, - flat bool) (types.SuggestedParams, error) { - gh, err := base64.StdEncoding.DecodeString(ghb64) - if err != nil { - return types.SuggestedParams{}, err - } - return types.SuggestedParams{ - Fee: types.MicroAlgos(fee), - GenesisID: gen, - GenesisHash: gh, - FirstRoundValid: types.Round(fv), - LastRoundValid: types.Round(lv), - FlatFee: flat, - }, err -} - func weMakeAGetAssetByIDCall(assetID int) error { clt, err := algod.MakeClient(mockServer.URL, "") if err != nil { diff --git a/test/helpers.go b/test/helpers.go index 2519acf6..c9e36142 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -10,8 +10,6 @@ import ( "os" "path" "strings" - - "github.com/algorand/go-algorand-sdk/client/v2/common/models" ) func loadMockJsons(commaDelimitedFilenames, pathToJsons string) ([][]byte, error) { @@ -96,35 +94,6 @@ func expectErrorStringToContain(contains string) error { "actual error string: %s", contains, globalErrForExamination.Error()) } -func comparisonCheck(varname string, expected, actual interface{}) error { - if expected != actual { - return fmt.Errorf("expected %s value %v did not match actual value %v", varname, expected, actual) - } - return nil -} - -func findAssetInHoldingsList(list []models.AssetHolding, desiredId uint64) (models.AssetHolding, error) { - for _, holding := range list { - if holding.AssetId == desiredId { - return holding, nil - } - } - return models.AssetHolding{}, fmt.Errorf("could not find asset ID %d in passed list of asset holdings", desiredId) -} - -func getSigtypeFromTransaction(transaction models.Transaction) string { - if len(transaction.Signature.Sig) != 0 { - return "sig" - } - if len(transaction.Signature.Multisig.Subsignature) != 0 { - return "msig" - } - if len(transaction.Signature.Logicsig.MultisigSignature.Subsignature) != 0 || - len(transaction.Signature.Logicsig.Logic) != 0 { - return "lsig" - } - return "unknown sigtype" -} func loadResource(filepath string) ([]byte, error) { return ioutil.ReadFile(path.Join("features", "resources", filepath)) diff --git a/test/steps_test.go b/test/steps_test.go index 410e1f79..66a0dce7 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -95,7 +95,6 @@ var votekd uint64 var nonpart bool var num string var backupTxnSender string -var groupTxnBytes []byte var data []byte var sig types.Signature var abiMethod abi.Method @@ -978,10 +977,6 @@ func defaultTxn(iamt int, inote string) error { return defaultTxnWithAddress(iamt, inote, accounts[0]) } -func defaultTxnRekey(iamt int, inote string) error { - return defaultTxnWithAddress(iamt, inote, rekey) -} - func defaultMsigTxn(iamt int, inote string) error { var err error if inote != "none" { @@ -1077,15 +1072,13 @@ func sendMsigTxn() error { return nil } +// TODO: this needs to be modified/removed when v1 is no longer supported func checkTxn() error { - fmt.Print("ZZZZZZZ 1") waitForAlgodInDevMode() - fmt.Print("ZZZZZZZ 2") _, err := acl.PendingTransactionInformation(txid) if err != nil { return err } - fmt.Print("ZZZZZZZ 3") if txn.Sender.String() != "" && txn.Sender.String() != "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" { _, err = acl.TransactionInformation(txn.Sender.String(), txid) } else { @@ -1094,9 +1087,10 @@ func checkTxn() error { if err != nil { return err } - fmt.Print("ZZZZZZZ 4") - _, err = acl.TransactionByID(txid) - return err + // v1 indexer dependency: + // _, err = acl.TransactionByID(txid) + // return err + return nil } func txnFail() error { @@ -1124,7 +1118,7 @@ func signBothEqual() error { func signMsigKmd() error { kcl.ImportMultisig(handle, msig.Version, msig.Threshold, msig.Pks) - decoded, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(pk) + decoded, _ := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(pk) s, err := kcl.MultisigSignTransaction(handle, walletPswd, txn, decoded[:32], types.MultisigSig{}) if err != nil { return err @@ -1161,7 +1155,7 @@ func readTxn(encodedTxn string, inum string) error { } num = inum path = filepath.Dir(filepath.Dir(path)) + "/temp/old" + num + ".tx" - err = ioutil.WriteFile(path, encodedBytes, 0644) + _ = ioutil.WriteFile(path, encodedBytes, 0644) data, err := ioutil.ReadFile(path) if err != nil { return err @@ -1187,10 +1181,10 @@ func checkEnc() error { return err } pathold := filepath.Dir(filepath.Dir(path)) + "/temp/old" + num + ".tx" - dataold, err := ioutil.ReadFile(pathold) + dataold, _ := ioutil.ReadFile(pathold) pathnew := filepath.Dir(filepath.Dir(path)) + "/temp/raw" + num + ".tx" - datanew, err := ioutil.ReadFile(pathnew) + datanew, _ := ioutil.ReadFile(pathnew) if bytes.Equal(dataold, datanew) { return nil diff --git a/test/transactions_test.go b/test/transactions_test.go index 3c22d08e..ca3e6e72 100644 --- a/test/transactions_test.go +++ b/test/transactions_test.go @@ -16,7 +16,6 @@ import ( "golang.org/x/crypto/ed25519" ) -var signingAccount crypto.Account var sk1 ed25519.PrivateKey var addr1 types.Address @@ -37,28 +36,6 @@ func aSigningAccountWithAddressAndMnemonic(address, mnem string) error { return err } -func suggestedTransactionParametersTxn(fee int, flatFee string, firstValid, LastValid int, genesisHash, genesisId string) error { - if flatFee != "true" && flatFee != "false" { - return fmt.Errorf("flatFee must be either 'true' or 'false'") - } - - genHash, err := base64.StdEncoding.DecodeString(genesisHash) - if err != nil { - return err - } - - sugParams = types.SuggestedParams{ - Fee: types.MicroAlgos(fee), - GenesisID: genesisId, - GenesisHash: genHash, - FirstRoundValid: types.Round(firstValid), - LastRoundValid: types.Round(LastValid), - FlatFee: flatFee == "true", - } - - return nil -} - func signTheTransaction() error { var err error txid, stx, err = crypto.SignTransaction(sk1, tx) From a601bc3f563be9404cae824a4c9d06d35538ad83 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 08:35:57 -0500 Subject: [PATCH 04/16] per CR: try to percolate a read error, instead of sweeping under the rug the unused result. --- test/steps_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/steps_test.go b/test/steps_test.go index 66a0dce7..ec33a828 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -1184,7 +1184,10 @@ func checkEnc() error { dataold, _ := ioutil.ReadFile(pathold) pathnew := filepath.Dir(filepath.Dir(path)) + "/temp/raw" + num + ".tx" - datanew, _ := ioutil.ReadFile(pathnew) + datanew, err := ioutil.ReadFile(pathnew) + if err != nil { + return fmt.Errorf("checkEnc: %w", err) + } if bytes.Equal(dataold, datanew) { return nil From 2c6b93aa08699205a8438e59731cb315b3e0ff76 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 08:40:57 -0500 Subject: [PATCH 05/16] unswallow more err's --- test/steps_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/steps_test.go b/test/steps_test.go index ec33a828..22be8fc1 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -1118,7 +1118,10 @@ func signBothEqual() error { func signMsigKmd() error { kcl.ImportMultisig(handle, msig.Version, msig.Threshold, msig.Pks) - decoded, _ := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(pk) + decoded, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(pk) + if err != nil { + return fmt.Errorf("signMsigKmd: %w", err) + } s, err := kcl.MultisigSignTransaction(handle, walletPswd, txn, decoded[:32], types.MultisigSig{}) if err != nil { return err @@ -1155,7 +1158,10 @@ func readTxn(encodedTxn string, inum string) error { } num = inum path = filepath.Dir(filepath.Dir(path)) + "/temp/old" + num + ".tx" - _ = ioutil.WriteFile(path, encodedBytes, 0644) + err = ioutil.WriteFile(path, encodedBytes, 0644) + if err != nil { + return fmt.Errorf("readTxn: %w", err) + } data, err := ioutil.ReadFile(path) if err != nil { return err From e293ed52584ee09d2f48ab1f9ed6b0fb49202cad Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 10:58:21 -0500 Subject: [PATCH 06/16] don't default to deleting local features, and introduce verbose mode --- .test-env | 6 ++++++ test-harness.sh | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.test-env b/.test-env index 3abc5e33..0bf7121c 100644 --- a/.test-env +++ b/.test-env @@ -3,6 +3,12 @@ SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing" SDK_TESTING_BRANCH="trim-indexer" SDK_TESTING_HARNESS="test-harness" +VERBOSE_HARNESS=0 + +# WARNING: If set to 1, new features will be LOST when downloading the test harness. +# REGARDLESS: modified features are ALWAYS overwritten. +REMOVE_LOCAL_FEATURES=0 + # WARNING: Be careful when turning on the next variable. # In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env` OVERWRITE_TESTING_ENVIRONMENT=0 \ No newline at end of file diff --git a/test-harness.sh b/test-harness.sh index 8e318f86..3d3964fe 100755 --- a/test-harness.sh +++ b/test-harness.sh @@ -33,9 +33,18 @@ if [[ $OVERWRITE_TESTING_ENVIRONMENT == 1 ]]; then fi ## Copy feature files into the project resources -rm -rf test/features -mkdir -p test/features -cp -r "$SDK_TESTING_HARNESS"/features/* test/features +if [[ $REMOVE_LOCAL_FEATURES == 1 ]]; then + echo "$THIS: OVERWRITE wipes clean tests/features" + if [[ $VERBOSE_HARNESS == 1 ]]; then + ( tree tests/features && echo "$THIS: see the previous for files deleted" ) || true + fi + rm -rf tests/features +fi +mkdir -p tests/features +cp -r "$SDK_TESTING_HARNESS"/features/* tests/features +if [[ $VERBOSE_HARNESS == 1 ]]; then + ( tree tests/features && echo "$THIS: see the previous for files copied over" ) || true +fi echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s" From 5fd47ef2996ec7d3b850dbeb1a320fcc64e2bd78 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 11:08:04 -0500 Subject: [PATCH 07/16] Update test-harness.sh --- test-harness.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-harness.sh b/test-harness.sh index 3d3964fe..04f54c7c 100755 --- a/test-harness.sh +++ b/test-harness.sh @@ -36,14 +36,14 @@ fi if [[ $REMOVE_LOCAL_FEATURES == 1 ]]; then echo "$THIS: OVERWRITE wipes clean tests/features" if [[ $VERBOSE_HARNESS == 1 ]]; then - ( tree tests/features && echo "$THIS: see the previous for files deleted" ) || true + ( tree test/features && echo "$THIS: see the previous for files deleted" ) || true fi - rm -rf tests/features + rm -rf test/features fi -mkdir -p tests/features +mkdir -p test/features cp -r "$SDK_TESTING_HARNESS"/features/* tests/features if [[ $VERBOSE_HARNESS == 1 ]]; then - ( tree tests/features && echo "$THIS: see the previous for files copied over" ) || true + ( tree test/features && echo "$THIS: see the previous for files copied over" ) || true fi echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s" From 46e31385949264815bc09c1ea0cd4a5558d925a8 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 11:13:45 -0500 Subject: [PATCH 08/16] variable for destination test directory --- test-harness.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test-harness.sh b/test-harness.sh index 04f54c7c..dec7d15f 100755 --- a/test-harness.sh +++ b/test-harness.sh @@ -6,6 +6,7 @@ START=$(date "+%s") THIS=$(basename "$0") ENV_FILE=".test-env" +TEST_DIR="test" set -a source "$ENV_FILE" @@ -34,16 +35,16 @@ fi ## Copy feature files into the project resources if [[ $REMOVE_LOCAL_FEATURES == 1 ]]; then - echo "$THIS: OVERWRITE wipes clean tests/features" + echo "$THIS: OVERWRITE wipes clean $TEST_DIR/features" if [[ $VERBOSE_HARNESS == 1 ]]; then - ( tree test/features && echo "$THIS: see the previous for files deleted" ) || true + ( tree $TEST_DIR/features && echo "$THIS: see the previous for files deleted" ) || true fi - rm -rf test/features + rm -rf $TEST_DIR/features fi -mkdir -p test/features -cp -r "$SDK_TESTING_HARNESS"/features/* tests/features +mkdir -p $TEST_DIR/features +cp -r "$SDK_TESTING_HARNESS"/features/* $TEST_DIR/features if [[ $VERBOSE_HARNESS == 1 ]]; then - ( tree test/features && echo "$THIS: see the previous for files copied over" ) || true + ( tree $TEST_DIR/features && echo "$THIS: see the previous for files copied over" ) || true fi echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s" From 4c521a50337c12391d5e852f39e1f4a9805e2c05 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 17 Aug 2022 17:00:45 -0500 Subject: [PATCH 09/16] Update .test-env --- .test-env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.test-env b/.test-env index 0bf7121c..ab9a64c1 100644 --- a/.test-env +++ b/.test-env @@ -11,4 +11,4 @@ REMOVE_LOCAL_FEATURES=0 # WARNING: Be careful when turning on the next variable. # In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env` -OVERWRITE_TESTING_ENVIRONMENT=0 \ No newline at end of file +OVERWRITE_TESTING_ENVIRONMENT=0 From 9d842a99bd3bc9f646b4e4616673ebe1c1bdd8c5 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Thu, 18 Aug 2022 12:43:32 -0500 Subject: [PATCH 10/16] bite the bullet and seperate out the cucumber tags --- Makefile | 8 ++++---- test/integration.tags | 13 +++++++++++++ test/unit.tags | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 test/integration.tags create mode 100644 test/unit.tags diff --git a/Makefile b/Makefile index 6c487400..0dcd07c9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ SRCPATH := $(shell pwd) TEST_SOURCES := $(shell cd $(SRCPATH) && go list ./...) TEST_SOURCES_NO_CUCUMBER := $(shell cd $(SRCPATH) && go list ./... | grep -v test) +UNIT_TAGS := $(shell awk '{print $2}' test/unit.tags | paste -s -d, -) +INTEGRATIONS_TAGS := $(shell awk '{print $2}' test/integration.tags | paste -s -d, -) GO_IMAGE := golang:$(subst go,,$(shell go version | cut -d' ' -f 3 | cut -d'.' -f 1,2))-stretch lint: @@ -18,15 +20,13 @@ build: generate test: go test $(TEST_SOURCES_NO_CUCUMBER) -UNITS = "@unit.sourcemap,@unit.offline,@unit.algod,@unit.indexer,@unit.transactions.keyreg,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231,@unit.responses.genesis,@unit.feetest,@unit.indexer.logs,@unit.abijson,@unit.abijson.byname,@unit.transactions.payment,@unit.atomic_transaction_composer,@unit.responses.unlimited_assets,@unit.indexer.ledger_refactoring,@unit.algod.ledger_refactoring,@unit.dryrun.trace.application" unit: go test $(TEST_SOURCES_NO_CUCUMBER) - cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(UNITS) --test.v . + cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(UNIT_TAGS) --test.v . -INTEGRATIONS = "@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" integration: go test $(TEST_SOURCES_NO_CUCUMBER) - cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS) --test.v . + cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS_TAGS) --test.v . harness: ./test-harness.sh diff --git a/test/integration.tags b/test/integration.tags new file mode 100644 index 00000000..e0ea6997 --- /dev/null +++ b/test/integration.tags @@ -0,0 +1,13 @@ +@abi +@algod +@applications.verified +@assets +@auction +@c2c +@compile +@compile.sourcemap +@dryrun +@kmd +@rekey_v1 +@send +@send.keyregtxn \ No newline at end of file diff --git a/test/unit.tags b/test/unit.tags new file mode 100644 index 00000000..9dc6ffc2 --- /dev/null +++ b/test/unit.tags @@ -0,0 +1,26 @@ +@unit.abijson +@unit.abijson.byname +@unit.algod +@unit.algod.ledger_refactoring +@unit.applications +@unit.atomic_transaction_composer +@unit.dryrun +@unit.dryrun.trace.application +@unit.feetest +@unit.indexer +@unit.indexer.ledger_refactoring +@unit.indexer.logs +@unit.indexer.rekey +@unit.offline +@unit.rekey +@unit.responses +@unit.responses.231 +@unit.responses.genesis +@unit.responses.messagepack +@unit.responses.messagepack.231 +@unit.responses.unlimited_assets +@unit.sourcemap +@unit.tealsign +@unit.transactions +@unit.transactions.keyreg +@unit.transactions.payment \ No newline at end of file From 9514d6a35300301ceeb12cf400011022f024ad82 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Thu, 18 Aug 2022 14:21:17 -0500 Subject: [PATCH 11/16] quotes --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0dcd07c9..8a00efa1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ SRCPATH := $(shell pwd) TEST_SOURCES := $(shell cd $(SRCPATH) && go list ./...) TEST_SOURCES_NO_CUCUMBER := $(shell cd $(SRCPATH) && go list ./... | grep -v test) -UNIT_TAGS := $(shell awk '{print $2}' test/unit.tags | paste -s -d, -) -INTEGRATIONS_TAGS := $(shell awk '{print $2}' test/integration.tags | paste -s -d, -) +UNIT_TAGS := "$(shell awk '{print $2}' test/unit.tags | paste -s -d, -)" +INTEGRATIONS_TAGS := "$(shell awk '{print $2}' test/integration.tags | paste -s -d, -)" GO_IMAGE := golang:$(subst go,,$(shell go version | cut -d' ' -f 3 | cut -d'.' -f 1,2))-stretch lint: From dc02aebb3633d13e73eb29387e413439b3557db3 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Sun, 21 Aug 2022 18:10:49 -0500 Subject: [PATCH 12/16] display-all-go-steps used by Unused Steps Script --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 8a00efa1..bd04d357 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ integration: go test $(TEST_SOURCES_NO_CUCUMBER) cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS_TAGS) --test.v . +display-all-go-steps: + find test -name "*.go" | xargs grep "github.com/cucumber/godog" 2>/dev/null | cut -d: -f1 | sort | uniq | xargs grep -Eo "Step[(].[^\`]+" | awk '{sub(/:Step\(./,":")} 1' | sed -E 's/", [a-zA-Z0-9]+\)//g' #| grep "with path" + harness: ./test-harness.sh From 0d40c4a84ddc0ac2e232a2ea794322d6f60e9b17 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Sun, 21 Aug 2022 18:27:26 -0500 Subject: [PATCH 13/16] removing steps after Unused Steps Analysis Script --- test/algodclientv2_test.go | 50 ++++-------- test/indexer_unit_test.go | 14 +--- test/steps_test.go | 160 ------------------------------------- 3 files changed, 21 insertions(+), 203 deletions(-) diff --git a/test/algodclientv2_test.go b/test/algodclientv2_test.go index e804ad4c..b8550f99 100644 --- a/test/algodclientv2_test.go +++ b/test/algodclientv2_test.go @@ -19,7 +19,6 @@ func AlgodClientV2Context(s *godog.Suite) { s.Step(`^we make any Pending Transaction Information call$`, weMakeAnyPendingTransactionInformationCall) s.Step(`^the parsed Pending Transaction Information response should have sender "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make any Pending Transactions Information call$`, weMakeAnyPendingTransactionsInformationCall) - s.Step(`^the parsed Pending Transactions Information response should have sender "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make any Send Raw Transaction call$`, weMakeAnySendRawTransactionCall) s.Step(`^the parsed Send Raw Transaction response should have txid "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make any Pending Transactions By Address call$`, weMakeAnyPendingTransactionsByAddressCall) @@ -37,11 +36,8 @@ func AlgodClientV2Context(s *godog.Suite) { s.Step(`^we make any Suggested Transaction Parameters call$`, weMakeAnySuggestedTransactionParametersCall) s.Step(`^the parsed Suggested Transaction Parameters response should have first round valid of (\d+)$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^expect the path used to be "([^"]*)"$`, expectThePathUsedToBe) - s.Step(`^we make a Pending Transaction Information against txid "([^"]*)" with max (\d+)$`, weMakeAPendingTransactionInformationAgainstTxidWithMax) - s.Step(`^we make a Pending Transactions By Address call against account "([^"]*)" and max (\d+)$`, weMakeAPendingTransactionsByAddressCallAgainstAccountAndMax) s.Step(`^we make a Status after Block call with round (\d+)$`, weMakeAStatusAfterBlockCallWithRound) s.Step(`^we make an Account Information call against account "([^"]*)"$`, weMakeAnAccountInformationCallAgainstAccount) - s.Step(`^we make a Get Block call against block number (\d+)$`, weMakeAGetBlockCallAgainstBlockNumber) s.Step(`^the parsed Pending Transactions Information response should contain an array of len (\d+) and element number (\d+) should have sender "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make a Pending Transaction Information against txid "([^"]*)" with format "([^"]*)"$`, weMakeAPendingTransactionInformationAgainstTxidWithFormat) s.Step(`^we make a Pending Transaction Information with max (\d+) and format "([^"]*)"$`, weMakeAPendingTransactionInformationWithMaxAndFormat) @@ -119,24 +115,6 @@ func weMakeAnySuggestedTransactionParametersCall() error { return weMakeAnyCallTo("algod", "TransactionParams") } -func weMakeAPendingTransactionInformationAgainstTxidWithMax(txid string, max int) error { - algodClient, err := algod.MakeClient(mockServer.URL, "") - if err != nil { - return err - } - _, _, globalErrForExamination = algodClient.PendingTransactionInformation(txid).Do(context.Background()) - return nil -} - -func weMakeAPendingTransactionsByAddressCallAgainstAccountAndMax(account string, max int) error { - algodClient, err := algod.MakeClient(mockServer.URL, "") - if err != nil { - return err - } - _, _, globalErrForExamination = algodClient.PendingTransactionsByAddress(account).Max(uint64(max)).Do(context.Background()) - return nil -} - func weMakeAStatusAfterBlockCallWithRound(round int) error { algodClient, err := algod.MakeClient(mockServer.URL, "") if err != nil { @@ -155,22 +133,18 @@ func weMakeAnAccountInformationCallAgainstAccount(account string) error { return nil } -func weMakeAGetBlockCallAgainstBlockNumber(blocknum int) error { +func weMakeAPendingTransactionInformationAgainstTxidWithFormat(txid, format string) error { + if format != "msgpack" { + return fmt.Errorf("this sdk does not support format %s", format) + } algodClient, err := algod.MakeClient(mockServer.URL, "") if err != nil { return err } - _, globalErrForExamination = algodClient.Block(uint64(blocknum)).Do(context.Background()) + _, _, globalErrForExamination = algodClient.PendingTransactionInformation(txid).Do(context.Background()) return nil } -func weMakeAPendingTransactionInformationAgainstTxidWithFormat(txid, format string) error { - if format != "msgpack" { - return fmt.Errorf("this sdk does not support format %s", format) - } - return weMakeAPendingTransactionInformationAgainstTxidWithMax(txid, 0) -} - func weMakeAPendingTransactionInformationWithMaxAndFormat(max int, format string) error { if format != "msgpack" { return fmt.Errorf("this sdk does not support format %s", format) @@ -187,14 +161,24 @@ func weMakeAPendingTransactionsByAddressCallAgainstAccountAndMaxAndFormat(accoun if format != "msgpack" { return fmt.Errorf("this sdk does not support format %s", format) } - return weMakeAPendingTransactionsByAddressCallAgainstAccountAndMax(account, max) + algodClient, err := algod.MakeClient(mockServer.URL, "") + if err != nil { + return err + } + _, _, globalErrForExamination = algodClient.PendingTransactionsByAddress(account).Max(uint64(max)).Do(context.Background()) + return nil } func weMakeAGetBlockCallAgainstBlockNumberWithFormat(blocknum int, format string) error { if format != "msgpack" { return fmt.Errorf("this sdk does not support format %s", format) } - return weMakeAGetBlockCallAgainstBlockNumber(blocknum) + algodClient, err := algod.MakeClient(mockServer.URL, "") + if err != nil { + return err + } + _, globalErrForExamination = algodClient.Block(uint64(blocknum)).Do(context.Background()) + return nil } var dryrunResponse modelsV2.DryrunResponse diff --git a/test/indexer_unit_test.go b/test/indexer_unit_test.go index 1aa033f9..47e6af97 100644 --- a/test/indexer_unit_test.go +++ b/test/indexer_unit_test.go @@ -36,8 +36,6 @@ func IndexerUnitTestContext(s *godog.Suite) { s.Step(`^we make a Lookup Block call against round (\d+)$`, weMakeALookupBlockCallAgainstRound) s.Step(`^we make a Lookup Account by ID call against account "([^"]*)" with round (\d+)$`, weMakeALookupAccountByIDCallAgainstAccountWithRound) s.Step(`^we make a Lookup Asset by ID call against asset index (\d+)$`, weMakeALookupAssetByIDCallAgainstAssetIndex) - s.Step(`^we make a Search For Transactions call with account "([^"]*)" NotePrefix "([^"]*)" TxType "([^"]*)" SigType "([^"]*)" txid "([^"]*)" round (\d+) minRound (\d+) maxRound (\d+) limit (\d+) beforeTime (\d+) afterTime (\d+) currencyGreaterThan (\d+) currencyLessThan (\d+) assetIndex (\d+) addressRole "([^"]*)" ExcluseCloseTo "([^"]*)"$`, weMakeASearchForTransactionsCallWithAccountNotePrefixTxTypeSigTypeTxidRoundMinRoundMaxRoundLimitBeforeTimeAfterTimeCurrencyGreaterThanCurrencyLessThanAssetIndexAddressRoleExcluseCloseTo) - s.Step(`^we make a SearchForAssets call with limit (\d+) creator "([^"]*)" name "([^"]*)" unit "([^"]*)" index (\d+) and afterAsset (\d+)$`, weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndexAndAfterAsset) s.Step(`^mock server recording request paths`, mockServerRecordingRequestPaths) s.Step(`^we make a Search For Transactions call with account "([^"]*)" NotePrefix "([^"]*)" TxType "([^"]*)" SigType "([^"]*)" txid "([^"]*)" round (\d+) minRound (\d+) maxRound (\d+) limit (\d+) beforeTime "([^"]*)" afterTime "([^"]*)" currencyGreaterThan (\d+) currencyLessThan (\d+) assetIndex (\d+) addressRole "([^"]*)" ExcluseCloseTo "([^"]*)"$`, weMakeASearchForTransactionsCallWithAccountNotePrefixTxTypeSigTypeTxidRoundMinRoundMaxRoundLimitBeforeTimeAfterTimeCurrencyGreaterThanCurrencyLessThanAssetIndexAddressRoleExcluseCloseTo) s.Step(`^we make a SearchForAssets call with limit (\d+) creator "([^"]*)" name "([^"]*)" unit "([^"]*)" index (\d+)$`, weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndex) @@ -240,28 +238,24 @@ func weMakeASearchForTransactionsCallWithAccountNotePrefixTxTypeSigTypeTxidRound return nil } -func weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndexAndAfterAsset(limit int, creator, name, unit string, assetIndex, _ int) error { +func weMakeASearchAccountsCallWithAssetIDLimitCurrencyGreaterThanCurrencyLessThanAndRound(assetID, limit, currencyGreater, currencyLesser, round int) error { indexerClient, err := indexer.MakeClient(mockServer.URL, "") if err != nil { return err } - _, globalErrForExamination = indexerClient.SearchForAssets().AssetID(uint64(assetIndex)).Limit(uint64(limit)).Creator(creator).Name(name).Unit(unit).Do(context.Background()) + _, globalErrForExamination = indexerClient.SearchAccounts().AssetID(uint64(assetID)).Limit(uint64(limit)).CurrencyLessThan(uint64(currencyLesser)).CurrencyGreaterThan(uint64(currencyGreater)).Round(uint64(round)).Do(context.Background()) return nil } -func weMakeASearchAccountsCallWithAssetIDLimitCurrencyGreaterThanCurrencyLessThanAndRound(assetID, limit, currencyGreater, currencyLesser, round int) error { +func weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndex(limit int, creator, name, unit string, index int) error { indexerClient, err := indexer.MakeClient(mockServer.URL, "") if err != nil { return err } - _, globalErrForExamination = indexerClient.SearchAccounts().AssetID(uint64(assetID)).Limit(uint64(limit)).CurrencyLessThan(uint64(currencyLesser)).CurrencyGreaterThan(uint64(currencyGreater)).Round(uint64(round)).Do(context.Background()) + _, globalErrForExamination = indexerClient.SearchForAssets().AssetID(uint64(index)).Limit(uint64(limit)).Creator(creator).Name(name).Unit(unit).Do(context.Background()) return nil } -func weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndex(limit int, creator, name, unit string, index int) error { - return weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndexAndAfterAsset(limit, creator, name, unit, index, 0) -} - func weMakeALookupApplicationLogsByIDCallWithApplicationIDLimitMinRoundMaxRoundNextTokenSenderAndTxID(appID, limit, minRound, maxRound int, nextToken, sender, txID string) error { indexerClient, err := indexer.MakeClient(mockServer.URL, "") if err != nil { diff --git a/test/steps_test.go b/test/steps_test.go index 22be8fc1..f5528ef2 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -10,7 +10,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "math/rand" "os" "path" @@ -20,8 +19,6 @@ import ( "testing" "time" - "path/filepath" - "golang.org/x/crypto/ed25519" "github.com/algorand/go-algorand-sdk/abi" @@ -93,7 +90,6 @@ var votefst uint64 var votelst uint64 var votekd uint64 var nonpart bool -var num string var backupTxnSender string var data []byte var sig types.Signature @@ -238,7 +234,6 @@ func FeatureContext(s *godog.Suite) { s.Step("the wallet handle should not work", tryHandle) s.Step(`payment transaction parameters (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)" "([^"]*)" (\d+) "([^"]*)" "([^"]*)"`, txnParams) s.Step(`mnemonic for private key "([^"]*)"`, mnForSk) - s.Step("I create the payment transaction", createTxn) s.Step(`multisig addresses "([^"]*)"`, msigAddresses) s.Step("I create the multisig payment transaction$", createMsigTxn) s.Step("I create the multisig payment transaction with zero fee", createMsigTxnZeroFee) @@ -286,10 +281,6 @@ func FeatureContext(s *godog.Suite) { s.Step("the signed transaction should equal the kmd signed transaction", signBothEqual) s.Step("I sign the multisig transaction with kmd", signMsigKmd) s.Step("the multisig transaction should equal the kmd signed multisig transaction", signMsigBothEqual) - s.Step(`I read a transaction "([^"]*)" from file "([^"]*)"`, readTxn) - s.Step("I write the transaction to file", writeTxn) - s.Step("the transaction should still be the same", checkEnc) - s.Step("I do my part", createSaveTxn) s.Step(`^the node should be healthy`, nodeHealth) s.Step(`^I get the ledger supply`, ledger) s.Step(`^I get transactions by address and round`, txnsByAddrRound) @@ -316,8 +307,6 @@ func FeatureContext(s *godog.Suite) { s.Step(`^it should still be the same amount of microalgos (\d+)`, checkAlgos) s.Step(`I get account information`, accInfo) s.Step("I sign the bid", signBid) - s.Step(`key registration transaction parameters (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)" "([^"]*)" (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)`, keyregTxnParams) - s.Step("I create the key registration transaction", createKeyregTxn) s.Step(`default V2 key registration transaction "([^"]*)"`, createKeyregWithStateProof) s.Step(`^I can get account information`, newAccInfo) s.Step("asset test fixture", createAssetTestFixture) @@ -548,24 +537,6 @@ func mnForSk(mn string) error { } return err } - -func createTxn() error { - var err error - paramsToUse := types.SuggestedParams{ - Fee: types.MicroAlgos(fee), - GenesisID: gen, - GenesisHash: gh, - FirstRoundValid: types.Round(fv), - LastRoundValid: types.Round(lv), - FlatFee: false, - } - txn, err = future.MakePaymentTxn(a.String(), to, amt, note, close, paramsToUse) - if err != nil { - return err - } - return err -} - func msigAddresses(addresses string) error { var err error addrlist := strings.Fields(addresses) @@ -1147,85 +1118,6 @@ func signMsigBothEqual() error { } -func readTxn(encodedTxn string, inum string) error { - encodedBytes, err := base64.StdEncoding.DecodeString(encodedTxn) - if err != nil { - return err - } - path, err := os.Getwd() - if err != nil { - return err - } - num = inum - path = filepath.Dir(filepath.Dir(path)) + "/temp/old" + num + ".tx" - err = ioutil.WriteFile(path, encodedBytes, 0644) - if err != nil { - return fmt.Errorf("readTxn: %w", err) - } - data, err := ioutil.ReadFile(path) - if err != nil { - return err - } - err = msgpack.Decode(data, &stxObj) - return err -} - -func writeTxn() error { - path, err := os.Getwd() - if err != nil { - return err - } - path = filepath.Dir(filepath.Dir(path)) + "/temp/raw" + num + ".tx" - data := msgpack.Encode(stxObj) - err = ioutil.WriteFile(path, data, 0644) - return err -} - -func checkEnc() error { - path, err := os.Getwd() - if err != nil { - return err - } - pathold := filepath.Dir(filepath.Dir(path)) + "/temp/old" + num + ".tx" - dataold, _ := ioutil.ReadFile(pathold) - - pathnew := filepath.Dir(filepath.Dir(path)) + "/temp/raw" + num + ".tx" - datanew, err := ioutil.ReadFile(pathnew) - if err != nil { - return fmt.Errorf("checkEnc: %w", err) - } - - if bytes.Equal(dataold, datanew) { - return nil - } - return fmt.Errorf("should be equal") -} - -func createSaveTxn() error { - var err error - - amt = 100000 - pk = accounts[0] - params, err := acl.BuildSuggestedParams() - if err != nil { - return err - } - lastRound = uint64(params.FirstRoundValid) - txn, err = future.MakePaymentTxn(accounts[0], accounts[1], amt, note, "", params) - if err != nil { - return err - } - - path, err := os.Getwd() - if err != nil { - return err - } - path = filepath.Dir(filepath.Dir(path)) + "/temp/txn.tx" - data := msgpack.Encode(txn) - err = ioutil.WriteFile(path, data, 0644) - return err -} - func nodeHealth() error { err := acl.HealthCheck() return err @@ -1425,58 +1317,6 @@ func newAccInfo() error { return err } -func keyregTxnParams(ifee, ifv, ilv int, igh, ivotekey, iselkey string, ivotefst, ivotelst, ivotekd int, igen, inote string) error { - var err error - if inote != "none" { - note, err = base64.StdEncoding.DecodeString(inote) - if err != nil { - return err - } - } else { - note, err = base64.StdEncoding.DecodeString("") - if err != nil { - return err - } - } - gh, err = base64.StdEncoding.DecodeString(igh) - if err != nil { - return err - } - votekey = ivotekey - selkey = iselkey - fee = uint64(ifee) - fv = uint64(ifv) - lv = uint64(ilv) - votefst = uint64(ivotefst) - votelst = uint64(ivotelst) - votekd = uint64(ivotekd) - if igen != "none" { - gen = igen - } else { - gen = "" - } - if err != nil { - return err - } - return nil -} - -func createKeyregTxn() (err error) { - paramsToUse := types.SuggestedParams{ - Fee: types.MicroAlgos(fee), - GenesisID: gen, - GenesisHash: gh, - FirstRoundValid: types.Round(fv), - LastRoundValid: types.Round(lv), - FlatFee: false, - } - txn, err = future.MakeKeyRegTxn(a.String(), note, paramsToUse, votekey, selkey, votefst, votelst, votekd) - if err != nil { - return err - } - return err -} - func createKeyregWithStateProof(keyregType string) (err error) { params, err := acl.BuildSuggestedParams() if err != nil { From be7c1517d7163102a08400dbcd39249c10dbd2a9 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Mon, 22 Aug 2022 09:49:32 -0500 Subject: [PATCH 14/16] add note about starting test harness without running all tests --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c224d501..17ff328c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ In `client/v2` the `indexer` package contains a client for the Algorand Indexer # SDK Development -Run tests with `make docker-test` +Run tests with `make docker-test`. To set up the sandbox-based test harness without standing up the go-algorand docker image use `make harness`. # Quick Start From 4cd2d66e1242e90f184292802d044609190bfc51 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Mon, 22 Aug 2022 11:03:10 -0500 Subject: [PATCH 15/16] Update .test-env Co-authored-by: Michael Diamant --- .test-env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.test-env b/.test-env index ab9a64c1..3b17bb19 100644 --- a/.test-env +++ b/.test-env @@ -1,6 +1,6 @@ # Configs for testing repo download: SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing" -SDK_TESTING_BRANCH="trim-indexer" +SDK_TESTING_BRANCH="master" SDK_TESTING_HARNESS="test-harness" VERBOSE_HARNESS=0 From 2951489871090ac9b4842b7ae949d25439434b65 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Mon, 22 Aug 2022 11:13:08 -0500 Subject: [PATCH 16/16] remove comment from make display-* command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bd04d357..e3e2c90a 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ integration: cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS_TAGS) --test.v . display-all-go-steps: - find test -name "*.go" | xargs grep "github.com/cucumber/godog" 2>/dev/null | cut -d: -f1 | sort | uniq | xargs grep -Eo "Step[(].[^\`]+" | awk '{sub(/:Step\(./,":")} 1' | sed -E 's/", [a-zA-Z0-9]+\)//g' #| grep "with path" + find test -name "*.go" | xargs grep "github.com/cucumber/godog" 2>/dev/null | cut -d: -f1 | sort | uniq | xargs grep -Eo "Step[(].[^\`]+" | awk '{sub(/:Step\(./,":")} 1' | sed -E 's/", [a-zA-Z0-9]+\)//g' harness: ./test-harness.sh