Skip to content

Commit

Permalink
Add --in-docker flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ly0va committed Oct 28, 2020
1 parent ec2251c commit 54c698c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
12 changes: 12 additions & 0 deletions infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command } from 'commander';
import * as utils from '../utils';
import { Wallet } from 'ethers';
import fs from 'fs';
import * as verifyKeys from './verify-keys';
import * as dataRestore from './data-restore';

Expand All @@ -18,6 +19,16 @@ export async function exitProof(...args: string[]) {
await utils.spawn(`cargo run --example generate_exit_proof --release -- ${args.join(' ')}`);
}

export async function catLogs(exitCode?: number) {
utils.allowFailSync(() => {
console.log('\nSERVER LOGS:\n', fs.readFileSync('server.log').toString());
console.log('\nPROVER LOGS:\n', fs.readFileSync('dummy_prover.log').toString());
});
if (exitCode !== undefined) {
process.exit(exitCode);
}
}

export async function testAccounts() {
const NUM_TEST_WALLETS = 10;
const baseWalletPath = "m/44'/60'/0'/0/";
Expand All @@ -44,6 +55,7 @@ export const command = new Command('run')

command.command('test-accounts').description('print ethereum test accounts').action(testAccounts);
command.command('explorer').description('run zksync explorer locally').action(explorer);
command.command('cat-logs').description('print server and prover logs').action(catLogs);

command
.command('revert-reason <tx_hash> [web3_url]')
Expand Down
62 changes: 51 additions & 11 deletions infrastructure/zk/src/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import * as utils from '../utils';
import fs from 'fs';
import * as dummyProver from '../dummy-prover';
import * as contract from '../contract';
import * as run from '../run/run';

export async function withServer<T>(testSuite: () => Promise<T>, timeout: number) {
export async function withServer(testSuite: () => Promise<void>, timeout: number) {
if (!(await dummyProver.status())) {
await dummyProver.enable();
}
Expand All @@ -13,15 +14,15 @@ export async function withServer<T>(testSuite: () => Promise<T>, timeout: number
await utils.spawn('cargo build --bin dummy_prover --release');

const serverLog = fs.openSync('server.log', 'w');
const server = utils.background('cargo run --bin zksync_server --release', ['ignore', serverLog, serverLog]);
const server = utils.background('cargo run --bin zksync_server --release', [0, serverLog, serverLog]);
await utils.sleep(1);

const proverLog = fs.openSync('prover.log', 'w');
const prover = utils.background('cargo run --bin dummy_prover --release dummy-prover-instance', [
'ignore',
proverLog,
proverLog
]);
const proverLog = fs.openSync('dummy_prover.log', 'w');
// prettier-ignore
const prover = utils.background(
'cargo run --bin dummy_prover --release dummy-prover-instance',
[0, proverLog, proverLog]
);
await utils.sleep(10);

const timer = setTimeout(() => {
Expand All @@ -46,16 +47,39 @@ export async function withServer<T>(testSuite: () => Promise<T>, timeout: number
utils.allowFailSync(() => process.kill(-server.pid, 'SIGKILL'));
utils.allowFailSync(() => process.kill(-prover.pid, 'SIGKILL'));
utils.allowFailSync(() => clearTimeout(timer));
console.log('\nSERVER LOGS:\n', fs.readFileSync('server.log').toString());
console.log('\nPROVER LOGS:\n', fs.readFileSync('prover.log').toString());
if (code !== 0) {
run.catLogs();
}
utils.sleepSync(5);
console.log('Exit code:', code);
});

await testSuite();
process.exit(0);
}

export async function inDocker(command: string, timeout: number) {
const timer = setTimeout(() => {
console.log('Timeout reached!');
run.catLogs(1);
}, timeout * 1000);
timer.unref();

const volume = `${process.env.ZKSYNC_HOME}:/usr/src/zksync`;
const image = `matterlabs/ci-integration-test:latest`;
await utils.spawn(
`docker run -v ${volume} ${image} bash -c "/usr/local/bin/entrypoint.sh && ${command} || zk run cat-logs"`
);
}

export async function all() {
await server();
await api();
await zcli();
await rustSDK();
await utils.spawn('killall zksync_server');
await run.dataRestore.checkExisting();
}

export async function api() {
await utils.spawn('yarn --cwd core/tests/ts-tests api-test');
}
Expand Down Expand Up @@ -115,6 +139,22 @@ export async function rustSDK() {

export const command = new Command('integration').description('zksync integration tests').alias('i');

command
.command('all')
.description('run all integration tests (no testkit)')
.option('--with-server')
.option('--in-docker')
.action(async (cmd: Command) => {
const timeout = 1800;
if (cmd.withServer) {
await withServer(all, timeout);
} else if (cmd.inDocker) {
await inDocker('zk test i all', timeout);
} else {
await all();
}
});

command
.command('zcli')
.description('run zcli integration tests')
Expand Down
6 changes: 5 additions & 1 deletion infrastructure/zk/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ export async function js() {

export async function rust() {
await utils.spawn('cargo test --release');
await db(true);
await prover();
const { stdout: threads } = await utils.exec('nproc');
await circuit(parseInt(threads));
}

export const command = new Command('test').description('run test suites').addCommand(integration.command);

command.command('js').description('run unit-tests for javascript packages').action(js);
command.command('prover').description('run unit-tests for the prover').action(prover);
command.command('contracts').description('run unit-tests for the contracts').action(contracts);
command.command('rust').description('run unit-tests for rust binaries').action(rust);
command.command('rust').description('run unit-tests for all rust binaries and libraries').action(rust);

command
.command('db')
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/zk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export type { ChildProcess } from 'child_process';
// returns { stdout, stderr }
const promisified = promisify(_exec);
export function exec(command: string) {
command = command.replace(/\n/g, '');
command = command.replace(/\n/g, ' ');
return promisified(command);
}

// executes a command in a new shell
// but pipes data to parent's stdout/stderr
export function spawn(command: string) {
command = command.replace(/\n/g, '');
command = command.replace(/\n/g, ' ');
const child = _spawn(command, { stdio: 'inherit', shell: true });
return new Promise((resolve, reject) => {
child.on('error', reject);
Expand All @@ -31,7 +31,7 @@ export function spawn(command: string) {
// executes a command in background and returns a child process handle
// by default pipes data to parent's stdio but this can be overriden
export function background(command: string, stdio: any = 'inherit') {
command = command.replace(/\n/g, '');
command = command.replace(/\n/g, ' ');
return _spawn(command, { stdio, shell: true, detached: true });
}

Expand Down

0 comments on commit 54c698c

Please sign in to comment.