Skip to content

Commit

Permalink
adjust flags for - over _ and more consistent usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dghelm committed Aug 21, 2024
1 parent 32facc0 commit d3bd6a2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/commands/helper/fund-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class HelperFundContracts extends Command {
char: 'k',
description: 'Private key for funder wallet',
}),
'config-contracts': Flags.string({
contracts: Flags.string({
char: 'n',
default: './config-contracts.toml',
description: 'Path to config-contracts.toml file',
Expand Down Expand Up @@ -120,8 +120,8 @@ export default class HelperFundContracts extends Command {

if (flags['gateway-address']) {
this.l1ETHGateway = flags['gateway-address']
} else if (flags['config-contracts']) {
const contractsConfigPath = path.resolve(flags['config-contracts'])
} else if (flags.contracts) {
const contractsConfigPath = path.resolve(flags.contracts)
try {
const contractsConfig = parseTomlConfig(contractsConfigPath)
this.l1ETHGateway = contractsConfig?.L1_ETH_GATEWAY_PROXY_ADDR
Expand Down
26 changes: 13 additions & 13 deletions src/commands/test/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Command, Flags} from '@oclif/core'
import { Command, Flags } from '@oclif/core'
import cliProgress from 'cli-progress'
import {ethers} from 'ethers'
import { ethers } from 'ethers'
import path from 'node:path'

import {DeployedContract, L1Contracts, L2Contracts} from '../../data/contracts.js'
import {parseTomlConfig} from '../../utils/config-parser.js'
import { DeployedContract, L1Contracts, L2Contracts } from '../../data/contracts.js'
import { parseTomlConfig } from '../../utils/config-parser.js'

interface ContractsConfig {
[key: string]: string
Expand All @@ -20,7 +20,7 @@ export default class TestContracts extends Command {
description: 'Path to config.toml file',
}),
contracts: Flags.string({
char: 't',
char: 'n',
default: './config-contracts.toml',
description: 'Path to configs-contracts.toml file',
}),
Expand All @@ -32,7 +32,7 @@ export default class TestContracts extends Command {
}

async run(): Promise<void> {
const {flags} = await this.parse(TestContracts)
const { flags } = await this.parse(TestContracts)

const configPath = path.resolve(flags.config)
const contractsPath = path.resolve(flags.contracts)
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class TestContracts extends Command {
this.log(`Missing address for contract: ${contract.name}`)
}

return {...contract, address}
return { ...contract, address }
}).filter((address) => address !== undefined)

const l2Addresses: DeployedContract[] = L2Contracts.map((contract) => {
Expand All @@ -93,7 +93,7 @@ export default class TestContracts extends Command {
this.log(`Missing address for contract: ${contract.name}`)
}

return {...contract, address}
return { ...contract, address }
}).filter((address) => address !== undefined)

try {
Expand All @@ -108,8 +108,8 @@ export default class TestContracts extends Command {
cliProgress.Presets.shades_classic,
)

const l1BarDeploy = multibarDeployment.create(l1Addresses.length, 0, {name: 'Checking L1 contract deployment...'})
const l2BarDeploy = multibarDeployment.create(l2Addresses.length, 0, {name: 'Checking L2 contract deployment...'})
const l1BarDeploy = multibarDeployment.create(l1Addresses.length, 0, { name: 'Checking L1 contract deployment...' })
const l2BarDeploy = multibarDeployment.create(l2Addresses.length, 0, { name: 'Checking L2 contract deployment...' })

const notDeployed: DeployedContract[] = []

Expand Down Expand Up @@ -233,7 +233,7 @@ export default class TestContracts extends Command {
notDeployed: DeployedContract[],
) {
for (const c of contracts) {
progressBar.update({name: `Checking ${c.name}...`})
progressBar.update({ name: `Checking ${c.name}...` })
const code = await provider.getCode(c.address ?? '')
if (code === '0x') {
notDeployed.push(c)
Expand All @@ -250,7 +250,7 @@ export default class TestContracts extends Command {
notInitialized: DeployedContract[],
) {
for (const c of contracts) {
progressBar.update({name: `Checking ${c.name}...`})
progressBar.update({ name: `Checking ${c.name}...` })
try {
const initCount = await provider.getStorage(c?.address || '', 0)
if (Number.parseInt(initCount) > 0) {
Expand All @@ -274,7 +274,7 @@ export default class TestContracts extends Command {
const ownableABI = ['function owner() view returns (address)']

for (const c of contracts) {
progressBar.update({name: `Checking ${c.name}...`})
progressBar.update({ name: `Checking ${c.name}...` })
if (c.owned && c.address) {
const contract = new ethers.Contract(c.address, ownableABI, provider)
try {
Expand Down
81 changes: 40 additions & 41 deletions src/commands/test/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Separator, confirm, select} from '@inquirer/prompts'
import { Separator, confirm, select } from '@inquirer/prompts'
import {
// Args,
Command,
Flags,
} from '@oclif/core'
import chalk from 'chalk'
import {Wallet, ethers} from 'ethers'
import { Wallet, ethers } from 'ethers'
import fs from 'node:fs/promises'
import path from 'node:path'
import ora from 'ora'
import {toString as qrCodeToString} from 'qrcode'
import { toString as qrCodeToString } from 'qrcode'

import {parseTomlConfig} from '../../utils/config-parser.js'
import { parseTomlConfig } from '../../utils/config-parser.js'
import {
BlockExplorerParams,
Withdrawal,
Expand Down Expand Up @@ -93,31 +93,31 @@ export default class TestE2e extends Command {
description: 'Path to config.toml file',
}),
contracts: Flags.string({
char: 't',
char: 'n',
default: './config-contracts.toml',
description: 'Path to configs-contracts.toml file',
}),
// eslint-disable-next-line camelcase
manual_fund: Flags.boolean({char: 'm', description: 'Manually fund the test wallet.'}),
manual: Flags.boolean({ char: 'm', description: 'Manually fund the test wallet.' }),
pod: Flags.boolean({
char: 'p',
default: false,
description: 'Run inside Kubernetes pod',
}),
// eslint-disable-next-line camelcase
private_key: Flags.string({char: 'k', description: 'Private key for funder wallet initialization'}),
'private-key': Flags.string({ char: 'k', description: 'Private key for funder wallet initialization' }),
resume: Flags.boolean({
char: 'r',
default: false,
description: 'Uses e2e_resume.json to continue last run.',
}),
// eslint-disable-next-line camelcase
skip_wallet_generation: Flags.boolean({char: 's', description: 'Manually fund the test wallet.'}),
'skip-wallet-generation': Flags.boolean({ char: 's', description: 'Manually fund the test wallet.' }),
}

private blockExplorers: Record<Layer, BlockExplorerParams> = {
[Layer.L1]: {blockExplorerURI: ''},
[Layer.L2]: {blockExplorerURI: ''},
[Layer.L1]: { blockExplorerURI: '' },
[Layer.L2]: { blockExplorerURI: '' },
}

private bridgeApiUrl!: string
Expand Down Expand Up @@ -185,17 +185,17 @@ export default class TestE2e extends Command {
complete: boolean
}
} = {
bridgeERC20L1ToL2: {complete: false},
bridgeERC20L2ToL1: {complete: false},
bridgeFundsL1ToL2: {complete: false},
bridgeFundsL2ToL1: {complete: false},
claimERC20OnL1: {complete: false},
claimETHOnL1: {complete: false},
deployERC20OnL1: {complete: false},
deployERC20OnL2: {complete: false},
fundWalletOnL1: {complete: false},
fundWalletOnL2: {complete: false},
}
bridgeERC20L1ToL2: { complete: false },
bridgeERC20L2ToL1: { complete: false },
bridgeFundsL1ToL2: { complete: false },
bridgeFundsL2ToL1: { complete: false },
claimERC20OnL1: { complete: false },
claimETHOnL1: { complete: false },
deployERC20OnL1: { complete: false },
deployERC20OnL2: { complete: false },
fundWalletOnL1: { complete: false },
fundWalletOnL2: { complete: false },
}

private resumeFilePath: string | undefined

Expand All @@ -205,11 +205,11 @@ export default class TestE2e extends Command {

public async run(): Promise<void> {
try {
const {flags} = await this.parse(TestE2e)
const { flags } = await this.parse(TestE2e)

const configPath = path.resolve(flags.config)
const contractsPath = path.resolve(flags.contracts)
this.manualFunding = flags.manual_fund
this.manualFunding = flags.manual

const config = parseTomlConfig(configPath)
const contractsConfig: ContractsConfig = parseTomlConfig(contractsPath)
Expand Down Expand Up @@ -250,7 +250,7 @@ export default class TestE2e extends Command {

this.l1Rpc = l1RpcUrl
this.l2Rpc = l2RpcUrl
this.skipWalletGen = flags.skip_wallet_generation
this.skipWalletGen = flags['skip-wallet-generation']
this.l1ETHGateway = contractsConfig.L1_ETH_GATEWAY_PROXY_ADDR
this.l2ETHGateway = contractsConfig.L2_ETH_GATEWAY_PROXY_ADDR
this.l1GatewayRouter = contractsConfig.L1_GATEWAY_ROUTER_PROXY_ADDR
Expand All @@ -265,14 +265,14 @@ export default class TestE2e extends Command {
this.l1Provider = new ethers.JsonRpcProvider(l1RpcUrl)
this.l2Provider = new ethers.JsonRpcProvider(l2RpcUrl)

if (flags.skip_wallet_generation) {
this.wallet = new ethers.Wallet(flags.private_key ?? config.accounts.DEPLOYER_PRIVATE_KEY)
if (this.skipWalletGen) {
this.wallet = new ethers.Wallet(flags['private-key'] ?? config.accounts.DEPLOYER_PRIVATE_KEY)
this.results.fundWalletOnL1.walletAddress = this.wallet.address
this.logResult(`Skipping wallet generation, using: ${this.wallet.address}`)
} else if (flags.private_key) {
this.fundingWallet = new ethers.Wallet(flags.private_key, this.l1Provider)
} else if (flags['private-key']) {
this.fundingWallet = new ethers.Wallet(flags['private-key'], this.l1Provider)
this.logResult(`Funding Wallet: ${this.fundingWallet.address}`)
} else if (config.accounts.DEPLOYER_PRIVATE_KEY && !flags.manual_fund) {
} else if (config.accounts.DEPLOYER_PRIVATE_KEY && !flags.manual) {
this.logResult('No funding source found. Using DEPLOYER_PRIVATE_KEY.')
this.fundingWallet = new ethers.Wallet(config.accounts.DEPLOYER_PRIVATE_KEY, this.l1Provider)
this.logResult(`Funding Wallet: ${this.fundingWallet.address}`)
Expand Down Expand Up @@ -355,7 +355,7 @@ export default class TestE2e extends Command {

// Get L2TokenAddress from L1 Contract Address
const l2TokenAddress = await getL2TokenFromL1Address(erc20Address, this.l1Rpc, this.l1GatewayRouter)
const {l2TxHash, queueIndex} = await getCrossDomainMessageFromTx(
const { l2TxHash, queueIndex } = await getCrossDomainMessageFromTx(
depositTx.hash,
this.l1Rpc,
this.l1MessegeQueueProxyAddress,
Expand Down Expand Up @@ -390,7 +390,7 @@ export default class TestE2e extends Command {
throw new Error('ERC20 address not found. Make sure deployERC20OnL1 was successful.')
}

this.log(JSON.stringify({erc20Address, rpc: this.l2Rpc, wallet: this.wallet.address}))
this.log(JSON.stringify({ erc20Address, rpc: this.l2Rpc, wallet: this.wallet.address }))

const balance = await awaitERC20Balance(this.wallet.address, erc20Address, this.l2Rpc)

Expand Down Expand Up @@ -436,7 +436,7 @@ export default class TestE2e extends Command {
)

// Call withdrawERC20
const withdrawTx = await l2GatewayRouter.withdrawERC20(erc20Address, halfBalance, 0, {value: 0})
const withdrawTx = await l2GatewayRouter.withdrawERC20(erc20Address, halfBalance, 0, { value: 0 })
await withdrawTx.wait()

this.logResult(`Withdrawal transaction sent: ${withdrawTx.hash}`, 'success')
Expand Down Expand Up @@ -469,15 +469,15 @@ export default class TestE2e extends Command {
// const value = amount + ethers.parseEther(`${gasLimit*l2BaseFee} wei`);
await this.logAddress(await l1ETHGateway.getAddress(), `Depositing ${amount} by sending ${value} to`, Layer.L1)

const tx = await l1ETHGateway.depositETH(amount, gasLimit, {value})
const tx = await l1ETHGateway.depositETH(amount, gasLimit, { value })

await this.logTx(tx.hash, 'Transaction sent', Layer.L1)
const receipt = await tx.wait()
const blockNumber = receipt?.blockNumber

this.logResult(`Transaction mined in block: ${chalk.cyan(blockNumber)}`, 'success')

const {l2TxHash, queueIndex} = await getCrossDomainMessageFromTx(
const { l2TxHash, queueIndex } = await getCrossDomainMessageFromTx(
tx.hash,
this.l1Rpc,
this.l1MessegeQueueProxyAddress,
Expand Down Expand Up @@ -511,7 +511,7 @@ export default class TestE2e extends Command {
// const value = amount + ethers.parseEther(`${gasLimit*l2BaseFee} wei`);
await this.logAddress(await l2ETHGateway.getAddress(), `Withdrawing ${amount} by sending ${value} to`, Layer.L2)

const tx = await l2ETHGateway.withdrawETH(amount, 0, {value})
const tx = await l2ETHGateway.withdrawETH(amount, 0, { value })
this.results.bridgeFundsL2ToL1.l2WithdrawTx = tx.hash

await this.logTx(tx.hash, 'Transaction sent', Layer.L2)
Expand Down Expand Up @@ -726,8 +726,7 @@ export default class TestE2e extends Command {
withdrawals = await getWithdrawals(this.wallet.address, this.bridgeApiUrl)
} catch (error) {
this.logResult(
`Warning: Failed to get withdrawals. Continuing... Error: ${
error instanceof Error ? error.message : 'Unknown error'
`Warning: Failed to get withdrawals. Continuing... Error: ${error instanceof Error ? error.message : 'Unknown error'
}`,
'warning',
)
Expand Down Expand Up @@ -782,7 +781,7 @@ export default class TestE2e extends Command {
// const value = amount + ethers.parseEther(`${gasLimit*l2BaseFee} wei`);
await this.logAddress(await l1Messenger.getAddress(), `Calling relayMessageWithProof on`, Layer.L1)

const {from, message, nonce, proof, to, value} = unclaimedWithdrawal.claim_info
const { from, message, nonce, proof, to, value } = unclaimedWithdrawal.claim_info

const tx = await l1Messenger.relayMessageWithProof(from, to, value, nonce, message, {
batchIndex: proof.batch_index,
Expand Down Expand Up @@ -872,7 +871,7 @@ export default class TestE2e extends Command {

this.wallet = new ethers.Wallet(privateKey, this.l1Provider)
await this.logAddress(this.wallet.address, 'Generated new wallet', Layer.L1)
this.results.fundWalletOnL1 = {complete: false, generatedPrivateKey: privateKey, walletAddress: this.wallet.address}
this.results.fundWalletOnL1 = { complete: false, generatedPrivateKey: privateKey, walletAddress: this.wallet.address }
this.logResult(`Private Key: ${chalk.yellow(this.wallet.privateKey)}`, 'warning')
}

Expand Down Expand Up @@ -1010,13 +1009,13 @@ export default class TestE2e extends Command {
this.log('\n')
this.logResult('Scan this QR code to fund the address:', 'info')

this.log(await qrCodeToString(qrString, {small: true, type: 'terminal'}))
this.log(await qrCodeToString(qrString, { small: true, type: 'terminal' }))

let funded = false

while (!funded) {
// eslint-disable-next-line no-await-in-loop
await confirm({message: 'Press Enter when ready...'})
await confirm({ message: 'Press Enter when ready...' })

this.logResult(`Checking...`, 'info')
// Check if wallet is actually funded -- if not, we'll loop.
Expand Down

0 comments on commit d3bd6a2

Please sign in to comment.