Skip to content
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
5 changes: 5 additions & 0 deletions packages/ponder-sdk/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ export const schemaChainId = schemaPositiveInteger;
* Chain id standards are organized by the Ethereum Community @ https://github.com/ethereum-lists/chains
**/
export type ChainId = z.infer<typeof schemaChainId>;

/**
* String representation of a valid Chain ID.
*/
export type ChainIdString = string;
28 changes: 16 additions & 12 deletions packages/ponder-sdk/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ describe("Ponder Client", () => {
expect(errorMessage).toContain(
"Missing required Prometheus metric: ponder_historical_total_blocks",
);
expect(errorMessage).toContain(
"Missing required Prometheus metric: ponder_sync_is_complete",
);
expect(errorMessage).toContain(
"Missing required Prometheus metric: ponder_sync_is_realtime",
);
}
});

Expand All @@ -151,11 +145,21 @@ describe("Ponder Client", () => {
const errorMessage = error instanceof Error ? error.message : "unknown error";
// Assert
expect(errorMessage).toContain("Invalid serialized Ponder Indexing Metrics");
expect(errorMessage).toContain("'optimism' must be a string representing a chain ID");
expect(errorMessage).toContain("'mainnet' must be a string representing a chain ID");
expect(errorMessage).toContain("'base' must be a string representing a chain ID");
expect(errorMessage).toContain("'scroll' must be a string representing a chain ID");
expect(errorMessage).toContain("'linea' must be a string representing a chain ID");
expect(errorMessage).toContain(
"metric must be a string representing a valid ChainId, but got: 'optimism'",
);
expect(errorMessage).toContain(
"metric must be a string representing a valid ChainId, but got: 'mainnet'",
);
expect(errorMessage).toContain(
"metric must be a string representing a valid ChainId, but got: 'base'",
);
expect(errorMessage).toContain(
"metric must be a string representing a valid ChainId, but got: 'scroll'",
);
expect(errorMessage).toContain(
"metric must be a string representing a valid ChainId, but got: 'linea'",
);
}
});

Expand Down Expand Up @@ -189,7 +193,7 @@ describe("Ponder Client", () => {

// Act & Assert
await expect(ponderClient.metrics()).rejects.toThrowError(
/Invalid serialized Ponder Indexing Metrics.*Chain Indexing Metrics cannot have both `indexingCompleted` and `indexingRealtime` as `true`/,
/Invalid serialized Ponder Indexing Metrics.*'ponder_sync_is_complete' and 'ponder_sync_is_realtime' metrics cannot both be 1 at the same time for chain 10/,
);
});
});
Expand Down
42 changes: 16 additions & 26 deletions packages/ponder-sdk/src/deserialize/indexing-metrics.mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
type ChainIndexingMetricsRealtime,
ChainIndexingStates,
PonderAppCommands,
type PonderIndexingMetrics,
PonderIndexingOrderings,
Expand Down Expand Up @@ -55,56 +57,44 @@ ponder_historical_total_blocks{chain="59144"} 21873991
[
10,
{
backfillSyncBlocksTotal: 36827849,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 147268938, timestamp: 1770136653 },
},
} satisfies ChainIndexingMetricsRealtime,
],
[
1,
{
backfillSyncBlocksTotal: 21042285,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 24377568, timestamp: 1770136655 },
},
} satisfies ChainIndexingMetricsRealtime,
],
[
8453,
{
backfillSyncBlocksTotal: 24103899,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 41673653, timestamp: 1770136653 },
},
} satisfies ChainIndexingMetricsRealtime,
],
[
534352,
{
backfillSyncBlocksTotal: 12693186,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 29373405, timestamp: 1770136654 },
},
} satisfies ChainIndexingMetricsRealtime,
],
[
42161,
{
backfillSyncBlocksTotal: 78607197,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 428248999, timestamp: 1770136654 },
},
} satisfies ChainIndexingMetricsRealtime,
],
[
59144,
{
backfillSyncBlocksTotal: 21873991,
indexingCompleted: false,
indexingRealtime: true,
state: ChainIndexingStates.Realtime,
latestSyncedBlock: { number: 28584906, timestamp: 1770136654 },
},
} satisfies ChainIndexingMetricsRealtime,
],
]),
} satisfies PonderIndexingMetrics,
Expand Down Expand Up @@ -215,15 +205,15 @@ ponder_sync_is_realtime{chain="1"} 1
ponder_sync_is_realtime{chain="59144"} 1
ponder_sync_is_realtime{chain="8453"} 1

# HELP ponder_sync_is_complete Boolean (0 or 1) indicating if the sync has synced all blocks
# TYPE ponder_sync_is_complete gauge
ponder_sync_is_complete{chain="42161"} 1
ponder_sync_is_complete{chain="534352"} 1
ponder_sync_is_complete{chain="10"} 1
ponder_sync_is_complete{chain="1"} 1
ponder_sync_is_complete{chain="59144"} 1
ponder_sync_is_complete{chain="8453"} 1

# HELP ponder_sync_is_complete Boolean (0 or 1) indicating if the sync has synced all blocks
# TYPE ponder_sync_is_complete gauge

# HELP ponder_historical_total_blocks Number of blocks required for the historical sync
# TYPE ponder_historical_total_blocks gauge
Expand Down
Loading
Loading