-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
41 lines (36 loc) · 1.77 KB
/
index.ts
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
import { WitnessGenerator } from './src/witness_generator';
import { Checker } from './src/checker';
import * as path from 'path';
import * as fs from 'fs';
import * as utils from './src/utils';
const walkSync = require('walk-sync');
async function compileCircuitDir(circuitDir, options) {
const circuitName = path.basename(circuitDir);
let witnessGenerator = new WitnessGenerator(circuitName, options);
await witnessGenerator.compile(circuitDir);
}
async function testCircuitDir(circuitDir, dataDir, options) {
// make sure the circuit is compiled
const circuitName = path.basename(circuitDir);
let witnessGenerator = new WitnessGenerator(circuitName, options);
const { r1csFilepath, symFilepath } = await witnessGenerator.compile(circuitDir);
const checker = new Checker(r1csFilepath, symFilepath);
if (dataDir == null || dataDir == '') {
dataDir = circuitDir;
}
for (const input of walkSync(path.resolve(dataDir), { includeBasePath: true, globs: ['**/input.json'] })) {
const testCaseDir = path.normalize(path.dirname(input));
//const testCaseName = path.basename(testCaseDir)
console.log('\ntest', testCaseDir);
const inputFile = path.join(testCaseDir, 'input.json');
const witnessFileType = options.witnessFileType == 'bin' || options.witnessFileType == 'wtns' ? 'wtns' : 'json';
const witnessFile = path.join(testCaseDir, 'witness.' + witnessFileType);
const expectedOutputFile = path.join(testCaseDir, 'output.json');
await witnessGenerator.generateWitness(inputFile, witnessFile);
if (!options.sanityCheck || fs.existsSync(expectedOutputFile)) {
await checker.checkConstraintsAndOutput(witnessFile, expectedOutputFile);
}
console.log('\ntest', testCaseDir, 'done');
}
}
export { compileCircuitDir, testCircuitDir, utils };