UNPKG

@lit-protocol/e2e

Version:

Lit Protocol E2E testing package for running comprehensive integration tests

100 lines 3.76 kB
export const SUPPORTED_NETWORKS = [ 'naga-local', 'naga-test', 'naga-dev', 'naga-staging', 'naga-proto', 'naga', ]; const RPC_ENV_KEY_BY_NETWORK = { 'naga-local': undefined, 'naga-dev': 'LIT_YELLOWSTONE_PRIVATE_RPC_URL', 'naga-test': 'LIT_YELLOWSTONE_PRIVATE_RPC_URL', 'naga-staging': 'LIT_YELLOWSTONE_PRIVATE_RPC_URL', 'naga-proto': 'LIT_MAINNET_RPC_URL', naga: 'LIT_MAINNET_RPC_URL', }; // -- configure const testEnv = { local: { type: 'local', key: 'LOCAL_MASTER_ACCOUNT' }, live: { type: 'live', key: 'LIVE_MASTER_ACCOUNT' }, }; const LIVE_MASTER_ACCOUNT_BY_NETWORK = { naga: 'LIVE_MASTER_ACCOUNT_NAGA', 'naga-dev': 'LIVE_MASTER_ACCOUNT_NAGA_DEV', 'naga-test': 'LIVE_MASTER_ACCOUNT_NAGA_TEST', 'naga-staging': 'LIVE_MASTER_ACCOUNT_NAGA_STAGING', }; export function createEnvVars() { // 1. Get network string const networkEnv = process.env['NETWORK']; if (!networkEnv || !SUPPORTED_NETWORKS.includes(networkEnv)) { throw new Error(`❌ NETWORK env var is not set or not supported. Found. ${networkEnv}`); } const network = networkEnv; const selectedNetwork = network.includes('local') ? 'local' : 'live'; // 2. Get private key let privateKey; if (network.includes('local')) { Object.assign(testEnv.local, { type: 'local' }); privateKey = process.env[testEnv.local.key]; } else { Object.assign(testEnv.live, { type: 'live' }); const overrideKey = LIVE_MASTER_ACCOUNT_BY_NETWORK[network]; const liveKey = overrideKey && process.env[overrideKey] ? overrideKey : testEnv.live.key; privateKey = process.env[liveKey]; } if (!privateKey) { const expectedKey = selectedNetwork === 'local' ? 'LOCAL_MASTER_ACCOUNT' : LIVE_MASTER_ACCOUNT_BY_NETWORK[network] ? `${LIVE_MASTER_ACCOUNT_BY_NETWORK[network]} or LIVE_MASTER_ACCOUNT` : 'LIVE_MASTER_ACCOUNT'; throw new Error(`❌ You are on "${selectedNetwork}" environment, network ${network}. We are expecting ${expectedKey} to be set.`); } // 3. Get RPC URL let rpcUrl; let localContextPath; // -- local network if (network === 'naga-local') { localContextPath = process.env['NAGA_LOCAL_CONTEXT_PATH']; const localRpcUrl = process.env['LOCAL_RPC_URL']; const defaultRpcUrl = 'http://127.0.0.1:8545'; if (!localContextPath) { throw new Error(`NAGA_LOCAL_CONTEXT_PATH is not set for naga-local network. Received ${localContextPath}`); } if (!localRpcUrl) { console.error(`⚠️ LOCAL_RPC_URL is not set for naga-local network. Default to ${defaultRpcUrl}`); } rpcUrl = localRpcUrl || defaultRpcUrl; } // -- live networks const rpcEnvKey = RPC_ENV_KEY_BY_NETWORK[network]; if (rpcEnvKey) { console.log(`ℹ️ Checking override env var ${rpcEnvKey} for network ${network}`); const liveRpcUrl = process.env[rpcEnvKey]; if (liveRpcUrl) { rpcUrl = liveRpcUrl; console.log(`🔧 Using RPC override (${rpcEnvKey}) for ${network}`); } else { console.log(`ℹ️ No RPC override provided via ${rpcEnvKey}; using module default for ${network}`); } } const result = { network, privateKey, rpcUrl, localContextPath, }; const clone = Object.freeze({ ...result, privateKey: (privateKey.slice(0, 6) + '...'), }); console.log('✅ Env Vars:', clone); console.log("When RPC URL is undefined, module's default RPC will be used."); return result; } //# sourceMappingURL=createEnvVars.js.map