Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Update index.test.ts #157

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 28 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import { SupplyFetcher, supplyFetchers } from "../src";
import path from 'path';
import fs from 'fs';

const delay = (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));

// Function to get the number of addresses dynamically from the token's .ts file
const getAddressCountForToken = async (token: string): Promise<number> => {
const tokenFilePath = path.join(__dirname, '../src/tokens', `${token.toLowerCase()}.ts`);

if (!fs.existsSync(tokenFilePath)) {
return 1; // Default to 1 if file doesn't exist
}

const tokenModule = await import(tokenFilePath);

if (tokenModule && Array.isArray(tokenModule.default)) {
return tokenModule.default.length;
}

return 1; // Default to 1 if no addresses array is found
};

describe("supply fetchers", () => {
const fetchers: [string, SupplyFetcher][] = [];

Expand All @@ -17,6 +36,9 @@ describe("supply fetchers", () => {

for (const [token, fetcher] of fetchers) {
test(`test fetcher for token ${token}`, async () => {
// Fetch the number of addresses dynamically
const addressCount = await getAddressCountForToken(token);

const resp = await fetcher({ timeout: 20_000 });
if (resp.circulating !== undefined) {
expect(typeof resp.circulating).toBe("string");
Expand All @@ -28,8 +50,12 @@ describe("supply fetchers", () => {
// eslint-disable-next-line no-console
console.debug(resp);
}
// Delay for 110ms to avoid hitting the rate limit of 10 calls/second
await delay(110);

// Calculate custom delay based on the number of addresses
const customDelay = 110 * addressCount;

// Delay for customDelay ms to avoid hitting the rate limit
await delay(customDelay);
});
}
});
Loading