Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions certora/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
// node certora/run.js AccessControl
// node certora/run.js AccessControlHarness:AccessControl

const proc = require('child_process');
const { PassThrough } = require('stream');
const events = require('events');

const argv = require('yargs')
import { spawn } from 'child_process';
import { PassThrough } from 'stream';
import { once } from 'events';
import path from 'path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import pLimit from 'p-limit';
import fs from 'fs/promises';

const argv = yargs(hideBin(process.argv))
.env('')
.options({
all: {
Expand All @@ -21,7 +26,7 @@ const argv = require('yargs')
spec: {
alias: 's',
type: 'string',
default: __dirname + '/specs.json',
default: path.resolve(import.meta.dirname, 'specs.json'),
},
parallel: {
alias: 'p',
Expand All @@ -38,18 +43,20 @@ const argv = require('yargs')
type: 'array',
default: [],
},
}).argv;
})
.parse();

function match(entry, request) {
const [reqSpec, reqContract] = request.split(':').reverse();
return entry.spec == reqSpec && (!reqContract || entry.contract == reqContract);
}

const specs = require(argv.spec).filter(s => argv.all || argv._.some(r => match(s, r)));
const limit = require('p-limit')(argv.parallel);
const specs = JSON.parse(fs.readFileSync(argv.spec, 'utf8')).filter(s => argv.all || argv._.some(r => match(s, r)));

const limit = pLimit(argv.parallel);

if (argv._.length == 0 && !argv.all) {
console.error(`Warning: No specs requested. Did you forgot to toggle '--all'?`);
console.error(`Warning: No specs requested. Did you forget to toggle '--all'?`);
}

for (const r of argv._) {
Expand All @@ -64,12 +71,13 @@ if (process.exitCode) {
}

for (const { spec, contract, files, options = [] } of specs) {
limit(
runCertora,
spec,
contract,
files,
[...options, ...argv.options].flatMap(opt => opt.split(' ')),
limit(() =>
runCertora(
spec,
contract,
files,
[...options, ...argv.options].flatMap(opt => opt.split(' ')),
),
);
}

Expand All @@ -79,7 +87,7 @@ async function runCertora(spec, contract, files, options = []) {
if (argv.verbose) {
console.log('Running:', args.join(' '));
}
const child = proc.spawn('certoraRun', args);
const child = spawn('certoraRun', args);

const stream = new PassThrough();
const output = collect(stream);
Expand All @@ -103,7 +111,7 @@ async function runCertora(spec, contract, files, options = []) {
});

// wait for process end
const [code, signal] = await events.once(child, 'exit');
const [code, signal] = await once(child, 'exit');

// error
if (code || signal) {
Expand Down
109 changes: 99 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"hardhat-ignore-warnings": "^0.2.11",
"lodash.startcase": "^4.4.0",
"micromatch": "^4.0.2",
"p-limit": "^3.1.0",
"p-limit": "^6.0.0",
"prettier": "^3.0.0",
"prettier-plugin-solidity": "^1.1.0",
"rimraf": "^6.0.0",
Expand Down