@@ -18,6 +18,8 @@ import {
1818} from 'viem' ;
1919import { privateKeyToAccount } from 'viem/accounts' ;
2020import { join , dirname } from 'node:path' ;
21+ import { homedir } from 'node:os' ;
22+ import { existsSync } from 'node:fs' ;
2123import { fileURLToPath } from 'node:url' ;
2224import { PAYMENT_CHANNEL_ABI } from '../../src/contracts.js' ;
2325
@@ -26,8 +28,29 @@ const __dirname = dirname(__filename);
2628
2729export const ANVIL_PORT = 8547 ;
2830export const ANVIL_RPC = `http://127.0.0.1:${ ANVIL_PORT } ` ;
29- export const ANVIL_BIN = '/opt/homebrew/bin/anvil' ;
30- export const FORGE_BIN = '/opt/homebrew/bin/forge' ;
31+
32+ function resolveBin ( name : string ) : string {
33+ const envOverride = process . env [ `${ name . toUpperCase ( ) } _BIN` ] ;
34+ if ( envOverride && existsSync ( envOverride ) ) return envOverride ;
35+ try {
36+ const found = execSync ( `command -v ${ name } ` , { encoding : 'utf-8' } ) . trim ( ) ;
37+ if ( found ) return found ;
38+ } catch {
39+ // not on PATH; try well-known locations
40+ }
41+ const candidates = [
42+ `/opt/homebrew/bin/${ name } ` ,
43+ `/usr/local/bin/${ name } ` ,
44+ join ( homedir ( ) , '.foundry' , 'bin' , name ) ,
45+ ] ;
46+ for ( const candidate of candidates ) {
47+ if ( existsSync ( candidate ) ) return candidate ;
48+ }
49+ return name ;
50+ }
51+
52+ export const ANVIL_BIN = resolveBin ( 'anvil' ) ;
53+ export const FORGE_BIN = resolveBin ( 'forge' ) ;
3154export const CONTRACTS_DIR = join ( __dirname , '..' , '..' , '..' , 'contracts' ) ;
3255
3356export const ACCOUNTS = {
0 commit comments