diff --git a/.github/workflows/js-v2.yml b/.github/workflows/js-v2.yml index f10e2e55d2..bfe91e7aa6 100644 --- a/.github/workflows/js-v2.yml +++ b/.github/workflows/js-v2.yml @@ -64,36 +64,15 @@ jobs: npx nx build @lightprotocol/zk-compression-cli - name: Run stateless.js tests with V2 - run: | - echo "Running stateless.js tests with retry logic (max 2 attempts)..." - attempt=1 - max_attempts=2 - until npx nx test @lightprotocol/stateless.js; do - attempt=$((attempt + 1)) - if [ $attempt -gt $max_attempts ]; then - echo "Tests failed after $max_attempts attempts" - exit 1 - fi - echo "Attempt $attempt/$max_attempts failed, retrying..." - sleep 5 - done - echo "Tests passed on attempt $attempt" + run: npx nx test @lightprotocol/stateless.js + + - name: Run compressed-token legacy tests with V2 + run: npx nx test @lightprotocol/compressed-token - - name: Run compressed-token tests with V2 + - name: Run compressed-token ctoken tests with V2 run: | - echo "Running compressed-token tests with retry logic (max 2 attempts)..." - attempt=1 - max_attempts=2 - until npx nx test @lightprotocol/compressed-token; do - attempt=$((attempt + 1)) - if [ $attempt -gt $max_attempts ]; then - echo "Tests failed after $max_attempts attempts" - exit 1 - fi - echo "Attempt $attempt/$max_attempts failed, retrying..." - sleep 5 - done - echo "Tests passed on attempt $attempt" + cd js/compressed-token + LIGHT_PROTOCOL_VERSION=V2 pnpm test:e2e:ctoken:all - name: Run sdk-anchor-test TypeScript tests with V2 run: | diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index 563d74b669..c3cf4412a1 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -64,33 +64,7 @@ jobs: npx nx build @lightprotocol/zk-compression-cli - name: Run stateless.js tests with V1 - run: | - echo "Running stateless.js tests with retry logic (max 2 attempts)..." - attempt=1 - max_attempts=2 - until npx nx test @lightprotocol/stateless.js; do - attempt=$((attempt + 1)) - if [ $attempt -gt $max_attempts ]; then - echo "Tests failed after $max_attempts attempts" - exit 1 - fi - echo "Attempt $attempt/$max_attempts failed, retrying..." - sleep 5 - done - echo "Tests passed on attempt $attempt" + run: npx nx test @lightprotocol/stateless.js - name: Run compressed-token tests with V1 - run: | - echo "Running compressed-token tests with retry logic (max 2 attempts)..." - attempt=1 - max_attempts=2 - until npx nx test @lightprotocol/compressed-token; do - attempt=$((attempt + 1)) - if [ $attempt -gt $max_attempts ]; then - echo "Tests failed after $max_attempts attempts" - exit 1 - fi - echo "Attempt $attempt/$max_attempts failed, retrying..." - sleep 5 - done - echo "Tests passed on attempt $attempt" + run: npx nx test @lightprotocol/compressed-token diff --git a/cli/src/utils/processPhotonIndexer.ts b/cli/src/utils/processPhotonIndexer.ts index cabbb2032e..f7d38f36b8 100644 --- a/cli/src/utils/processPhotonIndexer.ts +++ b/cli/src/utils/processPhotonIndexer.ts @@ -10,6 +10,7 @@ import { import { exec } from "node:child_process"; import * as util from "node:util"; import { exit } from "node:process"; +import axios from "axios"; const execAsync = util.promisify(exec); @@ -36,6 +37,59 @@ function getPhotonInstallMessage(): string { } } +async function waitForIndexerSync( + rpcUrl: string, + indexerPort: number, + timeoutMs: number = 60000, +): Promise { + const startTime = Date.now(); + const interval = 500; + + while (Date.now() - startTime < timeoutMs) { + try { + const [validatorSlotRes, indexerSlotRes] = await Promise.all([ + axios.post( + rpcUrl, + { jsonrpc: "2.0", id: 1, method: "getSlot", params: [] }, + { timeout: 5000 }, + ), + axios.post( + `http://127.0.0.1:${indexerPort}`, + { jsonrpc: "2.0", id: 1, method: "getIndexerSlot", params: [] }, + { timeout: 5000 }, + ), + ]); + + const validatorSlot = validatorSlotRes.data?.result; + const indexerSlot = indexerSlotRes.data?.result; + + if ( + typeof validatorSlot === "number" && + typeof indexerSlot === "number" + ) { + const slotDiff = validatorSlot - indexerSlot; + if (slotDiff <= 5) { + console.log( + `Indexer synced (validator: ${validatorSlot}, indexer: ${indexerSlot})`, + ); + return; + } + console.log( + `Waiting for indexer sync... (validator: ${validatorSlot}, indexer: ${indexerSlot}, diff: ${slotDiff})`, + ); + } + } catch { + // Ignore errors during sync check, just retry + } + + await new Promise((resolve) => setTimeout(resolve, interval)); + } + + throw new Error( + `Indexer failed to sync with validator within ${timeoutMs / 1000}s`, + ); +} + export async function startIndexer( rpcUrl: string, indexerPort: number, @@ -63,6 +117,7 @@ export async function startIndexer( } spawnBinary(INDEXER_PROCESS_NAME, args); await waitForServers([{ port: indexerPort, path: "/getIndexerHealth" }]); + await waitForIndexerSync(rpcUrl, indexerPort); console.log("Indexer started successfully!"); } }