From bead373193c408f12ea3b43e210fdaaa61b06d19 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:59:58 +0000 Subject: [PATCH] restored WS --- packages/cli/package.json | 1 + packages/cli/src/cmds/entrypoint.ts | 16 ++++++++++------ packages/cli/src/internal/providerFactories.ts | 16 ++++++++++++---- packages/cli/src/lib/globalContextEffect.ts | 5 ----- pnpm-lock.yaml | 3 +++ 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index b5afe958..9d0979d1 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -94,6 +94,7 @@ "viem": "^1.19.3", "vitest": "1.0.0-beta.4", "web3": "4.2.2", + "why-is-node-running": "^2.2.2", "ws": "^8.14.2", "yaml": "^2.3.4", "yargs": "^17.7.2" diff --git a/packages/cli/src/cmds/entrypoint.ts b/packages/cli/src/cmds/entrypoint.ts index 18261d15..61760f54 100755 --- a/packages/cli/src/cmds/entrypoint.ts +++ b/packages/cli/src/cmds/entrypoint.ts @@ -1,4 +1,5 @@ import "../internal/logging"; +import log from "why-is-node-running"; import "@moonbeam-network/api-augment"; import yargs from "yargs"; import fs from "fs"; @@ -120,8 +121,7 @@ const cliStart = Effect.try(() => { yargs .positional("envName", { describe: "Network environment to run tests against", - array: true, - string: true, + type: "string", }) .positional("GrepTest", { type: "string", @@ -133,7 +133,7 @@ const cliStart = Effect.try(() => { const effect = Effect.gen(function* (_) { if (envName) { yield* _( - testEffect(envName as any, { testNamePattern: GrepTest }).pipe( + testEffect(envName, { testNamePattern: GrepTest }).pipe( Effect.catchTag("TestsFailedError", (error) => Effect.succeed( console.log(`❌ ${error.fails} test${error.fails !== 1 && "s"} failed`) @@ -148,6 +148,10 @@ const cliStart = Effect.try(() => { }); await Effect.runPromise(effect); + + setTimeout(function () { + log(); // logs out active handles that are keeping node running + }, 10000); } ) .command( @@ -181,11 +185,11 @@ const cli = pipe( ); Effect.runPromise(cli) - .then((res) => { - Console.log(res); + .then(() => { + console.log("🏁 Moonwall Test Run finished"); process.exit(0); }) .catch((defect) => { - Console.error(defect); + console.error(defect); process.exit(1); }); diff --git a/packages/cli/src/internal/providerFactories.ts b/packages/cli/src/internal/providerFactories.ts index 2d177158..76641f2a 100644 --- a/packages/cli/src/internal/providerFactories.ts +++ b/packages/cli/src/internal/providerFactories.ts @@ -7,7 +7,8 @@ import Debug from "debug"; import { Signer, Wallet, ethers } from "ethers"; import { createWalletClient, http, publicActions } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -import { Web3, HttpProvider } from "web3"; +import { Web3 } from "web3"; +import { WebSocketProvider as Web3ProviderWs } from "web3"; const debug = Debug("global:providers"); export class ProviderFactory { @@ -67,8 +68,12 @@ export class ProviderFactory { name: this.providerConfig.name, type: this.providerConfig.type, connect: () => { - const httpProvider = new HttpProvider(this.url.replace("ws", "http")); - return new Web3(httpProvider); + const provider = new Web3ProviderWs( + this.url, + {}, + { delay: 50, autoReconnect: false, maxAttempts: 10 } + ); + return new Web3(provider); }, }; } @@ -251,7 +256,9 @@ export class ProviderInterfaceFactory { `👋 Provider ${this.name} is connected to chain ` + (await api.eth.getChainId()) ), disconnect: () => { - // Not needed until we switch to websockets + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Apparently this exists according to docs? + // api.provider.disconnect(); <--- this is really problematic and halts exit }, }; } @@ -280,6 +287,7 @@ export class ProviderInterfaceFactory { greet: async () => console.log(`👋 Provider ${this.name} is connected to chain ` + (await api.getChainId())), disconnect: () => { + // Not needed until we switch to websockets }, }; } diff --git a/packages/cli/src/lib/globalContextEffect.ts b/packages/cli/src/lib/globalContextEffect.ts index befb6cce..7f933a33 100644 --- a/packages/cli/src/lib/globalContextEffect.ts +++ b/packages/cli/src/lib/globalContextEffect.ts @@ -194,11 +194,6 @@ export class MoonwallContext { const socketPath = `${network.tmpDir}/node-ipc.sock`; const server = net.createServer((client) => { - // client.on("end", () => { - // console.log("📨 IPC client disconnected"); - // }); - - // Client message handling client.on("data", async (data) => { const writeToClient = (message: IPCResponseMessage) => { if (client.writable) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f6454f7..4324b444 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -153,6 +153,9 @@ importers: web3: specifier: 4.2.2 version: 4.2.2(typescript@5.2.2) + why-is-node-running: + specifier: ^2.2.2 + version: 2.2.2 ws: specifier: ^8.14.2 version: 8.14.2