-
Notifications
You must be signed in to change notification settings - Fork 2
/
testutils.js
38 lines (33 loc) · 1.18 KB
/
testutils.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
const hre = require("hardhat");
const chai = require("chai");
chai.use(require("chai-as-promised"));
const circuitTestsFromData = ({ name, metadata, cases }) => {
describe(name, () => {
Object.entries(cases).forEach(([index, { input, output, hooks }]) => {
it(`Proof Test #${index}`, async () => {
if (output === null) {
await chai.expect(
hre.circom.generateProof(
name,
input
)
).to.be.rejectedWith("Error in template");
return;
}
const { publicSignals } = await hre.circom.generateProof(
name,
input
);
chai.expect(publicSignals).to.be.eql(output);
});
if (hooks !== undefined) {
hooks.forEach(({ name, f }) => {
it(`${name} #${index}`, async () => {
await f({ metadata, input, output });
});
});
}
});
});
};
module.exports = { circuitTestsFromData };