Skip to content

Commit

Permalink
Test: Implement block-headers cucumber tests. (#678)
Browse files Browse the repository at this point in the history
* Implement block-headers cucumber tests.
  • Loading branch information
gmalouf authored Feb 2, 2025
1 parent f61d25c commit dff39b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/indexer_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions test/responses_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
1 change: 1 addition & 0 deletions test/unit.tags
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dff39b7

Please sign in to comment.