Skip to content

Commit

Permalink
Unit tests for ValueCommitment
Browse files Browse the repository at this point in the history
  • Loading branch information
OBrezhniev committed May 1, 2024
1 parent 9511cce commit 9483263
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/circuits/query/valueCommitmentTest.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.1;

include "../../../circuits/lib/query/valueCommitment.circom";

component main = ValueCommitment();
31 changes: 31 additions & 0 deletions test/query/valueCommitment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {describe} from "mocha";

const path = require("path");
const wasm_tester = require("circom_tester").wasm;


describe("ValueCommitment test", function () {
let valueCommitmentCircuit;

before(async function () {
valueCommitmentCircuit = await wasm_tester(path.join(__dirname, "../circuits/query/", "valueCommitmentTest.circom"));
});

it("should commit a value with a non-zero nonce", async () => {
const inputs = { value: "5", commitNonce: "7" };
const expectedOut = { out: "21007229687521157814825902919006068496120320911167801732994749038798743998593" };

const witness = await valueCommitmentCircuit.calculateWitness(inputs, true);
await valueCommitmentCircuit.assertOut(witness, expectedOut);
await valueCommitmentCircuit.checkConstraints(witness);
});

it("should return zero for a commit with zero nonce", async () => {
const inputs = { value: "10", commitNonce: "0" };
const expectedOut = { out: "0" };

const witness = await valueCommitmentCircuit.calculateWitness(inputs, true);
await valueCommitmentCircuit.assertOut(witness, expectedOut);
await valueCommitmentCircuit.checkConstraints(witness);
});
});

0 comments on commit 9483263

Please sign in to comment.