-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b3c808
commit bb697f8
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import path from "path"; | ||
import { wasm as wasm_tester } from "circom_tester"; | ||
import { poseidonModular } from "@zk-email/helpers/src/hash"; | ||
|
||
describe("PoseidonModular", () => { | ||
jest.setTimeout(30 * 60 * 1000); // 30 minutes | ||
|
||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
circuit = await wasm_tester( | ||
path.join( | ||
__dirname, | ||
"./test-circuits/poseidon-modular-test.circom" | ||
), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
}); | ||
|
||
it("should hash correctly", async function () { | ||
const inputs = Array.from({ length: 37 }, () => | ||
BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)) | ||
); | ||
const hash = await poseidonModular(inputs); | ||
|
||
const witness = await circuit.calculateWitness({ | ||
in: inputs, | ||
}); | ||
await circuit.checkConstraints(witness); | ||
|
||
expect(witness[1]).toEqual(hash); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/circuits/tests/test-circuits/poseidon-modular-test.circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma circom 2.1.6; | ||
|
||
include "../../utils/hash.circom"; | ||
|
||
component main = PoseidonModular(37); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters