From 5a9e5d7d6dca9937fd75fd14c2d4567b3f2261cc Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 23 Nov 2023 22:30:14 +0100 Subject: [PATCH] support multiple endpoints (#555) --- configs/acala.yml | 4 +++- configs/polkadot.yml | 4 +++- packages/chopsticks/src/schema/index.ts | 2 +- packages/core/src/setup.ts | 4 ++-- packages/e2e/src/helper.ts | 4 ++-- packages/e2e/src/networks.ts | 4 ++-- packages/utils/src/index.ts | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/configs/acala.yml b/configs/acala.yml index 7197150f..62c50e05 100644 --- a/configs/acala.yml +++ b/configs/acala.yml @@ -1,4 +1,6 @@ -endpoint: wss://acala-rpc.dwellir.com +endpoint: + - wss://acala-rpc.aca-api.network + - wss://acala-rpc.dwellir.com mock-signature-host: true block: ${env.ACALA_BLOCK_NUMBER} db: ./db.sqlite diff --git a/configs/polkadot.yml b/configs/polkadot.yml index ffb9392c..a1145a9a 100644 --- a/configs/polkadot.yml +++ b/configs/polkadot.yml @@ -1,4 +1,6 @@ -endpoint: wss://rpc.polkadot.io +endpoint: + - wss://rpc.polkadot.io + - wss://polkadot-rpc.dwellir.com mock-signature-host: true block: ${env.POLKADOT_BLOCK_NUMBER} db: ./db.sqlite diff --git a/packages/chopsticks/src/schema/index.ts b/packages/chopsticks/src/schema/index.ts index 055414ab..a0acedab 100644 --- a/packages/chopsticks/src/schema/index.ts +++ b/packages/chopsticks/src/schema/index.ts @@ -13,7 +13,7 @@ export const zHash = z.string().length(66).and(zHex) export const configSchema = z .object({ port: z.number().optional(), - endpoint: z.string().optional(), + endpoint: z.union([z.string(), z.array(z.string())]).optional(), block: z.union([z.string().length(66).startsWith('0x'), z.number(), z.null()]).optional(), 'build-block-mode': z.nativeEnum(BuildBlockMode).optional(), 'import-storage': z.any().optional(), diff --git a/packages/core/src/setup.ts b/packages/core/src/setup.ts index 0a4353d7..b24ffb45 100644 --- a/packages/core/src/setup.ts +++ b/packages/core/src/setup.ts @@ -20,7 +20,7 @@ import { import { defaultLogger } from './logger.js' export type SetupOptions = { - endpoint?: string + endpoint?: string | string[] block?: string | number | null genesis?: GenesisProvider buildBlockMode?: BuildBlockMode @@ -37,7 +37,7 @@ export const setup = async (options: SetupOptions) => { let provider: ProviderInterface if (options.genesis) { provider = options.genesis - } else if (/^(https|http):\/\//.test(options.endpoint || '')) { + } else if (typeof options.endpoint === 'string' && /^(https|http):\/\//.test(options.endpoint || '')) { provider = new HttpProvider(options.endpoint) } else { provider = new WsProvider(options.endpoint, 3_000) diff --git a/packages/e2e/src/helper.ts b/packages/e2e/src/helper.ts index 968847cd..c9bcadea 100644 --- a/packages/e2e/src/helper.ts +++ b/packages/e2e/src/helper.ts @@ -23,7 +23,7 @@ import { handler } from '@acala-network/chopsticks/rpc/index.js' export { expectJson, expectHex, testingPairs } from '@acala-network/chopsticks-testing' export type SetupOption = { - endpoint?: string + endpoint?: string | string[] blockHash?: HexString mockSignatureHost?: boolean allowUnresolvedImports?: boolean @@ -60,7 +60,7 @@ export const setupAll = async ({ let provider: ProviderInterface if (genesis) { provider = await genesisFromUrl(genesis) - } else if (/^(https|http):\/\//.test(endpoint || '')) { + } else if (typeof endpoint === 'string' && /^(https|http):\/\//.test(endpoint || '')) { provider = new HttpProvider(endpoint) } else { provider = new WsProvider(endpoint, 3_000) diff --git a/packages/e2e/src/networks.ts b/packages/e2e/src/networks.ts index a4237336..236a8c5e 100644 --- a/packages/e2e/src/networks.ts +++ b/packages/e2e/src/networks.ts @@ -5,8 +5,8 @@ import { SetupOption, setupContext } from '@acala-network/chopsticks-testing' dotenvConfig const endpoints = { - polkadot: 'wss://rpc.polkadot.io', - acala: 'wss://acala-rpc-1.aca-api.network', + polkadot: ['wss://rpc.polkadot.io', 'wss://polkadot-rpc.dwellir.com'], + acala: ['wss://acala-rpc.aca-api.network', 'wss://acala-rpc.dwellir.com'], } const toNumber = (value: string | undefined): number | undefined => { diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 940b5650..4ae1b89b 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -16,7 +16,7 @@ import { SubmittableExtrinsic } from '@polkadot/api-base/types' export * from './signFake.js' export type SetupOption = { - endpoint: string + endpoint: string | string[] blockNumber?: number blockHash?: HexString wasmOverride?: string