Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update chromedriver deps, make install conditional in CI, and fix indexer sync error in cucumber tests #859

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
orbs:
node: circleci/[email protected]
slack: circleci/[email protected]
browser-tools: circleci/[email protected].3
browser-tools: circleci/[email protected].8
gh-pages: sugarshin/[email protected]

parameters:
Expand Down Expand Up @@ -77,6 +77,7 @@ jobs:
- checkout
- install_dependencies:
sudo: 'sudo'
browser: << parameters.browser >>
- run:
name: Install docker
command: |
Expand All @@ -89,7 +90,13 @@ jobs:
$(lsb_release -cs) stable" | $SUDO tee /etc/apt/sources.list.d/docker.list > /dev/null
$SUDO apt update
$SUDO apt -y install docker-ce docker-ce-cli containerd.io
- browser-tools/install-browser-tools
- when:
condition:
not:
equal: ['node', << parameters.browser >>]
steps:
browser-tools/install-browser-tools:
replace-existing-chrome: true
- run:
name: << parameters.browser >> test
command: |
Expand Down Expand Up @@ -120,6 +127,9 @@ commands:
sudo:
type: string
default: ''
browser:
type: string
default: ''
steps:
- run:
name: Install Dependencies
Expand All @@ -133,4 +143,4 @@ commands:
command: |
set -e
npm ci
npm install chromedriver@latest
if [ "<< parameters.browser >>" == "chrome" ]; then npm install chromedriver@latest; fi
8 changes: 5 additions & 3 deletions examples/asa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {
getLocalAlgodClient,
getLocalAccounts,
getLocalIndexerClient,
indexerWaitForRound,
} from './utils';

async function main() {
const algodClient = getLocalAlgodClient();
const indexerClient = getLocalIndexerClient();
const accounts = await getLocalAccounts();
const creator = accounts[0];

Expand Down Expand Up @@ -49,11 +51,11 @@ async function main() {
console.log(`Asset Params: ${assetInfo.params}`);
// example: ASSET_INFO

await new Promise((f) => setTimeout(f, 45000)); // sleep to ensure indexer is caught up
// ensure indexer is caught up
await indexerWaitForRound(indexerClient, result['confirmed-round'], 30);

// example: INDEXER_LOOKUP_ASSET
const indexer = getLocalIndexerClient();
const indexerAssetInfo = await indexer.lookupAssetByID(assetIndex).do();
const indexerAssetInfo = await indexerClient.lookupAssetByID(assetIndex).do();
console.log('Indexer Asset Info:', indexerAssetInfo);
// example: INDEXER_LOOKUP_ASSET

Expand Down
10 changes: 8 additions & 2 deletions examples/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getLocalIndexerClient,
getLocalAccounts,
getLocalAlgodClient,
indexerWaitForRound,
} from './utils';
import algosdk from '../src';

Expand Down Expand Up @@ -73,9 +74,14 @@ async function main() {
});

await client.sendRawTransaction(txn.signTxn(sender.privateKey)).do();
await algosdk.waitForConfirmation(client, txn.txID().toString(), 3);
const result = await algosdk.waitForConfirmation(
client,
txn.txID().toString(),
3
);

await new Promise((f) => setTimeout(f, 1000)); // sleep to ensure indexer is caught up
// ensure indexer is caught up
await indexerWaitForRound(indexerClient, result['confirmed-round'], 30);

// example: INDEXER_PREFIX_SEARCH
const txnsWithNotePrefix = await indexerClient
Expand Down
35 changes: 35 additions & 0 deletions examples/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ export function getLocalAlgodClient() {
return algodClient;
}

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export async function indexerWaitForRound(
client: algosdk.Indexer,
round: number | bigint,
maxAttempts: number
) {
let indexerRound = 0;
let attempts = 0;

for (;;) {
// eslint-disable-next-line no-await-in-loop
const status = await client.makeHealthCheck().do();
indexerRound = status.round;

if (indexerRound >= round) {
// Success
break;
}

// eslint-disable-next-line no-await-in-loop
await sleep(1000); // Sleep 1 second and check again
attempts += 1;

if (attempts > maxAttempts) {
// Failsafe to prevent infinite loop
throw new Error(
`Timeout waiting for indexer to catch up to round ${round}. It is currently on ${indexerRound}`
);
}
}
}

export interface SandboxAccount {
addr: string;
privateKey: Uint8Array;
Expand Down
Loading
Loading