From a580ae4acda0385c0cd47f9a82986e0a656b6616 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:26:13 +0000 Subject: [PATCH 01/16] feat: :sparkles: Added default fork config --- packages/cli/src/cmds/runTests.ts | 3 +- .../internal/cmdFunctions/initialisation.ts | 2 +- packages/cli/src/internal/commandParsers.ts | 45 ++++++++++++-- packages/cli/src/internal/localNode.ts | 4 ++ packages/cli/src/lib/globalContext.ts | 61 ++++++++----------- packages/cli/src/lib/runnerContext.ts | 8 ++- packages/types/config_schema.json | 35 +++++++---- packages/types/src/config.ts | 36 +++++++---- packages/types/src/runner.ts | 38 +++++++++++- test/configs/mbStateOverride.json | 1 + test/moonwall.config.json | 35 +++++++++++ .../chopsticks/test-chopsticks-state.ts | 2 +- .../chopsticks/test-chopsticks-state2.ts | 2 +- test/suites/dev_tests/test1/test_dev.ts | 4 +- test/suites/dev_tests/test2/test_dev2.ts | 6 +- .../dummy-smoke/test_block_finalized.ts | 2 +- test/suites/dummy-smoke/test_conditional.ts | 2 +- test/suites/dummy-smoke/test_conditional2.ts | 2 +- .../eth_test/test-ethers_test.spec copy 2.ts | 2 +- .../eth_test/test-ethers_test.spec copy.ts | 2 +- test/suites/eth_test/test-ethers_test.spec.ts | 2 +- .../suites/eth_test2/test-ethers_test.spec.ts | 2 +- test/suites/fork_test/test_fork.ts | 33 ++++++++++ test/suites/multizombie/test_basic.ts | 2 +- test/suites/read_only/test-readonly.spec.ts | 2 +- test/suites/run_error/test-run_errors.ts | 2 +- .../test_separation2 copy 2.ts | 2 +- .../test_separation/test_separation2 copy.ts | 2 +- .../test_separation/test_separation2.ts | 2 +- .../test_separation3 copy 2.ts | 2 +- .../test_separation/test_separation3 copy.ts | 2 +- .../test_separation/test_separation3.ts | 2 +- .../test_separation4 copy 2.ts | 2 +- .../test_separation/test_separation4 copy.ts | 2 +- .../test_separation/test_separation4.ts | 2 +- .../test_separation5 copy 2.ts | 2 +- .../test_separation/test_separation5 copy.ts | 2 +- .../test_separation/test_separation5.ts | 2 +- test/suites/viem/test_viem_test.ts | 2 +- test/suites/web3_test/test_web3.ts | 2 +- 40 files changed, 265 insertions(+), 98 deletions(-) create mode 100644 test/configs/mbStateOverride.json create mode 100644 test/suites/fork_test/test_fork.ts diff --git a/packages/cli/src/cmds/runTests.ts b/packages/cli/src/cmds/runTests.ts index 36f21044..c5e9023c 100644 --- a/packages/cli/src/cmds/runTests.ts +++ b/packages/cli/src/cmds/runTests.ts @@ -120,8 +120,7 @@ export async function executeTests(env: Environment, testRunArgs?: testRunArgs) const testFileDir = additionalArgs?.subDirectory !== undefined ? env.testFileDir.map((folder) => - // @ts-expect-error - bug in tsc - path.join(folder, additionalArgs.subDirectory) + path.join(folder, additionalArgs.subDirectory || "error") ) : env.testFileDir; diff --git a/packages/cli/src/internal/cmdFunctions/initialisation.ts b/packages/cli/src/internal/cmdFunctions/initialisation.ts index e4f6fbd7..e565a891 100644 --- a/packages/cli/src/internal/cmdFunctions/initialisation.ts +++ b/packages/cli/src/internal/cmdFunctions/initialisation.ts @@ -123,7 +123,7 @@ export function createConfig(options: { testFileDir: [options.testDir], foundation: { type: options.foundation as any, - }, + } as any, }, ], }; diff --git a/packages/cli/src/internal/commandParsers.ts b/packages/cli/src/internal/commandParsers.ts index e4c87359..82b1287d 100644 --- a/packages/cli/src/internal/commandParsers.ts +++ b/packages/cli/src/internal/commandParsers.ts @@ -7,6 +7,7 @@ import type { import chalk from "chalk"; import path from "node:path"; import { standardRepos } from "../lib/repoDefinitions"; +import invariant from "tiny-invariant"; export function parseZombieCmd(launchSpec: ZombieLaunchSpec) { if (launchSpec) { @@ -45,27 +46,61 @@ export async function parseRunCmd(launchSpec: DevLaunchSpec, additionalRepos?: R ? [...launchSpec.options] : fetchDefaultArgs(path.basename(launchSpec.binPath), additionalRepos); + const overrideArg = (newArg: string) => { + const newArgKey = newArg.split("=")[0]; + const existingIndex = args.findIndex((arg) => arg.startsWith(`${newArgKey}=`)); + + if (existingIndex !== -1) { + args[existingIndex] = newArg; + } else { + args.push(newArg); + } + }; + if (launchSpec.ports) { const ports = launchSpec.ports; if (ports.p2pPort) { - args.push(`--port=${ports.p2pPort}`); + overrideArg(`--port=${ports.p2pPort}`); } if (ports.wsPort) { - args.push(`--ws-port=${ports.wsPort}`); + overrideArg(`--ws-port=${ports.wsPort}`); } if (ports.rpcPort) { - args.push(`--rpc-port=${ports.rpcPort}`); + overrideArg(`--rpc-port=${ports.rpcPort}`); } } else { const freePort = (await getFreePort()).toString(); process.env.MOONWALL_RPC_PORT = freePort; if (launchSpec.newRpcBehaviour) { - args.push(`--rpc-port=${freePort}`); + overrideArg(`--rpc-port=${freePort}`); } else { - args.push(`--ws-port=${freePort}`); + overrideArg(`--ws-port=${freePort}`); } } + + const forkOptions = launchSpec.defaultForkConfig; + + console.log("forkOptions"); + console.dir(forkOptions, { depth: null }); + if (forkOptions) { + if (forkOptions.url) { + invariant(forkOptions.url.startsWith("http"), "Fork URL must start with http:// or https://"); + overrideArg(`--fork-chain-from-rpc=${forkOptions.url}`); + } + if (forkOptions.blockNumber) { + overrideArg(`--block=${forkOptions.blockNumber}`); + } + if (forkOptions.stateOverridePath) { + overrideArg(`--fork-state-overrides=${forkOptions.stateOverridePath}`); + } + if (forkOptions.verbose) { + overrideArg("-llazy-loading=trace"); + } + } + + console.log("post args"); + console.log(args); return { cmd, args, launch }; } diff --git a/packages/cli/src/internal/localNode.ts b/packages/cli/src/internal/localNode.ts index b3e7c974..cb579a30 100644 --- a/packages/cli/src/internal/localNode.ts +++ b/packages/cli/src/internal/localNode.ts @@ -16,6 +16,10 @@ export async function launchNode(cmd: string, args: string[], name: string) { checkAccess(cmd); } + console.log("REMOVE ME") + console.log(cmd) + console.log(args) + const port = args.find((a) => a.includes("port"))?.split("=")[1]; debug(`\x1b[36mStarting ${name} node on port ${port}...\x1b[0m`); diff --git a/packages/cli/src/lib/globalContext.ts b/packages/cli/src/lib/globalContext.ts index aeb3111b..f65a49d2 100644 --- a/packages/cli/src/lib/globalContext.ts +++ b/packages/cli/src/lib/globalContext.ts @@ -39,6 +39,7 @@ import { import { type ChildProcess, exec, execSync } from "node:child_process"; import { promisify } from "node:util"; import { withTimeout } from "../internal"; +import invariant from "tiny-invariant"; const debugSetup = Debug("global:context"); export class MoonwallContext { @@ -51,26 +52,23 @@ export class MoonwallContext { zombieNetwork?: Network; rtUpgradePath?: string; ipcServer?: net.Server; + injectedOptions?: object - constructor(config: MoonwallConfig) { + constructor(config: MoonwallConfig, options?: object) { const env = config.environments.find(({ name }) => name === process.env.MOON_TEST_ENV); - - if (!env) { - throw new Error(`Environment ${process.env.MOON_TEST_ENV} not found in config`); - } + invariant(env, `Environment ${process.env.MOON_TEST_ENV} not found in config`); this.providers = []; this.nodes = []; this.foundation = env.foundation.type; + this.injectedOptions = options } public async setupFoundation() { const config = await importAsyncConfig(); const env = config.environments.find(({ name }) => name === process.env.MOON_TEST_ENV); - if (!env) { - throw new Error(`Environment ${process.env.MOON_TEST_ENV} not found in config`); - } + invariant(env, `Environment ${process.env.MOON_TEST_ENV} not found in config`); const foundationHandlers: Record< FoundationType, @@ -79,9 +77,10 @@ export class MoonwallContext { read_only: this.handleReadOnly, chopsticks: this.handleChopsticks, dev: this.handleDev, - zombie: this.handleZombie, - fork: this.handleReadOnly, // TODO: Implement fork + zombie: this.handleZombie }; + console.log("RUNNING FOUNDATION HANDLER") + console.dir(env.foundation,{depth: null}) const foundationHandler = foundationHandlers[env.foundation.type]; this.environment = { @@ -93,9 +92,7 @@ export class MoonwallContext { } private async handleZombie(env: Environment) { - if (env.foundation.type !== "zombie") { - throw new Error(`Foundation type must be 'zombie'`); - } + invariant(env.foundation.type === "zombie", "Foundation type must be 'zombie'"); const { cmd: zombieConfig } = await parseZombieCmd(env.foundation.zombieSpec); this.rtUpgradePath = env.foundation.rtUpgradePath; @@ -114,9 +111,7 @@ export class MoonwallContext { } private async handleDev(env: Environment, config: MoonwallConfig) { - if (env.foundation.type !== "dev") { - throw new Error(`Foundation type must be 'dev'`); - } + invariant(env.foundation.type === "dev", "Foundation type must be 'dev'"); const { cmd, args, launch } = await parseRunCmd( env.foundation.launchSpec[0], @@ -434,6 +429,9 @@ export class MoonwallContext { const nodes = ctx.environment.nodes; + console.log("remove me") + console.dir(nodes, {depth:null}) + if (this.environment.foundationType === "zombie") { return await this.startZombieNetwork(); } @@ -625,12 +623,14 @@ export class MoonwallContext { } } - public static async getContext(config?: MoonwallConfig, force = false): Promise { + //TODO: Type options + public static async getContext(config?: MoonwallConfig, options?: object, force = false): Promise { + invariant(!(options && MoonwallContext.instance), "Attempting to open a new context with overrides when context already exists"); + if (!MoonwallContext.instance?.configured || force) { - if (!config) { - throw new Error("❌ Config must be provided on Global Context instantiation"); - } - MoonwallContext.instance = new MoonwallContext(config); + invariant(config, "Config must be provided on Global Context instantiation"); + + MoonwallContext.instance = new MoonwallContext(config, options); await MoonwallContext.instance.setupFoundation(); debugSetup(`🟢 Moonwall context "${config.label}" created`); } @@ -640,9 +640,7 @@ export class MoonwallContext { public static async destroy() { const ctx = MoonwallContext.instance; - if (!ctx) { - throw new Error("❌ No context to destroy"); - } + invariant(ctx, "No context to destroy"); try { await ctx.disconnect(); @@ -652,16 +650,10 @@ export class MoonwallContext { while (ctx.nodes.length > 0) { const node = ctx.nodes.pop(); - - if (!node) { - throw new Error("❌ No nodes to destroy"); - } + invariant(node, "No node to destroy"); const pid = node.pid; - - if (!pid) { - throw new Error("❌ No pid to destroy"); - } + invariant(pid, "No pid to destroy"); node.kill("SIGINT"); for (;;) { @@ -698,9 +690,10 @@ export class MoonwallContext { } } -export const contextCreator = async () => { +// TODO: Type this properly! +export const contextCreator = async (options?: object) => { const config = await importAsyncConfig(); - const ctx = await MoonwallContext.getContext(config); + const ctx = await MoonwallContext.getContext(config, options); await runNetworkOnly(); await ctx.connectEnvironment(); return ctx; diff --git a/packages/cli/src/lib/runnerContext.ts b/packages/cli/src/lib/runnerContext.ts index b660bfed..e0ef7d4f 100644 --- a/packages/cli/src/lib/runnerContext.ts +++ b/packages/cli/src/lib/runnerContext.ts @@ -70,6 +70,7 @@ export function describeSuite({ minRtVersion, chainType, notChainType, + options, }: ITestSuiteType): void { if ( (minRtVersion && minRtVersion > RT_VERSION) || @@ -82,7 +83,13 @@ export function describeSuite({ let ctx: MoonwallContext | null = null; beforeAll(async () => { + const env = getEnvironmentFromConfig(); + if (env.foundation.type === "dev") { + // Pass options to contextCreator if they exist + ctx = await contextCreator(options); + } + ctx = await contextCreator(); if (env.foundation.type === "read_only") { const settings = loadParams(env.foundation.launchSpec); @@ -159,7 +166,6 @@ export function describeSuite({ chopsticks: chopsticksHandler, zombie: zombieHandler, read_only: readOnlyHandler, - fork: readOnlyHandler, }; const handler = foundationHandlers[foundationMethods]; diff --git a/packages/types/config_schema.json b/packages/types/config_schema.json index 80a10fde..0648f2fc 100644 --- a/packages/types/config_schema.json +++ b/packages/types/config_schema.json @@ -69,9 +69,31 @@ "description": "A launch specification object for the \"dev\" foundation type.", "properties": { "binPath": { - "description": "The path to the binary file.", + "description": "The path to the binary to execute", "type": "string" }, + "defaultForkConfig": { + "description": "Default Fork options for the node (overriden by per-test fork options)", + "properties": { + "blockNumber": { + "description": "The block number to fork from (optional)", + "type": "number" + }, + "stateOverridePath": { + "description": "The state override path (optional)", + "type": "string" + }, + "url": { + "description": "The URL to fork from", + "type": "string" + }, + "verbose": { + "description": "Turns on trace logging for LazyLoading service (optional)", + "type": "boolean" + } + }, + "type": "object" + }, "disableDefaultEthProviders": { "description": "Determines if the default Ethereum provider connections should be disabled.\nWhen set to true, the framework will not automatically connect the Ethereum providers.\nDefault behavior (when unset or set to false) is to connect with Ethers, Viem & Web3 frameworks.\n\nNote: This also acts as a feature gate for context methods like createTxn and readPrecompile.", "type": "boolean" @@ -92,7 +114,7 @@ "type": "array" }, "ports": { - "description": "An optional object with p2pPort, wsPort, and rpcPort.", + "description": "Port configuration", "properties": { "p2pPort": { "description": "The port for peer-to-peer (P2P) communication.", @@ -181,15 +203,6 @@ } }, "type": "object" - }, - { - "properties": { - "type": { - "const": "fork", - "type": "string" - } - }, - "type": "object" } ], "description": "The foundation configuration for the environment. It can be of several types including \"dev\", \"chopsticks\", \"zombie\", \"read_only\", or \"fork\"." diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index 28dc78df..a60d37ea 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -174,10 +174,7 @@ export type IFoundation = type: "read_only"; launchSpec: ReadOnlyLaunchSpec; } - | { - type: "fork"; - // launchSpec: ForkLaunchSpec; - }; + /** * @name EthTransactionType @@ -231,11 +228,6 @@ export interface ReadOnlyLaunchSpec extends GenericLaunchSpec { disableRuntimeVersionCheck?: boolean; } -/** - * A launch specification object for the "fork" foundation type. - * @extends GenericLaunchSpec - */ -export interface ForkLaunchSpec extends GenericLaunchSpec {} /** * A launch specification object for the "zombie" foundation type. @@ -328,7 +320,7 @@ export interface ChopsticksLaunchSpec extends GenericLaunchSpec { */ export interface DevLaunchSpec extends GenericLaunchSpec { /** - * The path to the binary file. + * The path to the binary to execute */ binPath: string; @@ -347,7 +339,29 @@ export interface DevLaunchSpec extends GenericLaunchSpec { newRpcBehaviour?: boolean; /** - * An optional object with p2pPort, wsPort, and rpcPort. + * Default Fork options for the node (overriden by per-test fork options) + */ + defaultForkConfig?: { + /** + * The URL to fork from + */ + url: string; + /** + * The block number to fork from (optional) + */ + blockNumber?: number; + /** + * The state override path (optional) + */ + stateOverridePath?: string; + /** + * Turns on trace logging for LazyLoading service (optional) + */ + verbose?: boolean; + }; + + /** + * Port configuration */ ports?: { /** diff --git a/packages/types/src/runner.ts b/packages/types/src/runner.ts index 8cb93761..b6119118 100644 --- a/packages/types/src/runner.ts +++ b/packages/types/src/runner.ts @@ -58,7 +58,7 @@ export type FoundationContextMap = { ? ZombieContext : K extends "read_only" ? ReadOnlyContext - : /* default: */ GenericContext; + : /* default: */ GenericContext; }; export type TestContextMap = { @@ -74,6 +74,24 @@ export type TestCasesFn = (params: { // TODO: Extend to include skipIf() and runIf() export type TestCaseModifier = "only" | "skip"; +/** + * Fork configuration options for test cases + */ +export interface ForkConfig { + /** + * RPC endpoint to fork from + */ + endpoint: string; + /** + * Block number to fork from + */ + block?: number; + /** + * Path to state override file + */ + stateOverridePath?: string; +} + export interface ITestCase { id: string; title: string; @@ -86,6 +104,19 @@ export interface ITestCase { timeout?: number; } +export type TestSuiteConfig = { + id: string; + title: string; + foundationMethods: T; + description?: string; + testCases: TestCasesFn; +} & (T extends "dev" + ? { + forkConfig: ForkConfig; + } + : // biome-ignore lint/complexity/noBannedTypes: good enough for now + {}); + export type FoundationHandler = (params: { testCases: TestCasesFn; context: GenericContext; @@ -99,7 +130,10 @@ export type ITestSuiteType = { title: string; testCases: (TestContext: TestContextMap[T]) => void; foundationMethods: T; - options?: object; + // TODO: Make this foundation dependent + options?: { + forkConfig: ForkConfig; + }; minRtVersion?: number; chainType?: ChainType; notChainType?: ChainType; diff --git a/test/configs/mbStateOverride.json b/test/configs/mbStateOverride.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/test/configs/mbStateOverride.json @@ -0,0 +1 @@ +[] diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 1f461c3e..1717a13b 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -949,6 +949,41 @@ "endpoints": ["ws://127.0.0.1:9955"] } ] + }, + { + "name": "fork_test", + "testFileDir": ["suites/fork_test"], + "foundation": { + "type": "dev", + "launchSpec": [ + { + "name": "moonbeam", + "running": true, + "binPath": "./tmp/moonbeam", + "disableDefaultEthProviders": true, + "newRpcBehaviour": true, + "options": [ + "-llazy-loading=trace", + "--ethapi=txpool", + "--no-hardware-benchmarks", + "--no-telemetry", + "--unsafe-force-node-key-generation", + "--reserved-only", + "--no-grandpa", + "--no-prometheus", + "--force-authoring", + "--rpc-cors=all", + "--alice", + "--sealing=manual", + "--tmp" + ], + "defaultForkConfig": { + "url": "https://moonbeam.kaki.dev", + "stateOverridePath": "./configs/mbStateOverride.json" + } + } + ] + } } ] } diff --git a/test/suites/chopsticks/test-chopsticks-state.ts b/test/suites/chopsticks/test-chopsticks-state.ts index 55467f8c..4345b204 100644 --- a/test/suites/chopsticks/test-chopsticks-state.ts +++ b/test/suites/chopsticks/test-chopsticks-state.ts @@ -2,7 +2,7 @@ import "@moonbeam-network/api-augment"; import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "S1", diff --git a/test/suites/chopsticks/test-chopsticks-state2.ts b/test/suites/chopsticks/test-chopsticks-state2.ts index 929fc7ae..31984d0a 100644 --- a/test/suites/chopsticks/test-chopsticks-state2.ts +++ b/test/suites/chopsticks/test-chopsticks-state2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "S1", diff --git a/test/suites/dev_tests/test1/test_dev.ts b/test/suites/dev_tests/test1/test_dev.ts index 5c90ff99..71a0110d 100644 --- a/test/suites/dev_tests/test1/test_dev.ts +++ b/test/suites/dev_tests/test1/test_dev.ts @@ -21,9 +21,9 @@ import { deployViemContract, } from "@moonwall/util"; import { BN } from "@polkadot/util"; -import { Wallet, parseEther } from "ethers"; +import { type Wallet, parseEther } from "ethers"; import { - Abi, + type Abi, createWalletClient, decodeErrorResult, decodeEventLog, diff --git a/test/suites/dev_tests/test2/test_dev2.ts b/test/suites/dev_tests/test2/test_dev2.ts index 522d67ad..a78871e8 100644 --- a/test/suites/dev_tests/test2/test_dev2.ts +++ b/test/suites/dev_tests/test2/test_dev2.ts @@ -1,10 +1,10 @@ import "@moonbeam-network/api-augment"; import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { CHARLETH_ADDRESS, BALTATHAR_ADDRESS, alith } from "@moonwall/util"; -import { parseEther, Wallet } from "ethers"; +import { parseEther, type Wallet } from "ethers"; import { BN } from "@polkadot/util"; -import { ApiPromise } from "@polkadot/api"; -import Web3 from "web3"; +import type { ApiPromise } from "@polkadot/api"; +import type Web3 from "web3"; describeSuite({ id: "D02", title: "Dev test suite2", diff --git a/test/suites/dummy-smoke/test_block_finalized.ts b/test/suites/dummy-smoke/test_block_finalized.ts index 6649e416..5d813c0f 100644 --- a/test/suites/dummy-smoke/test_block_finalized.ts +++ b/test/suites/dummy-smoke/test_block_finalized.ts @@ -1,6 +1,6 @@ import Bottleneck from "bottleneck"; import semverLt from "semver/functions/lt"; -import { expect, describeSuite, ApiPromise, beforeAll, Web3 } from "@moonwall/cli"; +import { expect, describeSuite, type ApiPromise, beforeAll, type Web3 } from "@moonwall/cli"; import { checkBlockFinalized, fetchHistoricBlockNum, getBlockTime } from "@moonwall/util"; import Debug from "debug"; const debug = Debug("smoke:block-finalized"); diff --git a/test/suites/dummy-smoke/test_conditional.ts b/test/suites/dummy-smoke/test_conditional.ts index b85e2222..bfa3e963 100644 --- a/test/suites/dummy-smoke/test_conditional.ts +++ b/test/suites/dummy-smoke/test_conditional.ts @@ -1,5 +1,5 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "R01", diff --git a/test/suites/dummy-smoke/test_conditional2.ts b/test/suites/dummy-smoke/test_conditional2.ts index 187b1efc..f64f6270 100644 --- a/test/suites/dummy-smoke/test_conditional2.ts +++ b/test/suites/dummy-smoke/test_conditional2.ts @@ -1,5 +1,5 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "R01", diff --git a/test/suites/eth_test/test-ethers_test.spec copy 2.ts b/test/suites/eth_test/test-ethers_test.spec copy 2.ts index 3e6e6959..c4c0c6da 100644 --- a/test/suites/eth_test/test-ethers_test.spec copy 2.ts +++ b/test/suites/eth_test/test-ethers_test.spec copy 2.ts @@ -1,6 +1,6 @@ import { describeSuite, expect, beforeAll, MoonwallContext } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; -import { Wallet, ethers } from "ethers"; +import { type Wallet, ethers } from "ethers"; describeSuite({ id: "S01", diff --git a/test/suites/eth_test/test-ethers_test.spec copy.ts b/test/suites/eth_test/test-ethers_test.spec copy.ts index e1660e71..90b5e3c0 100644 --- a/test/suites/eth_test/test-ethers_test.spec copy.ts +++ b/test/suites/eth_test/test-ethers_test.spec copy.ts @@ -1,6 +1,6 @@ import { describeSuite, expect, beforeAll, MoonwallContext } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; -import { Wallet, ethers } from "ethers"; +import { type Wallet, ethers } from "ethers"; describeSuite({ id: "S01", diff --git a/test/suites/eth_test/test-ethers_test.spec.ts b/test/suites/eth_test/test-ethers_test.spec.ts index bf339465..c007f148 100644 --- a/test/suites/eth_test/test-ethers_test.spec.ts +++ b/test/suites/eth_test/test-ethers_test.spec.ts @@ -1,6 +1,6 @@ import { describeSuite, expect, beforeAll, MoonwallContext } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; -import { Wallet, ethers } from "ethers"; +import { type Wallet, ethers } from "ethers"; describeSuite({ id: "S01", diff --git a/test/suites/eth_test2/test-ethers_test.spec.ts b/test/suites/eth_test2/test-ethers_test.spec.ts index bf339465..c007f148 100644 --- a/test/suites/eth_test2/test-ethers_test.spec.ts +++ b/test/suites/eth_test2/test-ethers_test.spec.ts @@ -1,6 +1,6 @@ import { describeSuite, expect, beforeAll, MoonwallContext } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; -import { Wallet, ethers } from "ethers"; +import { type Wallet, ethers } from "ethers"; describeSuite({ id: "S01", diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts new file mode 100644 index 00000000..59416b20 --- /dev/null +++ b/test/suites/fork_test/test_fork.ts @@ -0,0 +1,33 @@ +import "@moonbeam-network/api-augment"; +import { describeSuite, expect, beforeAll } from "@moonwall/cli"; +import type { ApiPromise } from "@polkadot/api"; + +describeSuite({ + id: "F01", + title: "Fork test", + foundationMethods: "dev", + options: { + forkConfig: { + endpoint: "https://moonbeam.public.blastapi.io", + block: 100, + }, + }, + testCases: ({ it, context }) => { + let polkadotJs: ApiPromise; + + beforeAll(() => { + polkadotJs = context.polkadotJs(); + }); + + it({ + id: "T01", + title: "Checking that launched node can create blocks", + test: async () => { + const block = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); + await context.createBlock(); + const block2 = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); + expect(block2).to.be.greaterThan(block); + }, + }); + }, +}); diff --git a/test/suites/multizombie/test_basic.ts b/test/suites/multizombie/test_basic.ts index 7eeb3e57..a3edfc40 100644 --- a/test/suites/multizombie/test_basic.ts +++ b/test/suites/multizombie/test_basic.ts @@ -1,6 +1,6 @@ import "@moonbeam-network/api-augment"; import { expect, describeSuite, beforeAll } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "Z1", diff --git a/test/suites/read_only/test-readonly.spec.ts b/test/suites/read_only/test-readonly.spec.ts index d9b6f75e..8a619041 100644 --- a/test/suites/read_only/test-readonly.spec.ts +++ b/test/suites/read_only/test-readonly.spec.ts @@ -1,7 +1,7 @@ import "@moonbeam-network/api-augment"; import { describeSuite } from "@moonwall/cli"; import { checkBlockFinalized } from "@moonwall/util"; -import { Wallet } from "ethers"; +import type { Wallet } from "ethers"; describeSuite({ id: "S01", diff --git a/test/suites/run_error/test-run_errors.ts b/test/suites/run_error/test-run_errors.ts index c0a464b1..a54b98aa 100644 --- a/test/suites/run_error/test-run_errors.ts +++ b/test/suites/run_error/test-run_errors.ts @@ -1,4 +1,4 @@ -import { describeSuite, expect, beforeAll, ApiPromise, Web3 } from "@moonwall/cli"; +import { describeSuite, expect, beforeAll, type ApiPromise, type Web3 } from "@moonwall/cli"; import { ALITH_ADDRESS } from "@moonwall/util"; describeSuite({ diff --git a/test/suites/test_separation/test_separation2 copy 2.ts b/test/suites/test_separation/test_separation2 copy 2.ts index 597a50ac..e92b320c 100644 --- a/test/suites/test_separation/test_separation2 copy 2.ts +++ b/test/suites/test_separation/test_separation2 copy 2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll, beforeEach } from "@moonwall/cli"; import { CHARLETH_ADDRESS, ETHAN_ADDRESS, alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D21", diff --git a/test/suites/test_separation/test_separation2 copy.ts b/test/suites/test_separation/test_separation2 copy.ts index 597a50ac..e92b320c 100644 --- a/test/suites/test_separation/test_separation2 copy.ts +++ b/test/suites/test_separation/test_separation2 copy.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll, beforeEach } from "@moonwall/cli"; import { CHARLETH_ADDRESS, ETHAN_ADDRESS, alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D21", diff --git a/test/suites/test_separation/test_separation2.ts b/test/suites/test_separation/test_separation2.ts index 597a50ac..e92b320c 100644 --- a/test/suites/test_separation/test_separation2.ts +++ b/test/suites/test_separation/test_separation2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll, beforeEach } from "@moonwall/cli"; import { CHARLETH_ADDRESS, ETHAN_ADDRESS, alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D21", diff --git a/test/suites/test_separation/test_separation3 copy 2.ts b/test/suites/test_separation/test_separation3 copy 2.ts index 22ff2c93..d3a5c39f 100644 --- a/test/suites/test_separation/test_separation3 copy 2.ts +++ b/test/suites/test_separation/test_separation3 copy 2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D31", diff --git a/test/suites/test_separation/test_separation3 copy.ts b/test/suites/test_separation/test_separation3 copy.ts index 22ff2c93..d3a5c39f 100644 --- a/test/suites/test_separation/test_separation3 copy.ts +++ b/test/suites/test_separation/test_separation3 copy.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D31", diff --git a/test/suites/test_separation/test_separation3.ts b/test/suites/test_separation/test_separation3.ts index 22ff2c93..d3a5c39f 100644 --- a/test/suites/test_separation/test_separation3.ts +++ b/test/suites/test_separation/test_separation3.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D31", diff --git a/test/suites/test_separation/test_separation4 copy 2.ts b/test/suites/test_separation/test_separation4 copy 2.ts index 77b159a7..baee6f91 100644 --- a/test/suites/test_separation/test_separation4 copy 2.ts +++ b/test/suites/test_separation/test_separation4 copy 2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D41", diff --git a/test/suites/test_separation/test_separation4 copy.ts b/test/suites/test_separation/test_separation4 copy.ts index 77b159a7..baee6f91 100644 --- a/test/suites/test_separation/test_separation4 copy.ts +++ b/test/suites/test_separation/test_separation4 copy.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D41", diff --git a/test/suites/test_separation/test_separation4.ts b/test/suites/test_separation/test_separation4.ts index 77b159a7..baee6f91 100644 --- a/test/suites/test_separation/test_separation4.ts +++ b/test/suites/test_separation/test_separation4.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D41", diff --git a/test/suites/test_separation/test_separation5 copy 2.ts b/test/suites/test_separation/test_separation5 copy 2.ts index 904381cd..c9ecae01 100644 --- a/test/suites/test_separation/test_separation5 copy 2.ts +++ b/test/suites/test_separation/test_separation5 copy 2.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D51", diff --git a/test/suites/test_separation/test_separation5 copy.ts b/test/suites/test_separation/test_separation5 copy.ts index 904381cd..c9ecae01 100644 --- a/test/suites/test_separation/test_separation5 copy.ts +++ b/test/suites/test_separation/test_separation5 copy.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D51", diff --git a/test/suites/test_separation/test_separation5.ts b/test/suites/test_separation/test_separation5.ts index 904381cd..c9ecae01 100644 --- a/test/suites/test_separation/test_separation5.ts +++ b/test/suites/test_separation/test_separation5.ts @@ -1,7 +1,7 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { parseEther } from "ethers"; -import { ApiPromise } from "@polkadot/api"; +import type { ApiPromise } from "@polkadot/api"; describeSuite({ id: "D51", diff --git a/test/suites/viem/test_viem_test.ts b/test/suites/viem/test_viem_test.ts index a6fb2f3e..31eda0b2 100644 --- a/test/suites/viem/test_viem_test.ts +++ b/test/suites/viem/test_viem_test.ts @@ -1,4 +1,4 @@ -import { ViemClient, beforeAll, describeSuite, expect } from "@moonwall/cli"; +import { type ViemClient, beforeAll, describeSuite, expect } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; import { formatEther, formatUnits, getContract } from "viem"; diff --git a/test/suites/web3_test/test_web3.ts b/test/suites/web3_test/test_web3.ts index ccefd05e..03fef3d3 100644 --- a/test/suites/web3_test/test_web3.ts +++ b/test/suites/web3_test/test_web3.ts @@ -1,6 +1,6 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { xcAssetAbi } from "@moonwall/util"; -import Web3 from "web3"; +import type Web3 from "web3"; describeSuite({ id: "W3", From 1a233b91fd723345ba7a7048d7429c8bc7bd3af0 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:30:02 +0000 Subject: [PATCH 02/16] feat: :recycle: Overhaul command parsing --- packages/cli/src/internal/commandParsers.ts | 146 ++++++++++++++------ packages/cli/src/internal/localNode.ts | 4 - packages/cli/src/lib/globalContext.ts | 45 +++--- packages/cli/src/lib/runnerContext.ts | 1 - packages/types/src/config.ts | 42 +++--- packages/types/src/runner.ts | 41 ++---- test/moonwall.config.json | 11 +- 7 files changed, 166 insertions(+), 124 deletions(-) diff --git a/packages/cli/src/internal/commandParsers.ts b/packages/cli/src/internal/commandParsers.ts index 82b1287d..750171b8 100644 --- a/packages/cli/src/internal/commandParsers.ts +++ b/packages/cli/src/internal/commandParsers.ts @@ -3,6 +3,8 @@ import type { DevLaunchSpec, RepoSpec, ZombieLaunchSpec, + LaunchOverrides, + ForkConfig, } from "@moonwall/types"; import chalk from "chalk"; import path from "node:path"; @@ -39,76 +41,127 @@ function fetchDefaultArgs(binName: string, additionalRepos: RepoSpec[] = []): st return defaultArgs; } -export async function parseRunCmd(launchSpec: DevLaunchSpec, additionalRepos?: RepoSpec[]) { - const launch = !launchSpec.running ? true : launchSpec.running; - const cmd = launchSpec.binPath; - const args = launchSpec.options - ? [...launchSpec.options] - : fetchDefaultArgs(path.basename(launchSpec.binPath), additionalRepos); +export class LaunchCommandParser { + private args: string[]; + private cmd: string; + private launch: boolean; + private launchSpec: DevLaunchSpec; + private additionalRepos?: RepoSpec[]; + private launchOverrides?: LaunchOverrides; + + constructor(options: { + launchSpec: DevLaunchSpec; + additionalRepos?: RepoSpec[]; + launchOverrides?: LaunchOverrides; + }) { + const { launchSpec, additionalRepos, launchOverrides } = options; + this.launchSpec = launchSpec; + this.additionalRepos = additionalRepos; + this.launchOverrides = launchOverrides; + this.launch = !launchSpec.running ? true : launchSpec.running; + this.cmd = launchSpec.binPath; + this.args = launchSpec.options + ? [...launchSpec.options] + : fetchDefaultArgs(path.basename(launchSpec.binPath), additionalRepos); + } - const overrideArg = (newArg: string) => { + private overrideArg(newArg: string): void { const newArgKey = newArg.split("=")[0]; - const existingIndex = args.findIndex((arg) => arg.startsWith(`${newArgKey}=`)); + const existingIndex = this.args.findIndex((arg) => arg.startsWith(`${newArgKey}=`)); if (existingIndex !== -1) { - args[existingIndex] = newArg; + this.args[existingIndex] = newArg; } else { - args.push(newArg); + this.args.push(newArg); } - }; + } - if (launchSpec.ports) { - const ports = launchSpec.ports; - if (ports.p2pPort) { - overrideArg(`--port=${ports.p2pPort}`); - } - if (ports.wsPort) { - overrideArg(`--ws-port=${ports.wsPort}`); + withPorts() { + if (this.launchSpec.ports) { + const ports = this.launchSpec.ports; + if (ports.p2pPort) { + this.overrideArg(`--port=${ports.p2pPort}`); + } + if (ports.wsPort) { + this.overrideArg(`--ws-port=${ports.wsPort}`); + } + if (ports.rpcPort) { + this.overrideArg(`--rpc-port=${ports.rpcPort}`); + } + } else { + const freePort = getFreePort().toString(); + process.env.MOONWALL_RPC_PORT = freePort; + + if (this.launchSpec.newRpcBehaviour) { + this.overrideArg(`--rpc-port=${freePort}`); + } else { + this.overrideArg(`--ws-port=${freePort}`); + } } - if (ports.rpcPort) { - overrideArg(`--rpc-port=${ports.rpcPort}`); + return this; + } + + withDefaultForkConfig(): LaunchCommandParser { + const forkOptions = this.launchSpec.defaultForkConfig; + if (forkOptions) { + this.applyForkOptions(forkOptions); } - } else { - const freePort = (await getFreePort()).toString(); - process.env.MOONWALL_RPC_PORT = freePort; + return this; + } - if (launchSpec.newRpcBehaviour) { - overrideArg(`--rpc-port=${freePort}`); - } else { - overrideArg(`--ws-port=${freePort}`); + withLaunchOverrides(): LaunchCommandParser { + if (this.launchOverrides?.forkConfig) { + this.applyForkOptions(this.launchOverrides.forkConfig); } + return this; } - const forkOptions = launchSpec.defaultForkConfig; + private print() { + console.log(chalk.cyan(`Command to run is: ${chalk.bold(this.cmd)}`)); + console.log(chalk.cyan(`Arguments are: ${chalk.bold(this.args.join(" "))}`)); + return this; + } - console.log("forkOptions"); - console.dir(forkOptions, { depth: null }); - if (forkOptions) { + private applyForkOptions(forkOptions: ForkConfig): void { if (forkOptions.url) { invariant(forkOptions.url.startsWith("http"), "Fork URL must start with http:// or https://"); - overrideArg(`--fork-chain-from-rpc=${forkOptions.url}`); + this.overrideArg(`--fork-chain-from-rpc=${forkOptions.url}`); } if (forkOptions.blockNumber) { - overrideArg(`--block=${forkOptions.blockNumber}`); + this.overrideArg(`--block=${forkOptions.blockNumber}`); } if (forkOptions.stateOverridePath) { - overrideArg(`--fork-state-overrides=${forkOptions.stateOverridePath}`); + this.overrideArg(`--fork-state-overrides=${forkOptions.stateOverridePath}`); } if (forkOptions.verbose) { - overrideArg("-llazy-loading=trace"); + this.overrideArg("-llazy-loading=trace"); } } - console.log("post args"); - console.log(args); - return { cmd, args, launch }; -} + build(): { cmd: string; args: string[]; launch: boolean } { + return { + cmd: this.cmd, + args: this.args, + launch: this.launch, + }; + } -export const getFreePort = async () => { - const notionalPort = 10000 + Number(process.env.VITEST_POOL_ID || 1) * 100; - // return getPort({ port: notionalPort }); - return notionalPort; -}; + static create(options: { + launchSpec: DevLaunchSpec; + additionalRepos?: RepoSpec[]; + launchOverrides?: LaunchOverrides; + verbose?: boolean; + }) { + const parser = new LaunchCommandParser(options); + const parsed = parser.withPorts().withDefaultForkConfig().withLaunchOverrides(); + + if (options.verbose) { + parsed.print(); + } + + return parsed.build(); + } +} export function parseChopsticksRunCmd(launchSpecs: ChopsticksLaunchSpec[]): { cmd: string; @@ -167,3 +220,8 @@ export function parseChopsticksRunCmd(launchSpecs: ChopsticksLaunchSpec[]): { launch, }; } + +export const getFreePort = () => { + const notionalPort = 10000 + Number(process.env.VITEST_POOL_ID || 1) * 100; + return notionalPort; +}; diff --git a/packages/cli/src/internal/localNode.ts b/packages/cli/src/internal/localNode.ts index cb579a30..b3e7c974 100644 --- a/packages/cli/src/internal/localNode.ts +++ b/packages/cli/src/internal/localNode.ts @@ -16,10 +16,6 @@ export async function launchNode(cmd: string, args: string[], name: string) { checkAccess(cmd); } - console.log("REMOVE ME") - console.log(cmd) - console.log(args) - const port = args.find((a) => a.includes("port"))?.split("=")[1]; debug(`\x1b[36mStarting ${name} node on port ${port}...\x1b[0m`); diff --git a/packages/cli/src/lib/globalContext.ts b/packages/cli/src/lib/globalContext.ts index f65a49d2..909b0e88 100644 --- a/packages/cli/src/lib/globalContext.ts +++ b/packages/cli/src/lib/globalContext.ts @@ -3,6 +3,7 @@ import type { ConnectedProvider, Environment, FoundationType, + LaunchOverrides, MoonwallConfig, MoonwallEnvironment, MoonwallProvider, @@ -16,7 +17,11 @@ import net from "node:net"; import readline from "node:readline"; import { setTimeout as timer } from "node:timers/promises"; import path from "node:path"; -import { parseChopsticksRunCmd, parseRunCmd, parseZombieCmd } from "../internal/commandParsers"; +import { + LaunchCommandParser, + parseChopsticksRunCmd, + parseZombieCmd, +} from "../internal/commandParsers"; import { type IPCRequestMessage, type IPCResponseMessage, @@ -52,16 +57,16 @@ export class MoonwallContext { zombieNetwork?: Network; rtUpgradePath?: string; ipcServer?: net.Server; - injectedOptions?: object + injectedOptions?: LaunchOverrides; - constructor(config: MoonwallConfig, options?: object) { + constructor(config: MoonwallConfig, options?: LaunchOverrides) { const env = config.environments.find(({ name }) => name === process.env.MOON_TEST_ENV); invariant(env, `Environment ${process.env.MOON_TEST_ENV} not found in config`); this.providers = []; this.nodes = []; this.foundation = env.foundation.type; - this.injectedOptions = options + this.injectedOptions = options; } public async setupFoundation() { @@ -77,10 +82,8 @@ export class MoonwallContext { read_only: this.handleReadOnly, chopsticks: this.handleChopsticks, dev: this.handleDev, - zombie: this.handleZombie + zombie: this.handleZombie, }; - console.log("RUNNING FOUNDATION HANDLER") - console.dir(env.foundation,{depth: null}) const foundationHandler = foundationHandlers[env.foundation.type]; this.environment = { @@ -113,10 +116,12 @@ export class MoonwallContext { private async handleDev(env: Environment, config: MoonwallConfig) { invariant(env.foundation.type === "dev", "Foundation type must be 'dev'"); - const { cmd, args, launch } = await parseRunCmd( - env.foundation.launchSpec[0], - config.additionalRepos - ); + const { cmd, args, launch } = LaunchCommandParser.create({ + launchSpec: env.foundation.launchSpec[0], + additionalRepos: config.additionalRepos, + launchOverrides: this.injectedOptions, + verbose: false, + }); return { name: env.name, @@ -429,9 +434,6 @@ export class MoonwallContext { const nodes = ctx.environment.nodes; - console.log("remove me") - console.dir(nodes, {depth:null}) - if (this.environment.foundationType === "zombie") { return await this.startZombieNetwork(); } @@ -623,9 +625,15 @@ export class MoonwallContext { } } - //TODO: Type options - public static async getContext(config?: MoonwallConfig, options?: object, force = false): Promise { - invariant(!(options && MoonwallContext.instance), "Attempting to open a new context with overrides when context already exists"); + public static async getContext( + config?: MoonwallConfig, + options?: LaunchOverrides, + force = false + ): Promise { + invariant( + !(options && MoonwallContext.instance), + "Attempting to open a new context with overrides when context already exists" + ); if (!MoonwallContext.instance?.configured || force) { invariant(config, "Config must be provided on Global Context instantiation"); @@ -690,8 +698,7 @@ export class MoonwallContext { } } -// TODO: Type this properly! -export const contextCreator = async (options?: object) => { +export const contextCreator = async (options?: LaunchOverrides) => { const config = await importAsyncConfig(); const ctx = await MoonwallContext.getContext(config, options); await runNetworkOnly(); diff --git a/packages/cli/src/lib/runnerContext.ts b/packages/cli/src/lib/runnerContext.ts index e0ef7d4f..eee0077a 100644 --- a/packages/cli/src/lib/runnerContext.ts +++ b/packages/cli/src/lib/runnerContext.ts @@ -83,7 +83,6 @@ export function describeSuite({ let ctx: MoonwallContext | null = null; beforeAll(async () => { - const env = getEnvironmentFromConfig(); if (env.foundation.type === "dev") { // Pass options to contextCreator if they exist diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index a60d37ea..b330f974 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -173,8 +173,7 @@ export type IFoundation = | { type: "read_only"; launchSpec: ReadOnlyLaunchSpec; - } - + }; /** * @name EthTransactionType @@ -228,7 +227,6 @@ export interface ReadOnlyLaunchSpec extends GenericLaunchSpec { disableRuntimeVersionCheck?: boolean; } - /** * A launch specification object for the "zombie" foundation type. * @extends GenericLaunchSpec @@ -341,24 +339,7 @@ export interface DevLaunchSpec extends GenericLaunchSpec { /** * Default Fork options for the node (overriden by per-test fork options) */ - defaultForkConfig?: { - /** - * The URL to fork from - */ - url: string; - /** - * The block number to fork from (optional) - */ - blockNumber?: number; - /** - * The state override path (optional) - */ - stateOverridePath?: string; - /** - * Turns on trace logging for LazyLoading service (optional) - */ - verbose?: boolean; - }; + defaultForkConfig?: ForkConfig; /** * Port configuration @@ -556,3 +537,22 @@ export type Bin = { name: string; defaultArgs?: string[]; }; + +export type ForkConfig = { + /** + * The URL to fork from + */ + url: string; + /** + * The block number to fork from (optional) + */ + blockNumber?: number; + /** + * The state override path (optional) + */ + stateOverridePath?: string; + /** + * Turns on trace logging for LazyLoading service (optional) + */ + verbose?: boolean; +}; diff --git a/packages/types/src/runner.ts b/packages/types/src/runner.ts index b6119118..7c8af5e1 100644 --- a/packages/types/src/runner.ts +++ b/packages/types/src/runner.ts @@ -14,7 +14,7 @@ import type { } from "viem"; import type { Chain } from "viem/chains"; import type { Web3 } from "web3"; -import type { FoundationType } from "./config"; +import type { ForkConfig, FoundationType } from "./config"; import type { BlockCreation, BlockCreationResponse, ChopsticksBlockCreation } from "./context"; import type { ContractDeploymentOptions } from "./contracts"; import type { TransactionType } from "./eth"; @@ -58,7 +58,7 @@ export type FoundationContextMap = { ? ZombieContext : K extends "read_only" ? ReadOnlyContext - : /* default: */ GenericContext; + : /* default: */ GenericContext; }; export type TestContextMap = { @@ -74,24 +74,6 @@ export type TestCasesFn = (params: { // TODO: Extend to include skipIf() and runIf() export type TestCaseModifier = "only" | "skip"; -/** - * Fork configuration options for test cases - */ -export interface ForkConfig { - /** - * RPC endpoint to fork from - */ - endpoint: string; - /** - * Block number to fork from - */ - block?: number; - /** - * Path to state override file - */ - stateOverridePath?: string; -} - export interface ITestCase { id: string; title: string; @@ -110,12 +92,7 @@ export type TestSuiteConfig = { foundationMethods: T; description?: string; testCases: TestCasesFn; -} & (T extends "dev" - ? { - forkConfig: ForkConfig; - } - : // biome-ignore lint/complexity/noBannedTypes: good enough for now - {}); +}; export type FoundationHandler = (params: { testCases: TestCasesFn; @@ -125,15 +102,21 @@ export type FoundationHandler = (params: { ctx?: any; }) => void; +/** + * Represents overrides for launching a test environment. + * @property forkConfig - Optional configuration for forking a network. + */ +export type LaunchOverrides = { + forkConfig?: ForkConfig; +}; + export type ITestSuiteType = { id: string; title: string; testCases: (TestContext: TestContextMap[T]) => void; foundationMethods: T; // TODO: Make this foundation dependent - options?: { - forkConfig: ForkConfig; - }; + options?: LaunchOverrides; minRtVersion?: number; chainType?: ChainType; notChainType?: ChainType; diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 1717a13b..312c0674 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -958,15 +958,13 @@ "launchSpec": [ { "name": "moonbeam", - "running": true, - "binPath": "./tmp/moonbeam", - "disableDefaultEthProviders": true, + "binPath": "tmp/moonbeam", "newRpcBehaviour": true, "options": [ - "-llazy-loading=trace", "--ethapi=txpool", "--no-hardware-benchmarks", "--no-telemetry", + "--wasmtime-precompiled=wasm", "--unsafe-force-node-key-generation", "--reserved-only", "--no-grandpa", @@ -978,8 +976,9 @@ "--tmp" ], "defaultForkConfig": { - "url": "https://moonbeam.kaki.dev", - "stateOverridePath": "./configs/mbStateOverride.json" + "url": "https://moonbeam.unitedbloc.com", + "stateOverridePath": "tmp/mbStateOverride.json", + "verbose": true } } ] From 3b41c620a9a74c1814e20350bea370754b959bc5 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:35:49 +0000 Subject: [PATCH 03/16] refactor: :recycle: Refactor to use invariant --- packages/cli/src/lib/globalContext.ts | 55 ++++++++++----------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/packages/cli/src/lib/globalContext.ts b/packages/cli/src/lib/globalContext.ts index 909b0e88..915dc65e 100644 --- a/packages/cli/src/lib/globalContext.ts +++ b/packages/cli/src/lib/globalContext.ts @@ -149,15 +149,13 @@ export class MoonwallContext { } private async handleReadOnly(env: Environment) { - if (env.foundation.type !== "read_only") { - throw new Error(`Foundation type must be 'read_only'`); - } + invariant(env.foundation.type === "read_only", "Foundation type must be 'read_only'"); + + invariant( + env.connections, + `${env.name} env config is missing connections specification, required by foundation READ_ONLY` + ); - if (!env.connections) { - throw new Error( - `${env.name} env config is missing connections specification, required by foundation READ_ONLY` - ); - } return { name: env.name, foundationType: "read_only", @@ -166,15 +164,11 @@ export class MoonwallContext { } private async handleChopsticks(env: Environment) { - if (env.foundation.type !== "chopsticks") { - throw new Error(`Foundation type must be 'chopsticks'`); - } - - if (!env.connections || env.connections.length === 0) { - throw new Error( - `${env.name} env config is missing connections specification, required by foundation CHOPSTICKS` - ); - } + invariant(env.foundation.type === "chopsticks", "Foundation type must be 'chopsticks'"); + invariant( + env.connections && env.connections.length > 0, + `${env.name} env config is missing connections specification, required by foundation CHOPSTICKS` + ); this.rtUpgradePath = env.foundation.rtUpgradePath; return { @@ -187,9 +181,10 @@ export class MoonwallContext { private async startZombieNetwork() { const env = getEnvironmentFromConfig(); - if (env.foundation.type !== "zombie") { - throw new Error(`Foundation type must be 'zombie', something has gone very wrong.`); - } + invariant( + env.foundation.type === "zombie", + "Foundation type must be 'zombie', something has gone very wrong." + ); console.log("🧟 Spawning zombie nodes ..."); const nodes = this.environment.nodes; @@ -219,9 +214,7 @@ export class MoonwallContext { const onProcessExit = () => { try { - if (!this.zombieNetwork) { - throw "Zombie network not found to kill"; - } + invariant(this.zombieNetwork, "Zombie network not found to kill"); const processIds = Object.values((this.zombieNetwork.client as any).processMap) .filter((item: any) => item.pid) @@ -261,13 +254,10 @@ export class MoonwallContext { try { const message: IPCRequestMessage = JSON.parse(data.toString()); + invariant(message.nodeName, "nodeName not provided in message"); const zombieClient = network.client; - if (!message.nodeName) { - throw new Error("nodeName not provided in message"); - } - switch (message.cmd) { case "networkmap": { const result = Object.keys(network.nodesByName); @@ -371,7 +361,7 @@ export class MoonwallContext { } default: - throw new Error(`Invalid command received: ${message.cmd}`); + invariant(false, `Invalid command received: ${message.cmd}`); } } catch (e: any) { logIpc("📨 Error processing message from client"); @@ -542,9 +532,7 @@ export class MoonwallContext { const envVar = process.env.MOON_ZOMBIE_NODES; - if (!envVar) { - throw new Error("MOON_ZOMBIE_NODES not set, this is an error please raise."); - } + invariant(envVar, "MOON_ZOMBIE_NODES not set, this is an error please raise."); const zombieNodeLogs = envVar .split("|") @@ -599,10 +587,7 @@ export class MoonwallContext { public async disconnect(providerName?: string) { if (providerName) { const prov = this.providers.find(({ name }) => name === providerName); - - if (!prov) { - throw new Error(`Provider ${providerName} not found`); - } + invariant(prov, `Provider ${providerName} not found`); try { await prov.disconnect(); From ce941a0055bd3820850d61c105e3fc0787265868 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:30:18 +0000 Subject: [PATCH 04/16] test: :white_check_mark: Added fork test to CI --- .changeset/lucky-boats-cheat.md | 11 +++ docs/guide/intro/foundations.md | 7 +- docs/guide/intro/getting-started.md | 1 - packages/types/config_schema.json | 2 +- packages/types/src/config.ts | 2 +- packages/types/src/runner.ts | 2 +- test/moonwall.config.json | 8 ++- test/scripts/compile-wasm.ts | 105 ++++++++++++++++++++++++++++ test/suites/fork_test/test_fork.ts | 10 +-- 9 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 .changeset/lucky-boats-cheat.md create mode 100644 test/scripts/compile-wasm.ts diff --git a/.changeset/lucky-boats-cheat.md b/.changeset/lucky-boats-cheat.md new file mode 100644 index 00000000..5cbcd008 --- /dev/null +++ b/.changeset/lucky-boats-cheat.md @@ -0,0 +1,11 @@ +--- +"@moonwall/types": major +"@moonwall/cli": major +"@moonwall/tests": major +"@moonwall/docs": major +"@moonwall/util": major +--- + +Added Fork config to dev foundations + +- BETA: Added ability to use moonbeam's fork API both via moonwall.config and also in a test diff --git a/docs/guide/intro/foundations.md b/docs/guide/intro/foundations.md index 932f9393..1e5e1f04 100644 --- a/docs/guide/intro/foundations.md +++ b/docs/guide/intro/foundations.md @@ -48,9 +48,4 @@ Use Read Only if Moonwall doesn't need to start any networks - you've already go ::: tip Zombie is the ideal Foundation for testing cross chain interactions including XCM. -::: - - -### Fork: - -- 🚧 Not yet implemented! Will be part of a new way of forking the network with a real client. +::: \ No newline at end of file diff --git a/docs/guide/intro/getting-started.md b/docs/guide/intro/getting-started.md index 481ad17c..5931517d 100644 --- a/docs/guide/intro/getting-started.md +++ b/docs/guide/intro/getting-started.md @@ -87,7 +87,6 @@ This isn't too important as you will always be able to create new environment sp - `chopsticks` : Using Acala Foundation's Chopsticks to start a lazily-forked network. - `read_only`: Not starting a network but instead connecting to one that already exists. - `zombie`: Using ParityTech's ZombieNetwork framework to run a multi-node network -- `fork` : 🚧 Not yet implemented! Will be part of a new way of forking the network with a real client ::: tip This is the very brief rundown of foundations. For their specific information please visit the relevant sections in [Config](/guide/intro/foundations). diff --git a/packages/types/config_schema.json b/packages/types/config_schema.json index 0648f2fc..d0096abc 100644 --- a/packages/types/config_schema.json +++ b/packages/types/config_schema.json @@ -73,7 +73,7 @@ "type": "string" }, "defaultForkConfig": { - "description": "Default Fork options for the node (overriden by per-test fork options)", + "description": "BETA: Default Fork options for the node (overriden by per-test fork options)", "properties": { "blockNumber": { "description": "The block number to fork from (optional)", diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index b330f974..ced123fc 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -337,7 +337,7 @@ export interface DevLaunchSpec extends GenericLaunchSpec { newRpcBehaviour?: boolean; /** - * Default Fork options for the node (overriden by per-test fork options) + * BETA: Default Fork options for the node (overriden by per-test fork options) */ defaultForkConfig?: ForkConfig; diff --git a/packages/types/src/runner.ts b/packages/types/src/runner.ts index 7c8af5e1..1cca1d84 100644 --- a/packages/types/src/runner.ts +++ b/packages/types/src/runner.ts @@ -103,7 +103,7 @@ export type FoundationHandler = (params: { }) => void; /** - * Represents overrides for launching a test environment. + * BETA: Represents overrides for launching a test environment. * @property forkConfig - Optional configuration for forking a network. */ export type LaunchOverrides = { diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 312c0674..6c0c3c29 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -953,6 +953,9 @@ { "name": "fork_test", "testFileDir": ["suites/fork_test"], + "runScripts": [ + "compile-wasm.ts compile -b tmp/moonbeam -o tmp/wasm -c moonbeam-dev" + ], "foundation": { "type": "dev", "launchSpec": [ @@ -960,11 +963,12 @@ "name": "moonbeam", "binPath": "tmp/moonbeam", "newRpcBehaviour": true, + "disableDefaultEthProviders": true, "options": [ "--ethapi=txpool", "--no-hardware-benchmarks", "--no-telemetry", - "--wasmtime-precompiled=wasm", + "--wasmtime-precompiled=tmp/wasm", "--unsafe-force-node-key-generation", "--reserved-only", "--no-grandpa", @@ -977,7 +981,7 @@ ], "defaultForkConfig": { "url": "https://moonbeam.unitedbloc.com", - "stateOverridePath": "tmp/mbStateOverride.json", + "stateOverridePath": "./configs/mbStateOverride.json", "verbose": true } } diff --git a/test/scripts/compile-wasm.ts b/test/scripts/compile-wasm.ts new file mode 100644 index 00000000..5091123d --- /dev/null +++ b/test/scripts/compile-wasm.ts @@ -0,0 +1,105 @@ +import fs from "fs/promises"; +import path from "path"; +import child_process from "child_process"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; + +yargs(hideBin(process.argv)) + .usage("Usage: $0") + .version("2.0.0") + .options({ + OutputDirectory: { + type: "string", + alias: "o", + description: "Output directory for compiled contracts", + default: "precompiled-wasm", + }, + Binary: { + type: "string", + alias: "b", + description: "Moonbeam binary path", + default: "contracts/src", + }, + Chain: { + type: "string", + alias: "c", + description: "runtime chain to use", + require: true, + }, + Verbose: { + type: "boolean", + alias: "v", + description: "Verbose mode for extra logging.", + default: false, + }, + }) + .command("compile", "Compile wasm", async (argv) => { + await main(argv as any); + }) + .parse(); + +async function spawn(cmd: string) { + return new Promise((resolve, reject) => { + var spawned = child_process.spawn(cmd, { shell: true }); + + let errData = ""; + let outData = ""; + spawned.stdout.on("data", (chunk) => { + outData += chunk.toString(); + }); + + spawned.stderr.on("data", (chunk) => { + errData += chunk.toString(); + }); + + spawned.on("close", function (code) { + if (code && code > 0) { + return reject(new Error(errData)); + } + + resolve(outData); + }); + + spawned.on("error", function (err) { + reject(err); + }); + }); +} + +async function main(args: any) { + const outputDirectory = path.join(process.cwd(), args.argv.OutputDirectory); + const binaryPath = args.argv.Binary; + + console.log(`🗃️ Binary: ${binaryPath}`); + console.log(`🗃️ Output directory: ${outputDirectory}`); + + child_process.execSync(`mkdir -p ${outputDirectory}`); + + await fs.mkdir("tmp", { recursive: true }); + const tmpDir = await fs.mkdtemp("tmp/base-path"); + try { + // Generate plain chain spec + const generateChainSpecCmd = + `${binaryPath} build-spec` + ` --chain ${args.argv.Chain} > tmp/${args.argv.Chain}.json`; + console.log(`🗃️ ${generateChainSpecCmd}`); + await spawn(generateChainSpecCmd); + + // Generate raw chain spec + const generateRawChainSpecCmd = + `${binaryPath} build-spec --chain tmp/${args.argv.Chain}.json ` + + `--raw > tmp/${args.argv.Chain}-raw.json`; + console.log(`🗃️ ${generateRawChainSpecCmd}`); + await spawn(generateRawChainSpecCmd); + + // Generate precompiled wasm + const command = + `${binaryPath} precompile-wasm --log=wasmtime-runtime --base-path=${tmpDir} ` + + `--chain tmp/${args.argv.Chain}-raw.json ${outputDirectory}`; + console.log(`🗃️ ${command}`); + await spawn(command); + } finally { + if ((await fs.stat(tmpDir)).isDirectory()) { + await fs.rm(tmpDir, { recursive: true, force: true }); + } + } +} diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts index 59416b20..67f5fffb 100644 --- a/test/suites/fork_test/test_fork.ts +++ b/test/suites/fork_test/test_fork.ts @@ -8,15 +8,17 @@ describeSuite({ foundationMethods: "dev", options: { forkConfig: { - endpoint: "https://moonbeam.public.blastapi.io", - block: 100, + url: "https://moonbeam.public.blastapi.io", + verbose: true }, }, - testCases: ({ it, context }) => { + testCases: ({ it, context , log}) => { let polkadotJs: ApiPromise; - beforeAll(() => { + beforeAll(async () => { polkadotJs = context.polkadotJs(); + log("Waiting a minute for lazy loading to do its thing"); + await new Promise((resolve) => setTimeout(resolve, 60_000)); // wait for LL loading 1 minute }); it({ From ad8028f3fc8b5ffa47aa3b2d785e229d490aaf66 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:30:43 +0000 Subject: [PATCH 05/16] test: :white_check_mark: add fork test --- .github/workflows/main.yml | 2 +- test/configs/mbStateOverride.json | 7 +- test/moonwall.config.json | 5 +- test/scripts/compile-wasm.ts | 105 ----------------------------- test/suites/fork_test/test_fork.ts | 24 +++++-- 5 files changed, 26 insertions(+), 117 deletions(-) delete mode 100644 test/scripts/compile-wasm.ts diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1448030..1ddedcc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -114,7 +114,7 @@ jobs: strategy: fail-fast: false matrix: - suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke", "papi_dev"] + suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke", "papi_dev", "fork_test"] shard: [1, 2, 3, 4] steps: - uses: actions/checkout@v4 diff --git a/test/configs/mbStateOverride.json b/test/configs/mbStateOverride.json index fe51488c..a675a1cf 100644 --- a/test/configs/mbStateOverride.json +++ b/test/configs/mbStateOverride.json @@ -1 +1,6 @@ -[] +[ + { + "key": "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da90b65f88190770e2d4021d80a480ecf9c8300db2442725604b8f5eb172692bb15078205c2", + "value": "0x000000000000000001000000000000000000443945309a7a4800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080" + } +] diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 6c0c3c29..c803b39d 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -953,9 +953,7 @@ { "name": "fork_test", "testFileDir": ["suites/fork_test"], - "runScripts": [ - "compile-wasm.ts compile -b tmp/moonbeam -o tmp/wasm -c moonbeam-dev" - ], + "foundation": { "type": "dev", "launchSpec": [ @@ -968,7 +966,6 @@ "--ethapi=txpool", "--no-hardware-benchmarks", "--no-telemetry", - "--wasmtime-precompiled=tmp/wasm", "--unsafe-force-node-key-generation", "--reserved-only", "--no-grandpa", diff --git a/test/scripts/compile-wasm.ts b/test/scripts/compile-wasm.ts deleted file mode 100644 index 5091123d..00000000 --- a/test/scripts/compile-wasm.ts +++ /dev/null @@ -1,105 +0,0 @@ -import fs from "fs/promises"; -import path from "path"; -import child_process from "child_process"; -import yargs from "yargs"; -import { hideBin } from "yargs/helpers"; - -yargs(hideBin(process.argv)) - .usage("Usage: $0") - .version("2.0.0") - .options({ - OutputDirectory: { - type: "string", - alias: "o", - description: "Output directory for compiled contracts", - default: "precompiled-wasm", - }, - Binary: { - type: "string", - alias: "b", - description: "Moonbeam binary path", - default: "contracts/src", - }, - Chain: { - type: "string", - alias: "c", - description: "runtime chain to use", - require: true, - }, - Verbose: { - type: "boolean", - alias: "v", - description: "Verbose mode for extra logging.", - default: false, - }, - }) - .command("compile", "Compile wasm", async (argv) => { - await main(argv as any); - }) - .parse(); - -async function spawn(cmd: string) { - return new Promise((resolve, reject) => { - var spawned = child_process.spawn(cmd, { shell: true }); - - let errData = ""; - let outData = ""; - spawned.stdout.on("data", (chunk) => { - outData += chunk.toString(); - }); - - spawned.stderr.on("data", (chunk) => { - errData += chunk.toString(); - }); - - spawned.on("close", function (code) { - if (code && code > 0) { - return reject(new Error(errData)); - } - - resolve(outData); - }); - - spawned.on("error", function (err) { - reject(err); - }); - }); -} - -async function main(args: any) { - const outputDirectory = path.join(process.cwd(), args.argv.OutputDirectory); - const binaryPath = args.argv.Binary; - - console.log(`🗃️ Binary: ${binaryPath}`); - console.log(`🗃️ Output directory: ${outputDirectory}`); - - child_process.execSync(`mkdir -p ${outputDirectory}`); - - await fs.mkdir("tmp", { recursive: true }); - const tmpDir = await fs.mkdtemp("tmp/base-path"); - try { - // Generate plain chain spec - const generateChainSpecCmd = - `${binaryPath} build-spec` + ` --chain ${args.argv.Chain} > tmp/${args.argv.Chain}.json`; - console.log(`🗃️ ${generateChainSpecCmd}`); - await spawn(generateChainSpecCmd); - - // Generate raw chain spec - const generateRawChainSpecCmd = - `${binaryPath} build-spec --chain tmp/${args.argv.Chain}.json ` + - `--raw > tmp/${args.argv.Chain}-raw.json`; - console.log(`🗃️ ${generateRawChainSpecCmd}`); - await spawn(generateRawChainSpecCmd); - - // Generate precompiled wasm - const command = - `${binaryPath} precompile-wasm --log=wasmtime-runtime --base-path=${tmpDir} ` + - `--chain tmp/${args.argv.Chain}-raw.json ${outputDirectory}`; - console.log(`🗃️ ${command}`); - await spawn(command); - } finally { - if ((await fs.stat(tmpDir)).isDirectory()) { - await fs.rm(tmpDir, { recursive: true, force: true }); - } - } -} diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts index 67f5fffb..be7a4b0a 100644 --- a/test/suites/fork_test/test_fork.ts +++ b/test/suites/fork_test/test_fork.ts @@ -8,17 +8,15 @@ describeSuite({ foundationMethods: "dev", options: { forkConfig: { - url: "https://moonbeam.public.blastapi.io", - verbose: true + url: "https://moonbeam.unitedbloc.com", + verbose: true, }, }, - testCases: ({ it, context , log}) => { + testCases: ({ it, context, log }) => { let polkadotJs: ApiPromise; beforeAll(async () => { polkadotJs = context.polkadotJs(); - log("Waiting a minute for lazy loading to do its thing"); - await new Promise((resolve) => setTimeout(resolve, 60_000)); // wait for LL loading 1 minute }); it({ @@ -26,10 +24,24 @@ describeSuite({ title: "Checking that launched node can create blocks", test: async () => { const block = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); - await context.createBlock(); + await context.createBlock([], { finalize: false }); const block2 = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); expect(block2).to.be.greaterThan(block); }, }); + + it({ + id: "T02", + title: "Check that state overrides work", + test: async () => { + const testAccount = "0x8300db2442725604b8f5Eb172692Bb15078205c2"; + log(`Address: ${testAccount}`); + + const { + data: { free }, + } = await polkadotJs.query.system.account(testAccount); + expect(free.toBigInt(), "Free balance should be 1337000").toBe(1337000000000000000000n); + }, + }); }, }); 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 06/16] 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); + }, + }); }, }); From d24eb2e7ba1413c93e7a91f19f1d70c02abe6606 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:37:13 +0000 Subject: [PATCH 07/16] add new CI --- .github/workflows/main.yml | 36 +++++++++++++++++ packages/cli/src/cmds/entrypoint.ts | 6 +++ packages/cli/src/cmds/runTests.ts | 1 + test/moonwall.config.json | 11 +++++ test/snapshot_output.txt | 18 +++++++++ .../update/__snapshots__/test_basic.ts.snap | 3 ++ test/suites/update/test_basic.ts | 40 +++++++++++++++++++ test/suites/update/timbo.txt | 1 + 8 files changed, 116 insertions(+) create mode 100644 test/snapshot_output.txt create mode 100644 test/suites/update/__snapshots__/test_basic.ts.snap create mode 100644 test/suites/update/test_basic.ts create mode 100644 test/suites/update/timbo.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ddedcc4..e6772bae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -145,6 +145,42 @@ jobs: bun papi generate bun moonwall test ${{matrix.suite}} --ts ${{ matrix.shard }}/4 + test_update: + runs-on: ubuntu-latest + needs: ["build"] + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - uses: pnpm/action-setup@v4 + with: + version: 9.1.4 + - uses: actions/setup-node@v4 + with: + node-version: 23 + cache: "pnpm" + - name: Build like before + run: | + pnpm install + pnpm run build + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - name: Run snapshot update test + id: update_test + run: | + cd test + bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1 + - name: Check if files were modified in the 2 minutes + run: | + cd test + find suites/update/__snapshots__/test_basic.ts.snap suites/update/timbo.txt -mmin -2 | wc -l | grep -q "2" + - name: Check console output for snapshot updates + run: | + cd test + grep -q "Snapshots 3 updated" snapshot_output.txt + test_chopsticks: runs-on: ubuntu-latest needs: ["build"] diff --git a/packages/cli/src/cmds/entrypoint.ts b/packages/cli/src/cmds/entrypoint.ts index a6dc576b..75af0a57 100755 --- a/packages/cli/src/cmds/entrypoint.ts +++ b/packages/cli/src/cmds/entrypoint.ts @@ -90,6 +90,11 @@ yargs(hideBin(process.argv)) describe: "Test Shard info for CI", alias: "ts", type: "string", + }) + .option("update", { + describe: "Update all snapshots", + alias: "u", + type: "boolean", }); }, async (args) => { @@ -100,6 +105,7 @@ yargs(hideBin(process.argv)) testNamePattern: args.GrepTest, subDirectory: args.subDirectory, shard: args.testShard, + update: args.update , })) ) { process.exitCode = 1; diff --git a/packages/cli/src/cmds/runTests.ts b/packages/cli/src/cmds/runTests.ts index c5e9023c..0d31efd6 100644 --- a/packages/cli/src/cmds/runTests.ts +++ b/packages/cli/src/cmds/runTests.ts @@ -54,6 +54,7 @@ export type testRunArgs = { testNamePattern?: string; subDirectory?: string; shard?: string; + update?: boolean; }; export async function executeTests(env: Environment, testRunArgs?: testRunArgs) { diff --git a/test/moonwall.config.json b/test/moonwall.config.json index c803b39d..42fa1756 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -78,6 +78,17 @@ ] } }, + { + "name": "update_snapshot", + "testFileDir": ["suites/update"], + "foundation": { + "type": "read_only", + "launchSpec": { + "disableRuntimeVersionCheck": true + } + }, + "connections": [] + }, { "name": "failing_prescript", "testFileDir": ["suites/basic"], diff --git a/test/snapshot_output.txt b/test/snapshot_output.txt new file mode 100644 index 00000000..ad827403 --- /dev/null +++ b/test/snapshot_output.txt @@ -0,0 +1,18 @@ +Could not read runtime name or version +To fix: ensure moonwall config has a polkadotJs provider with a name containing 'para' +No output file specified, skipping + + RUN v2.1.4 /home/timbo/workspace/moonsong/moonwall/test + +stdout | suites/update/test_basic.ts > 🗃️ U01 This is a test suite that tests the update snapshot feature +2024-11-27T15:30:32.414Z test:update_snapshot The random number is 67 + + ✓ |update_snapshot| suites/update/test_basic.ts (3 tests) 9ms + + Snapshots 3 updated + Test Files 1 passed (1) + Tests 3 passed (3) + Start at 15:30:30 + Duration 2.05s (transform 104ms, setup 0ms, collect 1.90s, tests 9ms, environment 0ms, prepare 45ms) + +✅ All tests passed diff --git a/test/suites/update/__snapshots__/test_basic.ts.snap b/test/suites/update/__snapshots__/test_basic.ts.snap new file mode 100644 index 00000000..6cce7841 --- /dev/null +++ b/test/suites/update/__snapshots__/test_basic.ts.snap @@ -0,0 +1,3 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `43`; diff --git a/test/suites/update/test_basic.ts b/test/suites/update/test_basic.ts new file mode 100644 index 00000000..09ae7471 --- /dev/null +++ b/test/suites/update/test_basic.ts @@ -0,0 +1,40 @@ +import { expect, describeSuite, beforeAll } from "@moonwall/cli"; + +describeSuite({ + id: "U01", + title: "This is a test suite that tests the update snapshot feature", + foundationMethods: "read_only", + testCases: ({ it, log }) => { + let random: number + + beforeAll(() => { + random = Math.floor(Math.random() * 100); + log(`The random number is ${random}`); + }); + + it({ + id: "T01", + title: "In-line snapshot", + test: () => { + // biome-ignore lint/style/noUnusedTemplateLiteral: + expect(random).toMatchInlineSnapshot(`43`); + }, + }); + + it({ + id: "T02", + title: "Normal snapshot", + test: () => { + expect(random).toMatchSnapshot(); + }, + }); + + it({ + id: "T03", + title: "File snapshot", + test: () => { + expect(random).toMatchFileSnapshot("./timbo.txt"); + }, + }); + }, +}); diff --git a/test/suites/update/timbo.txt b/test/suites/update/timbo.txt new file mode 100644 index 00000000..ac4213d6 --- /dev/null +++ b/test/suites/update/timbo.txt @@ -0,0 +1 @@ +43 \ No newline at end of file From 904ff85a0bbf451b2884a97c59e3848d419e15be Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:40:02 +0000 Subject: [PATCH 08/16] fmt --- packages/cli/src/cmds/entrypoint.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/cmds/entrypoint.ts b/packages/cli/src/cmds/entrypoint.ts index 75af0a57..7a3b04d4 100755 --- a/packages/cli/src/cmds/entrypoint.ts +++ b/packages/cli/src/cmds/entrypoint.ts @@ -105,7 +105,7 @@ yargs(hideBin(process.argv)) testNamePattern: args.GrepTest, subDirectory: args.subDirectory, shard: args.testShard, - update: args.update , + update: args.update, })) ) { process.exitCode = 1; From 6e342c180f0f0f8ab0b1cf0ba6bf893bbe5353db Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:45:46 +0000 Subject: [PATCH 09/16] snapshot output --- test/.gitignore | 1 + test/snapshot_output.txt | 18 ------------------ test/suites/fork_test/test_fork.ts | 7 +++++-- test/suites/update/test_basic.ts | 2 +- 4 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 test/snapshot_output.txt diff --git a/test/.gitignore b/test/.gitignore index 6f3e66fe..e62c03e4 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -17,3 +17,4 @@ cache artifacts **/tmp/* **/contracts/out/ +snapshot_output.txt \ No newline at end of file diff --git a/test/snapshot_output.txt b/test/snapshot_output.txt deleted file mode 100644 index ad827403..00000000 --- a/test/snapshot_output.txt +++ /dev/null @@ -1,18 +0,0 @@ -Could not read runtime name or version -To fix: ensure moonwall config has a polkadotJs provider with a name containing 'para' -No output file specified, skipping - - RUN v2.1.4 /home/timbo/workspace/moonsong/moonwall/test - -stdout | suites/update/test_basic.ts > 🗃️ U01 This is a test suite that tests the update snapshot feature -2024-11-27T15:30:32.414Z test:update_snapshot The random number is 67 - - ✓ |update_snapshot| suites/update/test_basic.ts (3 tests) 9ms - - Snapshots 3 updated - Test Files 1 passed (1) - Tests 3 passed (3) - Start at 15:30:30 - Duration 2.05s (transform 104ms, setup 0ms, collect 1.90s, tests 9ms, environment 0ms, prepare 45ms) - -✅ All tests passed diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts index 09442d48..9ca90483 100644 --- a/test/suites/fork_test/test_fork.ts +++ b/test/suites/fork_test/test_fork.ts @@ -10,7 +10,7 @@ describeSuite({ forkConfig: { url: "https://moonbeam.unitedbloc.com", verbose: true, - blockHash: "0xffe39256c17cc4523a07c907bcf1aeeef4db217cd57cfcfb95d56088e0bb9f2d" + blockHash: "0xffe39256c17cc4523a07c907bcf1aeeef4db217cd57cfcfb95d56088e0bb9f2d", }, }, testCases: ({ it, context, log }) => { @@ -55,7 +55,10 @@ describeSuite({ 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); + expect( + free.toBigInt(), + `Free balance should match what account ${testAccount} has at block #8508372` + ).toBe(76562560590695097485140n); }, }); }, diff --git a/test/suites/update/test_basic.ts b/test/suites/update/test_basic.ts index 09ae7471..82b50add 100644 --- a/test/suites/update/test_basic.ts +++ b/test/suites/update/test_basic.ts @@ -5,7 +5,7 @@ describeSuite({ title: "This is a test suite that tests the update snapshot feature", foundationMethods: "read_only", testCases: ({ it, log }) => { - let random: number + let random: number; beforeAll(() => { random = Math.floor(Math.random() * 100); From 69f55c676996046b80708f09aefd3a4582ef8ef4 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:47:24 +0000 Subject: [PATCH 10/16] ci --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6772bae..38cbcd26 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -175,10 +175,12 @@ jobs: - name: Check if files were modified in the 2 minutes run: | cd test + find suites/update/__snapshots__/test_basic.ts.snap suites/update/timbo.txt find suites/update/__snapshots__/test_basic.ts.snap suites/update/timbo.txt -mmin -2 | wc -l | grep -q "2" - name: Check console output for snapshot updates run: | cd test + cat snapshot_output.txt grep -q "Snapshots 3 updated" snapshot_output.txt test_chopsticks: From 6d12be686bab3bb1ae75c48b0468c6044fba671b Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:59:38 +0000 Subject: [PATCH 11/16] ci --- .github/workflows/main.yml | 2 +- test/suites/update/__snapshots__/test_basic.ts.snap | 2 +- test/suites/update/test_basic.ts | 2 +- test/suites/update/timbo.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 38cbcd26..d8ab8b1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -181,7 +181,7 @@ jobs: run: | cd test cat snapshot_output.txt - grep -q "Snapshots 3 updated" snapshot_output.txt + grep "Snapshots 3 updated" snapshot_output.txt test_chopsticks: runs-on: ubuntu-latest diff --git a/test/suites/update/__snapshots__/test_basic.ts.snap b/test/suites/update/__snapshots__/test_basic.ts.snap index 6cce7841..10aef1c7 100644 --- a/test/suites/update/__snapshots__/test_basic.ts.snap +++ b/test/suites/update/__snapshots__/test_basic.ts.snap @@ -1,3 +1,3 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `43`; +exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `40`; diff --git a/test/suites/update/test_basic.ts b/test/suites/update/test_basic.ts index 82b50add..8a1c3c0c 100644 --- a/test/suites/update/test_basic.ts +++ b/test/suites/update/test_basic.ts @@ -17,7 +17,7 @@ describeSuite({ title: "In-line snapshot", test: () => { // biome-ignore lint/style/noUnusedTemplateLiteral: - expect(random).toMatchInlineSnapshot(`43`); + expect(random).toMatchInlineSnapshot(`40`); }, }); diff --git a/test/suites/update/timbo.txt b/test/suites/update/timbo.txt index ac4213d6..86ee83a4 100644 --- a/test/suites/update/timbo.txt +++ b/test/suites/update/timbo.txt @@ -1 +1 @@ -43 \ No newline at end of file +40 \ No newline at end of file From b75fc43edeefb2d7dbad0fd400c020b19d72d7d2 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:08:58 +0000 Subject: [PATCH 12/16] ci --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8ab8b1b..37225f20 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -148,6 +148,8 @@ jobs: test_update: runs-on: ubuntu-latest needs: ["build"] + env: + CI: false steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1 From 56fe0a1e43bbd3c648c1d8927e75455c4f32af54 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:11:13 +0000 Subject: [PATCH 13/16] CI --- .github/workflows/main.yml | 4 +--- test/suites/update/__snapshots__/test_basic.ts.snap | 2 +- test/suites/update/test_basic.ts | 2 +- test/suites/update/timbo.txt | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37225f20..e627800e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -148,8 +148,6 @@ jobs: test_update: runs-on: ubuntu-latest needs: ["build"] - env: - CI: false steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1 @@ -173,7 +171,7 @@ jobs: id: update_test run: | cd test - bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1 + CI=false bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1 - name: Check if files were modified in the 2 minutes run: | cd test diff --git a/test/suites/update/__snapshots__/test_basic.ts.snap b/test/suites/update/__snapshots__/test_basic.ts.snap index 10aef1c7..39598abd 100644 --- a/test/suites/update/__snapshots__/test_basic.ts.snap +++ b/test/suites/update/__snapshots__/test_basic.ts.snap @@ -1,3 +1,3 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `40`; +exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `7`; diff --git a/test/suites/update/test_basic.ts b/test/suites/update/test_basic.ts index 8a1c3c0c..84f4d178 100644 --- a/test/suites/update/test_basic.ts +++ b/test/suites/update/test_basic.ts @@ -17,7 +17,7 @@ describeSuite({ title: "In-line snapshot", test: () => { // biome-ignore lint/style/noUnusedTemplateLiteral: - expect(random).toMatchInlineSnapshot(`40`); + expect(random).toMatchInlineSnapshot(`7`); }, }); diff --git a/test/suites/update/timbo.txt b/test/suites/update/timbo.txt index 86ee83a4..c7930257 100644 --- a/test/suites/update/timbo.txt +++ b/test/suites/update/timbo.txt @@ -1 +1 @@ -40 \ No newline at end of file +7 \ No newline at end of file From 2ff132818e4ea2acf06be915dc1c529438735960 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:29:30 +0000 Subject: [PATCH 14/16] ci --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e627800e..f2142d27 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -148,6 +148,9 @@ jobs: test_update: runs-on: ubuntu-latest needs: ["build"] + env: + NO_COLOR: 1 + steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1 From 9a9382125ff6c9b320feec78ab573d4372b7d963 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:34:10 +0000 Subject: [PATCH 15/16] ci --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f2142d27..3f37d0ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -150,7 +150,6 @@ jobs: needs: ["build"] env: NO_COLOR: 1 - steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1 @@ -174,7 +173,7 @@ jobs: id: update_test run: | cd test - CI=false bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1 + bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1 - name: Check if files were modified in the 2 minutes run: | cd test From 1afcbca0c166f627914bbb1a91afcad11eeb5667 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:35:52 +0000 Subject: [PATCH 16/16] docs --- .changeset/cuddly-planets-sniff.md | 8 ++++++++ .changeset/lucky-boats-cheat.md | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/cuddly-planets-sniff.md diff --git a/.changeset/cuddly-planets-sniff.md b/.changeset/cuddly-planets-sniff.md new file mode 100644 index 00000000..f8548cb3 --- /dev/null +++ b/.changeset/cuddly-planets-sniff.md @@ -0,0 +1,8 @@ +--- +"@moonwall/types": patch +"@moonwall/cli": patch +"@moonwall/docs": patch +"@moonwall/tests": patch +--- + +Add snapshot update option diff --git a/.changeset/lucky-boats-cheat.md b/.changeset/lucky-boats-cheat.md index 5cbcd008..00cae3e8 100644 --- a/.changeset/lucky-boats-cheat.md +++ b/.changeset/lucky-boats-cheat.md @@ -1,9 +1,9 @@ --- -"@moonwall/types": major -"@moonwall/cli": major -"@moonwall/tests": major -"@moonwall/docs": major -"@moonwall/util": major +"@moonwall/types": minor +"@moonwall/cli": minor +"@moonwall/tests": minor +"@moonwall/docs": minor +"@moonwall/util": minor --- Added Fork config to dev foundations