snarkjs/test/calculatewitness.js
test/calculatewitness.jsRaw
1/*
2 Copyright 2018 0kims association.
3
4 This file is part of zksnark JavaScript library.
5
6 zksnark JavaScript library is a free software: you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by the
8 Free Software Foundation, either version 3 of the License, or (at your option)
9 any later version.
10
11 zksnark JavaScript library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 zksnark JavaScript library. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20const chai = require("chai");
21const fs = require("fs");
22const path = require("path");
23
24const Circuit = require("../src/circuit.js");
25const BN128 = require("../src/bn128.js");
26const F1Field = require("../src/zqfield.js");
27
28const assert = chai.assert;
29
30
31describe("Calculate witness", () => {
32 it("Should calculate the witness of a sum circuit", () => {
33
34 const cirDef = JSON.parse(fs.readFileSync(path.join(__dirname, "circuit", "sum.json"), "utf8"));
35 const cir = new Circuit(cirDef);
36 const witness = cir.calculateWitness({"a": "33", "b": "34"});
37
38 assert.equal(witness[cir.getSignalIdx("main.out")].toString(), "67");
39 });
40});