-
Notifications
You must be signed in to change notification settings - Fork 76
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
Showing
2 changed files
with
39 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,33 @@ | ||
import { wasm as wasm_tester } from "circom_tester"; | ||
import path from "path"; | ||
import { bigIntToChunkedBytes, Uint8ArrayToCharArray } from "@zk-email/helpers/src/binary-format"; | ||
|
||
|
||
describe("SplitBytesToWords Helper unit test", () => { | ||
jest.setTimeout(0.1 * 60 * 1000); | ||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
circuit = await wasm_tester( | ||
path.join(__dirname, "./test-circuits/splitBytesToWords-test.circom"), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
// output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
|
||
}); | ||
|
||
it("should split correctly according to bigIntToChunkedBytes function", async function () { | ||
const bytes = new Uint8Array(256).map(() => Math.floor(Math.random() * 256)); | ||
const bytesBigInt = bytes.reduce((acc, val) => (acc << 8n) | BigInt(val), 0n); | ||
const ts_split_to_words = bigIntToChunkedBytes(bytesBigInt, 121, 17); | ||
const ts_split_to_words_bigint = ts_split_to_words.map((word) => BigInt(word)); | ||
const witness = await circuit.calculateWitness({ | ||
in: Uint8ArrayToCharArray(bytes) | ||
}); | ||
await circuit.assertOut(witness, { out: ts_split_to_words_bigint }); | ||
}); | ||
|
||
}); |
6 changes: 6 additions & 0 deletions
6
packages/circuits/tests/test-circuits/splitBytesToWords-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,6 @@ | ||
pragma circom 2.1.6; | ||
|
||
include "../../utils/bytes.circom"; | ||
|
||
component main = SplitBytesToWords(256,121,17); | ||
|