Skip to content

Commit

Permalink
Fix CLI dry run flag handling (#3698)
Browse files Browse the repository at this point in the history
### Description

- Fix dry run flag
- Prevent invalid selection in warp config create
- Improve logging of warp validation errors
- Avoid module-scoped logger in SDK
  • Loading branch information
jmrossy authored May 3, 2024
1 parent 8246f14 commit bd6ca01
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion typescript/cli/src/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const dryRunOption: Options = {
type: 'string',
description:
'Chain name to fork and simulate deployment. Please ensure an anvil node instance is running during execution via `anvil`.',
alias: ['d'],
alias: 'd',
};

export const chainCommandOption: Options = {
Expand Down
8 changes: 7 additions & 1 deletion typescript/cli/src/config/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { confirm, input } from '@inquirer/prompts';
import { ethers } from 'ethers';

import {
ChainMetadata,
TokenType,
WarpCoreConfig,
WarpCoreConfigSchema,
WarpRouteDeployConfig,
WarpRouteDeployConfigSchema,
} from '@hyperlane-xyz/sdk';
import { objFilter } from '@hyperlane-xyz/utils';

import { CommandContext } from '../context/types.js';
import { errorRed, logBlue, logGreen } from '../logger.js';
Expand Down Expand Up @@ -66,8 +68,12 @@ export async function createWarpRouteDeployConfig({
? ethers.constants.AddressZero
: await input({ message: addressMessage });

const syntheticChains = await runMultiChainSelectionStep(
const metadataWithoutBase = objFilter(
context.chainMetadata,
(chain, _): _ is ChainMetadata => chain !== baseChain,
);
const syntheticChains = await runMultiChainSelectionStep(
metadataWithoutBase,
'Select chains to which the base token will be connected',
);

Expand Down
6 changes: 5 additions & 1 deletion typescript/cli/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { ethers } from 'ethers';

import { IRegistry } from '@hyperlane-xyz/registry';
import { ChainName, MultiProvider } from '@hyperlane-xyz/sdk';
import { isNullish } from '@hyperlane-xyz/utils';

import { isSignCommand } from '../commands/signCommands.js';
import { forkNetworkToMultiProvider } from '../deploy/dry-run.js';
import { logBlue } from '../logger.js';
import { MergedRegistry } from '../registry/MergedRegistry.js';
import { runSingleChainSelectionStep } from '../utils/chains.js';
import { getImpersonatedSigner, getSigner } from '../utils/keys.js';
Expand All @@ -16,7 +18,7 @@ import {
} from './types.js';

export async function contextMiddleware(argv: Record<string, any>) {
const isDryRun = !!argv.dryRun;
const isDryRun = !isNullish(argv.dryRun);
const requiresKey = isSignCommand(argv);
const settings: ContextSettings = {
registryUri: argv.registry,
Expand Down Expand Up @@ -79,6 +81,8 @@ export async function getDryRunContext(
);
}

logBlue(`Dry-running against chain: ${chain}`);

const multiProvider = await getMultiProvider(registry);
await forkNetworkToMultiProvider(multiProvider, chain);
const { key: impersonatedKey, signer: impersonatedSigner } =
Expand Down
2 changes: 1 addition & 1 deletion typescript/cli/src/send/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async function executeDelivery({
sender: senderAddress,
});
if (errors) {
logRed('Unable to validate transfer', errors);
logRed('Error validating transfer', JSON.stringify(errors));
throw new Error('Error validating transfer');
}

Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function runSingleChainSelectionStep(
const chain = (await select({
message,
choices,
pageSize: 20,
pageSize: 30,
})) as string;
handleNewChain([chain]);
return chain;
Expand All @@ -35,7 +35,7 @@ export async function runMultiChainSelectionStep(
const chains = (await checkbox({
message,
choices,
pageSize: 20,
pageSize: 30,
})) as string[];
handleNewChain(chains);
if (requireMultiple && chains?.length < 2) {
Expand Down
20 changes: 9 additions & 11 deletions typescript/sdk/src/utils/fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Address, isValidAddressEvm, rootLogger } from '@hyperlane-xyz/utils';
import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainName } from '../types.js';

const logger = rootLogger.child({ module: 'fork-utils' });

const ENDPOINT_PREFIX = 'http';
const DEFAULT_ANVIL_ENDPOINT = 'http://127.0.0.1:8545';

Expand All @@ -21,7 +19,7 @@ export enum ANVIL_RPC_METHODS {
* Resets the local node to it's original state (anvil [31337] at block zero).
*/
export const resetFork = async (anvilIPAddr?: string, anvilPort?: number) => {
logger.info(`Resetting forked network...`);
rootLogger.info(`Resetting forked network...`);

const provider = getLocalProvider(anvilIPAddr, anvilPort);
await provider.send(ANVIL_RPC_METHODS.RESET, [
Expand All @@ -32,7 +30,7 @@ export const resetFork = async (anvilIPAddr?: string, anvilPort?: number) => {
},
]);

logger.info(`✅ Successfully reset forked network`);
rootLogger.info(`✅ Successfully reset forked network`);
};

/**
Expand All @@ -46,7 +44,7 @@ export const setFork = async (
anvilIPAddr?: string,
anvilPort?: number,
) => {
logger.info(`Forking ${chain} for dry-run...`);
rootLogger.info(`Forking ${chain} for dry-run...`);

const provider = getLocalProvider(anvilIPAddr, anvilPort);
const currentChainMetadata = multiProvider.metadata[chain];
Expand All @@ -61,7 +59,7 @@ export const setFork = async (

multiProvider.setProvider(chain, provider);

logger.info(`✅ Successfully forked ${chain} for dry-run`);
rootLogger.info(`✅ Successfully forked ${chain} for dry-run`);
};

/**
Expand All @@ -74,12 +72,12 @@ export const impersonateAccount = async (
anvilIPAddr?: string,
anvilPort?: number,
): Promise<providers.JsonRpcSigner> => {
logger.info(`Impersonating account (${address})...`);
rootLogger.info(`Impersonating account (${address})...`);

const provider = getLocalProvider(anvilIPAddr, anvilPort);
await provider.send(ANVIL_RPC_METHODS.IMPERSONATE_ACCOUNT, [address]);

logger.info(`✅ Successfully impersonated account (${address})`);
rootLogger.info(`✅ Successfully impersonated account (${address})`);

return provider.getSigner(address);
};
Expand All @@ -93,7 +91,7 @@ export const stopImpersonatingAccount = async (
anvilIPAddr?: string,
anvilPort?: number,
) => {
logger.info(`Stopping account impersonation for address (${address})...`);
rootLogger.info(`Stopping account impersonation for address (${address})...`);

if (isValidAddressEvm(address))
throw new Error(
Expand All @@ -105,7 +103,7 @@ export const stopImpersonatingAccount = async (
address.substring(2),
]);

logger.info(
rootLogger.info(
`✅ Successfully stopped account impersonation for address (${address})`,
);
};
Expand All @@ -125,7 +123,7 @@ export const getLocalProvider = (
envUrl = `${ENDPOINT_PREFIX}${anvilIPAddr}:${anvilPort}`;

if (urlOverride && !urlOverride.startsWith(ENDPOINT_PREFIX)) {
logger.warn(
rootLogger.warn(
`⚠️ Provided URL override (${urlOverride}) does not begin with ${ENDPOINT_PREFIX}. Defaulting to ${
envUrl ?? DEFAULT_ANVIL_ENDPOINT
}`,
Expand Down

0 comments on commit bd6ca01

Please sign in to comment.