From 20d326b81f790c25fe2c30485b4c5a62ba51d9d4 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:59:45 +0000 Subject: [PATCH] refactor: :recycle: Fix block arg --- packages/cli/src/internal/commandParsers.ts | 4 ++-- packages/types/config_schema.json | 6 +++--- packages/types/src/config.ts | 4 ++-- test/suites/fork_test/test_fork.ts | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/internal/commandParsers.ts b/packages/cli/src/internal/commandParsers.ts index 750171b8..1a6e10b3 100644 --- a/packages/cli/src/internal/commandParsers.ts +++ b/packages/cli/src/internal/commandParsers.ts @@ -127,8 +127,8 @@ export class LaunchCommandParser { invariant(forkOptions.url.startsWith("http"), "Fork URL must start with http:// or https://"); this.overrideArg(`--fork-chain-from-rpc=${forkOptions.url}`); } - if (forkOptions.blockNumber) { - this.overrideArg(`--block=${forkOptions.blockNumber}`); + if (forkOptions.blockHash) { + this.overrideArg(`--block=${forkOptions.blockHash}`); } if (forkOptions.stateOverridePath) { this.overrideArg(`--fork-state-overrides=${forkOptions.stateOverridePath}`); diff --git a/packages/types/config_schema.json b/packages/types/config_schema.json index d0096abc..ac1e4d7c 100644 --- a/packages/types/config_schema.json +++ b/packages/types/config_schema.json @@ -75,9 +75,9 @@ "defaultForkConfig": { "description": "BETA: Default Fork options for the node (overriden by per-test fork options)", "properties": { - "blockNumber": { - "description": "The block number to fork from (optional)", - "type": "number" + "blockHash": { + "description": "The block hash to fork from", + "type": "string" }, "stateOverridePath": { "description": "The state override path (optional)", diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index ced123fc..9266b0af 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -544,9 +544,9 @@ export type ForkConfig = { */ url: string; /** - * The block number to fork from (optional) + * The block hash to fork from */ - blockNumber?: number; + blockHash?: string; /** * The state override path (optional) */ diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts index be7a4b0a..09442d48 100644 --- a/test/suites/fork_test/test_fork.ts +++ b/test/suites/fork_test/test_fork.ts @@ -10,6 +10,7 @@ describeSuite({ forkConfig: { url: "https://moonbeam.unitedbloc.com", verbose: true, + blockHash: "0xffe39256c17cc4523a07c907bcf1aeeef4db217cd57cfcfb95d56088e0bb9f2d" }, }, testCases: ({ it, context, log }) => { @@ -43,5 +44,19 @@ describeSuite({ expect(free.toBigInt(), "Free balance should be 1337000").toBe(1337000000000000000000n); }, }); + + it({ + id: "T03", + title: "Check that forking works at a particular height", + test: async () => { + const testAccount = "0x0f300B667c55B28f4609EecE5628Cc27445A10cC"; + log(`Address: ${testAccount}`); + + const { + data: { free }, + } = await polkadotJs.query.system.account(testAccount); + expect(free.toBigInt(), `Free balance should match what account ${testAccount} has at block #8508372`).toBe(76562560590695097485140n); + }, + }); }, });