From d3bd6a27a051bc2400dfae839cb8e970a9b4f67d Mon Sep 17 00:00:00 2001 From: Daniel Helm Date: Wed, 21 Aug 2024 15:12:05 -0500 Subject: [PATCH] adjust flags for - over _ and more consistent usage --- src/commands/helper/fund-contracts.ts | 6 +- src/commands/test/contracts.ts | 26 ++++----- src/commands/test/e2e.ts | 81 +++++++++++++-------------- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/commands/helper/fund-contracts.ts b/src/commands/helper/fund-contracts.ts index 04d80af..4a58e91 100644 --- a/src/commands/helper/fund-contracts.ts +++ b/src/commands/helper/fund-contracts.ts @@ -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', @@ -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 diff --git a/src/commands/test/contracts.ts b/src/commands/test/contracts.ts index 70c6f1a..092efd0 100644 --- a/src/commands/test/contracts.ts +++ b/src/commands/test/contracts.ts @@ -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 @@ -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', }), @@ -32,7 +32,7 @@ export default class TestContracts extends Command { } async run(): Promise { - const {flags} = await this.parse(TestContracts) + const { flags } = await this.parse(TestContracts) const configPath = path.resolve(flags.config) const contractsPath = path.resolve(flags.contracts) @@ -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) => { @@ -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 { @@ -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[] = [] @@ -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) @@ -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) { @@ -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 { diff --git a/src/commands/test/e2e.ts b/src/commands/test/e2e.ts index da5c1ef..832d0f0 100644 --- a/src/commands/test/e2e.ts +++ b/src/commands/test/e2e.ts @@ -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, @@ -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.L1]: {blockExplorerURI: ''}, - [Layer.L2]: {blockExplorerURI: ''}, + [Layer.L1]: { blockExplorerURI: '' }, + [Layer.L2]: { blockExplorerURI: '' }, } private bridgeApiUrl!: string @@ -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 @@ -205,11 +205,11 @@ export default class TestE2e extends Command { public async run(): Promise { 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) @@ -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 @@ -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}`) @@ -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, @@ -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) @@ -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') @@ -469,7 +469,7 @@ 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() @@ -477,7 +477,7 @@ export default class TestE2e extends Command { 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, @@ -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) @@ -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', ) @@ -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, @@ -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') } @@ -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.