Skip to content

Commit

Permalink
simplify how env is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Dec 12, 2024
1 parent 9030353 commit c58abd3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/scripts/deployStandard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { instantiateBridge } from './instantiate_bridge'
import * as dotenv from 'dotenv'
import { loadEnv } from '../src/lib/utils/env'
import args from './getCLargs'
import { constants, BigNumber, utils } from 'ethers'
import { MultiCaller } from '../src'
import axios from 'axios'
import prompt from 'prompts'
import * as path from 'path'
dotenv.config({ path: path.resolve(__dirname, '../../../.env') })

loadEnv()

const privKey = process.env.PRIVKEY as string
if (!privKey) {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/scripts/genNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as dotenv from 'dotenv'
import * as path from 'path'
dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
import { loadEnv } from '../src/lib/utils/env'
import { execSync } from 'child_process'
import * as fs from 'fs'

Expand All @@ -12,6 +10,8 @@ import {
mapL2NetworkToArbitrumNetwork,
} from '../src/lib/dataEntities/networks'

loadEnv()

const isTestingOrbitChains = process.env.ORBIT_TEST === '1'

function getLocalNetworksFromContainer(which: 'l1l2' | 'l2l3'): any {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/scripts/instantiate_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import { JsonRpcProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'
import { loadEnv } from '../src/lib/utils/env'

import * as dotenv from 'dotenv'
import args from './getCLargs'
import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
Expand All @@ -29,7 +29,7 @@ import {
import { Signer } from 'ethers'
import { AdminErc20Bridger } from '../src/lib/assetBridger/erc20Bridger'

dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
loadEnv()

const arbKey = process.env['ARB_KEY'] as string
const ethKey = process.env['ETH_KEY'] as string
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/scripts/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { JsonRpcProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'
import { Provider } from '@ethersproject/abstract-provider'
import * as dotenv from 'dotenv'
import { loadEnv } from '../src/lib/utils/env'

import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
Expand All @@ -41,7 +41,7 @@ import {
} from '../tests/integration/custom-fee-token/customFeeTokenTestHelpers'
import { fundParentSigner } from '../tests/integration/testHelpers'

dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
loadEnv()

const isTestingOrbitChains = process.env.ORBIT_TEST === '1'

Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/lib/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as dotenv from 'dotenv'
import * as path from 'path'

export const loadEnv = () => {
dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import { expect } from 'chai'
import { ethers, constants, Wallet } from 'ethers'
import * as dotenv from 'dotenv'
import * as path from 'path'
import { loadEnv } from '../../../src/lib/utils/env'

import { parseEther, parseUnits } from '@ethersproject/units'

Expand All @@ -35,7 +34,7 @@ import { ChildToParentMessageStatus } from '../../../src'
import { ChildToParentMessage } from '../../../src/lib/message/ChildToParentMessage'
import { getNativeTokenDecimals } from '../../../src/lib/utils/lib'

dotenv.config({ path: path.resolve(__dirname, '../../../../.env') })
loadEnv()

describeOnlyWhenCustomGasToken(
'EthBridger (with custom fee token)',
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/tests/integration/eth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
'use strict'

import { expect } from 'chai'
import * as dotenv from 'dotenv'
import * as path from 'path'

import { loadEnv } from '../../src/lib/utils/env'
import { Wallet } from '@ethersproject/wallet'
import { parseEther } from '@ethersproject/units'
import { constants } from 'ethers'
Expand All @@ -45,7 +43,7 @@ import {
} from '../../src/lib/utils/lib'
import { parseUnits } from 'ethers/lib/utils'

dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
loadEnv()

describe('Ether', async () => {
beforeEach('skipIfMainnet', async function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as path from 'path'
import * as dotenv from 'dotenv'
import { JsonRpcProvider } from '@ethersproject/providers'
import { constants } from 'ethers'
import { expect } from 'chai'
import { loadEnv } from '../../src/lib/utils/env'

import {
getArbitrumNetwork,
getArbitrumNetworkInformationFromRollup,
} from '../../src/lib/dataEntities/networks'

dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
loadEnv()

describe('getArbitrumNetworkInformationFromRollup', () => {
it('fetches information about arbitrum one', async () => {
Expand Down

0 comments on commit c58abd3

Please sign in to comment.