Skip to content

Commit

Permalink
Merge pull request #1557 from matter-labs/node-show-contract-logs
Browse files Browse the repository at this point in the history
feat: show contract logs while running tests and scripts with zksync hardhat node [DO NOT MERGE]
  • Loading branch information
Romsters authored Jan 14, 2025
2 parents 93cd879 + 09236cb commit 28e4ab2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function wrapTaskWithNode(taskArgs: TaskArguments, env: any, runSuper: Run
return await runSuper(taskArgs);
}
const zkSyncGlobal = global as ZKSyncTasksWithWrappedNode;
const { commandArgs, server, port } = await startServer();
const { commandArgs, server, port } = await startServer(undefined, false, { quiet: true });
try {
await server.listen(commandArgs, false);
await waitForNodeToBeReady(port);
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-node/src/core/script-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function runScript(
...extraNodeArgs,
];

const { commandArgs, server, port } = await startServer();
const { commandArgs, server, port } = await startServer(undefined, false, { showNodeConfig: false, showTxSummary: false });
await server.listen(commandArgs, false);
await waitForNodeToBeReady(port);

Expand Down
20 changes: 19 additions & 1 deletion packages/hardhat-zksync-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ task(TASK_NODE, 'Start a ZKSync Node')
undefined,
types.string,
)
.addOptionalParam(
'showEventLogs',
'Show event logs',
)
.addOptionalParam(
'showStorageLogs',
'Show storage log information (none, read, write, all) - default: none',
Expand Down Expand Up @@ -173,6 +177,10 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
undefined,
types.string,
)
.addOptionalParam(
'showEventLogs',
'Show event logs',
)
.addOptionalParam(
'showStorageLogs',
'Show storage log information (none, read, write, all) - default: none',
Expand Down Expand Up @@ -208,6 +216,10 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
.addOptionalParam('forkBlockNumber', 'Fork at the specified block height', undefined, types.int)
.addOptionalParam('replayTx', 'Transaction hash to replay', undefined, types.string)
.addOptionalParam('tag', 'Specified node release for use', undefined)
.addOptionalParam(
'quite',
'Disables logs',
)
// .addFlag('force', 'Force download even if the binary already exists')
.setAction(
async (
Expand All @@ -219,6 +231,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
cacheDir,
resetCache,
showCalls,
showEventLogs,
showStorageLogs,
showVmDetails,
showGasDetails,
Expand All @@ -228,6 +241,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
forkBlockNumber,
replayTx,
tag,
quiet,
}: {
port: number;
log: string;
Expand All @@ -236,6 +250,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
cacheDir: string;
resetCache: boolean;
showCalls: string;
showEventLogs: boolean;
showStorageLogs: string;
showVmDetails: string;
showGasDetails: string;
Expand All @@ -245,6 +260,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
forkBlockNumber: number;
replayTx: string;
tag: string;
quiet: boolean;
},
{ run },
) => {
Expand All @@ -256,6 +272,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
cacheDir,
resetCache,
showCalls,
showEventLogs,
showStorageLogs,
showVmDetails,
showGasDetails,
Expand All @@ -264,6 +281,7 @@ task(TASK_NODE_ZKSYNC, 'Starts a JSON-RPC server for ZKsync node')
fork,
forkBlockNumber,
replayTx,
quiet,
});

// Download the binary
Expand Down Expand Up @@ -335,7 +353,7 @@ task(
const binaryPath: string = await run(TASK_NODE_ZKSYNC_DOWNLOAD_BINARY, { force: false });

const currentPort = await getAvailablePort(START_PORT, MAX_PORT_ATTEMPTS);
const commandArgs = constructCommandArgs({ port: currentPort });
const commandArgs = constructCommandArgs({ port: currentPort, showNodeConfig: false, showTxSummary: false });

const server = new JsonRpcServer(binaryPath);

Expand Down
6 changes: 1 addition & 5 deletions packages/hardhat-zksync-node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export class JsonRpcServer implements RpcServer {
console.info(chalk.green(`Running command: ${command} ${commandArgs.join(' ')}`));
}

let stdioConfig: StdioOptions = 'inherit';
if (!blockProcess) {
stdioConfig = ['ignore', 'ignore', 'ignore'];
}
this.serverProcess = spawn(command, commandArgs, { stdio: stdioConfig });
this.serverProcess = spawn(command, commandArgs, { stdio: 'inherit' });

this.serverProcess.on('error', (error) => {
console.info(chalk.red('Error running the server:', error));
Expand Down
4 changes: 4 additions & 0 deletions packages/hardhat-zksync-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface CommandArguments {
cacheDir?: string;
resetCache?: boolean;
showCalls?: string;
showEventLogs?: boolean;
showStorageLogs?: string;
showVmDetails?: string;
showGasDetails?: string;
Expand All @@ -14,4 +15,7 @@ export interface CommandArguments {
fork?: string;
forkBlockNumber?: number;
replayTx?: string;
showNodeConfig?: boolean;
showTxSummary?: boolean;
quiet?: boolean;
}
20 changes: 18 additions & 2 deletions packages/hardhat-zksync-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ export function constructCommandArgs(args: CommandArguments): string[] {
commandArgs.push(`--resolve-hashes`);
}

if (args.showEventLogs !== undefined) {
commandArgs.push(`--show-event-logs=${args.showEventLogs}`);
}

if (args.showNodeConfig !== undefined) {
commandArgs.push(`--show-node-config=${args.showNodeConfig}`);
}

if (args.showTxSummary !== undefined) {
commandArgs.push(`--show-tx-summary=${args.showTxSummary}`);
}

if (args.quiet) {
commandArgs.push(`--quiet`);
}

if (args.devUseLocalContracts) {
commandArgs.push(`--dev-use-local-contracts`);
}
Expand Down Expand Up @@ -415,7 +431,7 @@ export async function configureNetwork(config: HardhatConfig, network: any, port
network.provider = await createProvider(config, network.name);
}

export const startServer = async (tag?: string, force: boolean = false) => {
export const startServer = async (tag?: string, force: boolean = false, args?: CommandArguments) => {
const platform = getPlatform();
if (platform === 'windows' || platform === '') {
throw new ZkSyncNodePluginError(`Unsupported platform: ${platform}`);
Expand All @@ -428,7 +444,7 @@ export const startServer = async (tag?: string, force: boolean = false) => {
const binaryPath = await downloader.getBinaryPath();

const currentPort = await getAvailablePort(START_PORT, MAX_PORT_ATTEMPTS);
const commandArgs = constructCommandArgs({ port: currentPort });
const commandArgs = constructCommandArgs({ ...args, port: currentPort });

return {
commandArgs,
Expand Down
10 changes: 9 additions & 1 deletion packages/hardhat-zksync-node/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ describe('node-zksync plugin', async function () {
devUseLocalContracts: true,
fork: 'mainnet',
forkBlockNumber: 100,
showEventLogs: true,
showNodeConfig: false,
showTxSummary: false,
quiet: true
};

const result = constructCommandArgs(args);
Expand All @@ -183,11 +187,15 @@ describe('node-zksync plugin', async function () {
'--show-gas-details=all',
'--show-calls=user',
'--resolve-hashes',
"--show-event-logs=true",
"--show-node-config=false",
"--show-tx-summary=false",
"--quiet",
'--dev-use-local-contracts',
'fork',
'mainnet',
'--fork-at',
'100',
'100'
]);
});

Expand Down

0 comments on commit 28e4ab2

Please sign in to comment.