From 811bbea977de8e92f70c659223c0a82cc5314601 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Thu, 1 Aug 2024 11:44:46 +1200 Subject: [PATCH] support chain-spec (#797) --- packages/chopsticks/src/context.ts | 9 +++++---- packages/chopsticks/src/schema/index.ts | 8 +++++++- packages/chopsticks/src/schema/options.test.ts | 8 +++++++- packages/e2e/src/connect-horizontal.test.ts | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/chopsticks/src/context.ts b/packages/chopsticks/src/context.ts index 2cf74ebc..00505531 100644 --- a/packages/chopsticks/src/context.ts +++ b/packages/chopsticks/src/context.ts @@ -27,12 +27,13 @@ export const genesisFromUrl = async (url: string) => { } export const setupContext = async (argv: Config, overrideParent = false) => { + const chainSpec = argv['chain-spec'] ?? argv.genesis let genesis: GenesisProvider | undefined - if (argv.genesis) { - if (typeof argv.genesis === 'string') { - genesis = await genesisFromUrl(argv.genesis) + if (chainSpec) { + if (typeof chainSpec === 'string') { + genesis = await genesisFromUrl(chainSpec) } else { - genesis = new GenesisProvider(argv.genesis) + genesis = new GenesisProvider(chainSpec) } } diff --git a/packages/chopsticks/src/schema/index.ts b/packages/chopsticks/src/schema/index.ts index 6dc2a84b..3f2602c7 100644 --- a/packages/chopsticks/src/schema/index.ts +++ b/packages/chopsticks/src/schema/index.ts @@ -41,7 +41,13 @@ export const configSchema = z.object({ 'wasm-override': z.string({ description: 'Path to wasm override' }).optional(), genesis: z .union([z.string(), genesisSchema], { - description: 'URL to genesis config file. NOTE: Only parachains with AURA consensus are supported!', + description: + 'Alias to `chain-spec`. URL to chain spec file. NOTE: Only parachains with AURA consensus are supported!', + }) + .optional(), + 'chain-spec': z + .union([z.string(), genesisSchema], { + description: 'URL to chain spec file. NOTE: Only parachains with AURA consensus are supported!', }) .optional(), timestamp: z.number().optional(), diff --git a/packages/chopsticks/src/schema/options.test.ts b/packages/chopsticks/src/schema/options.test.ts index a22ecc3b..a62b600b 100644 --- a/packages/chopsticks/src/schema/options.test.ts +++ b/packages/chopsticks/src/schema/options.test.ts @@ -26,6 +26,12 @@ it('get yargs options from zod schema', () => { "description": undefined, "type": undefined, }, + "chain-spec": { + "choices": undefined, + "demandOption": false, + "description": "URL to chain spec file. NOTE: Only parachains with AURA consensus are supported!", + "type": "string", + }, "db": { "choices": undefined, "demandOption": false, @@ -41,7 +47,7 @@ it('get yargs options from zod schema', () => { "genesis": { "choices": undefined, "demandOption": false, - "description": "URL to genesis config file. NOTE: Only parachains with AURA consensus are supported!", + "description": "Alias to \`chain-spec\`. URL to chain spec file. NOTE: Only parachains with AURA consensus are supported!", "type": "string", }, "import-storage": { diff --git a/packages/e2e/src/connect-horizontal.test.ts b/packages/e2e/src/connect-horizontal.test.ts index 0596c2c0..728117d4 100644 --- a/packages/e2e/src/connect-horizontal.test.ts +++ b/packages/e2e/src/connect-horizontal.test.ts @@ -14,7 +14,7 @@ describe('connectHorizontal', () => { }, }) const zeitgeist = await setupContext({ - endpoint: 'wss://zeitgeist-rpc.dwellir.com', + endpoint: 'wss://main.rpc.zeitgeist.pm/ws', blockNumber: 5084336, db: !process.env.RUN_TESTS_WITHOUT_DB ? 'e2e-tests-db.sqlite' : undefined, })