Skip to content

Commit

Permalink
Merge pull request #20 from matter-labs/fix-revert-test
Browse files Browse the repository at this point in the history
test: fix revert test flakiness
  • Loading branch information
perekopskiy authored Nov 28, 2024
2 parents f4cbcca + 62c776e commit 515f1d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions core/tests/revert-test/tests/revert-and-restart-en.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { assert, expect } from 'chai';
import fs from 'node:fs/promises';
import * as child_process from 'child_process';
import * as dotenv from 'dotenv';
import { loadConfig, replaceAggregatedBlockExecuteDeadline, shouldLoadConfigFromFile } from 'utils/build/file-configs';
import {
loadConfig,
replaceL1BatchMinAgeBeforeExecuteSeconds,
shouldLoadConfigFromFile
} from 'utils/build/file-configs';
import path from 'path';
import { logsTestPath } from 'utils/build/logs';
import { IZkSyncHyperchain, IZkSyncHyperchain__factory } from 'zksync-ethers/build/typechain';
Expand Down Expand Up @@ -288,7 +292,7 @@ describe('Block reverting test', function () {
await extNode.terminate();

if (fileConfig.loadFromFile) {
replaceAggregatedBlockExecuteDeadline(pathToHome, fileConfig, 10);
replaceL1BatchMinAgeBeforeExecuteSeconds(pathToHome, fileConfig, 0);
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions core/tests/revert-test/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { exec as _exec, spawn as _spawn, ChildProcessWithoutNullStreams, type ProcessEnvOptions } from 'child_process';
import { promisify } from 'util';
import { assert, expect } from 'chai';
import { FileConfig, getAllConfigsPath, replaceAggregatedBlockExecuteDeadline } from 'utils/build/file-configs';
import { FileConfig, getAllConfigsPath, replaceL1BatchMinAgeBeforeExecuteSeconds } from 'utils/build/file-configs';
import { IZkSyncHyperchain } from 'zksync-ethers/build/typechain';
import { Tester } from './tester';
import { killPidWithAllChilds } from 'utils/build/kill';
Expand Down Expand Up @@ -313,14 +313,14 @@ export class NodeSpawner {

public async spawnMainNode(enableExecute: boolean): Promise<Node<NodeType.MAIN>> {
const env = this.env ?? process.env;
env.ETH_SENDER_SENDER_AGGREGATED_BLOCK_EXECUTE_DEADLINE = enableExecute ? '1' : '10000';
env.ETH_SENDER_SENDER_L1_BATCH_MIN_AGE_BEFORE_EXECUTE_SECONDS = enableExecute ? '0' : '10000';
// Set full mode for the Merkle tree as it is required to get blocks committed.
env.DATABASE_MERKLE_TREE_MODE = 'full';

const { fileConfig, pathToHome, options, logs } = this;

if (fileConfig.loadFromFile) {
replaceAggregatedBlockExecuteDeadline(pathToHome, fileConfig, enableExecute ? 1 : 10000);
replaceL1BatchMinAgeBeforeExecuteSeconds(pathToHome, fileConfig, enableExecute ? 0 : 10000);
}

let components = 'api,tree,eth,state_keeper,commitment_generator,da_dispatcher,vm_runner_protective_reads';
Expand Down
15 changes: 10 additions & 5 deletions etc/utils/src/file-configs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as fs from 'fs';
import * as yaml from 'yaml';
import fsSync from 'fs';

export type FileConfig = { loadFromFile: false; chain?: undefined } | { loadFromFile: true; chain: string };

Expand Down Expand Up @@ -129,11 +130,15 @@ export function getConfigsFolderPath({
return path.join(pathToHome, 'chains', chain, configsFolder ?? 'configs', configsFolderSuffix ?? '');
}

export function replaceAggregatedBlockExecuteDeadline(pathToHome: string, fileConfig: any, value: number) {
export function replaceL1BatchMinAgeBeforeExecuteSeconds(pathToHome: string, fileConfig: any, value: number) {
const generalConfigPath = getConfigPath({ pathToHome, chain: fileConfig.chain, config: 'general.yaml' });
const generalConfig = fs.readFileSync(generalConfigPath, 'utf8');
const regex = /aggregated_block_execute_deadline:\s*\d+/g;
const newGeneralConfig = generalConfig.replace(regex, `aggregated_block_execute_deadline: ${value}`);

const generalConfig = fsSync.readFileSync(generalConfigPath, 'utf8');
const generalConfigObject = yaml.parse(generalConfig);
if (value == 0) {
delete generalConfigObject['eth']['sender']['l1_batch_min_age_before_execute_seconds'];
} else {
generalConfigObject['eth']['sender']['l1_batch_min_age_before_execute_seconds'] = value;
}
const newGeneralConfig = yaml.stringify(generalConfigObject);
fs.writeFileSync(generalConfigPath, newGeneralConfig, 'utf8');
}

0 comments on commit 515f1d0

Please sign in to comment.