From 4bc4cf51426ca077baa8ebe00cb80e771e6ba1fc Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 6 Feb 2026 19:23:48 +0000 Subject: [PATCH] chore: migrate app/util/test/ganache.js to TypeScript Co-Authored-By: shayan@cognition.ai --- app/util/test/{ganache.js => ganache.ts} | 40 ++++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) rename app/util/test/{ganache.js => ganache.ts} (53%) diff --git a/app/util/test/ganache.js b/app/util/test/ganache.ts similarity index 53% rename from app/util/test/ganache.js rename to app/util/test/ganache.ts index 7a45fa35aefb..7ba65520a4b8 100644 --- a/app/util/test/ganache.js +++ b/app/util/test/ganache.ts @@ -1,9 +1,19 @@ import { getGanachePort } from '../../../e2e/fixtures/utils'; -import ganache from 'ganache'; +import ganache, { Server, ServerOptions, EthereumProvider } from 'ganache'; export const DEFAULT_GANACHE_PORT = 8545; -const defaultOptions = { +interface GanacheOptions extends ServerOptions { + mnemonic: string; + blockTime?: number; + network_id?: number; + port?: number; + vmErrorsOnRPCResponse?: boolean; + hardfork?: string; + quiet?: boolean; +} + +const defaultOptions: Omit = { blockTime: 2, network_id: 1337, port: DEFAULT_GANACHE_PORT, @@ -13,7 +23,9 @@ const defaultOptions = { }; export default class Ganache { - async start(opts) { + private _server: Server | undefined; + + async start(opts: GanacheOptions): Promise { if (!opts.mnemonic) { throw new Error('Missing required mnemonic'); } @@ -28,24 +40,32 @@ export default class Ganache { } } - getProvider() { + getProvider(): EthereumProvider | undefined { return this._server?.provider; } - async getAccounts() { - return await this.getProvider().request({ + async getAccounts(): Promise { + const provider = this.getProvider(); + if (!provider) { + throw new Error('Provider not available'); + } + return await provider.request({ method: 'eth_accounts', params: [], }); } - async getBalance() { + async getBalance(): Promise { const accounts = await this.getAccounts(); - const balanceHex = await this.getProvider().request({ + const provider = this.getProvider(); + if (!provider) { + throw new Error('Provider not available'); + } + const balanceHex = await provider.request({ method: 'eth_getBalance', params: [accounts[0], 'latest'], }); - const balanceInt = parseInt(balanceHex, 16) / 10 ** 18; + const balanceInt = parseInt(balanceHex as string, 16) / 10 ** 18; const balanceFormatted = balanceInt % 1 === 0 ? balanceInt : balanceInt.toFixed(4); @@ -53,7 +73,7 @@ export default class Ganache { return balanceFormatted; } - async quit() { + async quit(): Promise { if (!this._server) { throw new Error('Server not running yet'); }