-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·95 lines (77 loc) · 2.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
const { ensureDirectoryStructure, writeResults } = require("./src/files");
const { callNargo } = require("./src/nargo");
const { PACKAGES } = require("./src/constants");
let override;
let errors = [];
function handleFlags() {
const args = process.argv.slice(2);
const flags = {};
for (let i = 0; i < args.length; i += 2) {
flags[args[i]] = args[i + 1];
}
const project = flags["--project"];
if (!project) return;
override = {};
override.project = project;
delete flags["--project"];
Object.keys(flags).forEach((flag) => {
override[flag.substring(2)] = flags[flag];
});
}
async function runAll() {
while (true) {
ensureDirectoryStructure();
let baselineResults;
let packages = PACKAGES;
// generate baseline & provers
baselineResults = packages.map((package) => package.generator());
// run tests
await Promise.all(
packages.map(async (package, index) => {
const baselineResult = baselineResults[index].toString();
await executeTest(package.name, baselineResult);
})
);
writeResults(errors);
}
}
async function runSingle() {
const filteredPackages = PACKAGES.filter(
(package) => package.name === override.project
);
if (filteredPackages.length === 0) {
throw new Error(`${override.project} not found`);
}
const package = filteredPackages[0];
delete override.project;
// generate baseline & prover
const baselineResult = package.generator(override).toString();
// run test
await executeTest(package.name, baselineResult);
writeResults(errors);
}
async function executeTest(packageName, baselineResult) {
try {
const testOutput = await callNargo(packageName);
if (testOutput.includes("Circuit witness successfully solved")) {
console.log(`${packageName} success`);
} else {
console.log(`${packageName} failure`);
errors.push({
packageName,
testOutput,
baselineResult,
});
}
} catch (error) {
console.log(`${packageName} failure`);
errors.push({
packageName,
error,
baselineResult,
});
}
}
handleFlags();
override ? runSingle() : runAll();