From dff39b7d83aed2b731771466a263a641b984aea2 Mon Sep 17 00:00:00 2001 From: Gary Malouf <982483+gmalouf@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:25:22 -0500 Subject: [PATCH] Test: Implement block-headers cucumber tests. (#678) * Implement block-headers cucumber tests. --- test/indexer_unit_test.go | 30 ++++++++++++++++++++++++++++++ test/responses_unit_test.go | 2 ++ test/unit.tags | 1 + 3 files changed, 33 insertions(+) diff --git a/test/indexer_unit_test.go b/test/indexer_unit_test.go index 05e412f9..f408a4ca 100644 --- a/test/indexer_unit_test.go +++ b/test/indexer_unit_test.go @@ -28,6 +28,8 @@ func IndexerUnitTestContext(s *godog.ScenarioContext) { s.Step(`^the parsed SearchAccounts response should be valid on round (\d+) and the array should be of len (\d+) and the element at index (\d+) should have address "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make any SearchForTransactions call$`, weMakeAnySearchForTransactionsCall) s.Step(`^the parsed SearchForTransactions response should be valid on round (\d+) and the array should be of len (\d+) and the element at index (\d+) should have sender "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) + s.Step(`^we make any SearchForBlockHeaders call$`, weMakeAnySearchForBlockHeadersCall) + s.Step(`^the parsed SearchForBlockHeaders response should have a block array of len (\d+) and the element at index (\d+) should have round "([^"]*)"$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make any SearchForAssets call$`, weMakeAnySearchForAssetsCall) s.Step(`^the parsed SearchForAssets response should be valid on round (\d+) and the array should be of len (\d+) and the element at index (\d+) should have asset index (\d+)$`, theParsedResponseShouldEqualTheMockResponse) s.Step(`^we make a Lookup Asset Balances call against asset index (\d+) with limit (\d+) afterAddress "([^"]*)" currencyGreaterThan (\d+) currencyLessThan (\d+)$`, weMakeALookupAssetBalancesCallAgainstAssetIndexWithLimitLimitAfterAddressCurrencyGreaterThanCurrencyLessThan) @@ -39,6 +41,7 @@ func IndexerUnitTestContext(s *godog.ScenarioContext) { s.Step(`^we make a Lookup Asset by ID call against asset index (\d+)$`, weMakeALookupAssetByIDCallAgainstAssetIndex) 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 Search For BlockHeaders call with minRound (\d+) maxRound (\d+) limit (\d+) nextToken "([^"]*)" beforeTime "([^"]*)" afterTime "([^"]*)" proposers "([^"]*)" expired "([^"]*)" absent "([^"]*)"$`, weMakeASearchForBlockHeadersCallWithMinRoundMaxRoundLimitNextTokenBeforeTimeAfterTimeProposersExpiredAbsent) s.Step(`^we make a SearchForAssets call with limit (\d+) creator "([^"]*)" name "([^"]*)" unit "([^"]*)" index (\d+)$`, weMakeASearchForAssetsCallWithLimitCreatorNameUnitIndex) s.Step(`^we make a Lookup Account Transactions call against account "([^"]*)" with NotePrefix "([^"]*)" TxType "([^"]*)" SigType "([^"]*)" txid "([^"]*)" round (\d+) minRound (\d+) maxRound (\d+) limit (\d+) beforeTime "([^"]*)" afterTime "([^"]*)" currencyGreaterThan (\d+) currencyLessThan (\d+) assetIndex (\d+) rekeyTo "([^"]*)"$`, weMakeALookupAccountTransactionsCallAgainstAccountWithNotePrefixTxTypeSigTypeTxidRoundMinRoundMaxRoundLimitBeforeTimeAfterTimeCurrencyGreaterThanCurrencyLessThanAssetIndexRekeyTo) s.Step(`^we make a Search Accounts call with assetID (\d+) limit (\d+) currencyGreaterThan (\d+) currencyLessThan (\d+) round (\d+) and authenticating address "([^"]*)"$`, weMakeASearchAccountsCallWithAssetIDLimitCurrencyGreaterThanCurrencyLessThanRoundAndAuthenticatingAddress) @@ -96,6 +99,10 @@ func weMakeAnySearchForTransactionsCall() error { return weMakeAnyCallTo("indexer", "searchForTransactions") } +func weMakeAnySearchForBlockHeadersCall() error { + return weMakeAnyCallTo("indexer", "searchForBlockHeaders") +} + func weMakeAnySearchForAssetsCall() error { return weMakeAnyCallTo("indexer", "searchForAssets") } @@ -229,6 +236,29 @@ func weMakeASearchForTransactionsCallWithAccountNotePrefixTxTypeSigTypeTxidRound return nil } +func weMakeASearchForBlockHeadersCallWithMinRoundMaxRoundLimitNextTokenBeforeTimeAfterTimeProposersExpiredAbsent(minRound, maxRound, limit int, nextToken, beforeTime, afterTime, proposers, expired, absent string) error { + indexerClient, err := indexer.MakeClient(mockServer.URL, "") + if err != nil { + return err + } + + sfbhBuilder := indexerClient.SearchForBlockHeaders().MinRound(uint64(minRound)).MaxRound(uint64(maxRound)).Limit(uint64(limit)).Next(nextToken).BeforeTimeString(beforeTime).AfterTimeString(afterTime) + if len(proposers) > 0 { + proposersArray := strings.Split(proposers, ",") + sfbhBuilder.Proposers(proposersArray) + } + if len(expired) > 0 { + expiredArray := strings.Split(expired, ",") + sfbhBuilder.Expired(expiredArray) + } + if len(absent) > 0 { + absentArray := strings.Split(absent, ",") + sfbhBuilder.Absent(absentArray) + } + _, globalErrForExamination = sfbhBuilder.Do(context.Background()) + return nil +} + func weMakeASearchForTransactionsCallWithAccountNotePrefixTxTypeSigTypeTxidRoundMinRoundMaxRoundLimitBeforeTimeAfterTimeCurrencyGreaterThanCurrencyLessThanAssetIndexAddressRoleExcluseCloseToRekeyTo(account, notePrefix, txType, sigType, txid string, round, minRound, maxRound, limit int, beforeTime, afterTime string, currencyGreater, currencyLesser, assetIndex int, addressRole, excludeCloseTo, rekeyTo string) error { indexerClient, err := indexer.MakeClient(mockServer.URL, "") if err != nil { diff --git a/test/responses_unit_test.go b/test/responses_unit_test.go index bd13b558..ead01785 100644 --- a/test/responses_unit_test.go +++ b/test/responses_unit_test.go @@ -76,6 +76,8 @@ func weMakeAnyCallTo(client /* algod/indexer */, endpoint string) (err error) { response, err = indexerC.LookupAssetTransactions(10).Do(context.Background()) case "searchForTransactions": response, err = indexerC.SearchForTransactions().Do(context.Background()) + case "searchForBlockHeaders": + response, err = indexerC.SearchForBlockHeaders().Do(context.Background()) case "lookupBlock": response, err = indexerC.LookupBlock(10).Do(context.Background()) case "lookupTransaction": diff --git a/test/unit.tags b/test/unit.tags index 89cc0d32..6f8d97c0 100644 --- a/test/unit.tags +++ b/test/unit.tags @@ -13,6 +13,7 @@ @unit.dryrun.trace.application @unit.feetest @unit.indexer +@unit.indexer.blockheaders @unit.indexer.ledger_refactoring @unit.indexer.logs @unit.indexer.rekey