mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-10 05:58:08 -05:00
test: added basic tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "circomlib/comparators.circom";
|
||||
include "circomlib/mux1.circom";
|
||||
include "circomlib/circuits/comparators.circom";
|
||||
include "circomlib/circuits/mux1.circom";
|
||||
|
||||
template QuinSelector(array_length) {
|
||||
signal input array[array_length];
|
||||
@@ -50,9 +50,6 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) {
|
||||
signal r_dec[decoded_length];
|
||||
signal sum_dec[decoded_length];
|
||||
|
||||
r_enc[0] <== 1;
|
||||
r_dec[0] <== 1;
|
||||
|
||||
// Helper components
|
||||
component mux_enc[encoded_length];
|
||||
|
||||
@@ -102,6 +99,7 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) {
|
||||
}
|
||||
|
||||
// Calculate powers of r for encoded
|
||||
r_enc[0] <== 1;
|
||||
for (var i = 1; i < encoded_length; i++) {
|
||||
mux_enc[i] = Mux1();
|
||||
mux_enc[i].c[0] <== r_enc[i - 1] * r;
|
||||
@@ -111,6 +109,7 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) {
|
||||
}
|
||||
|
||||
// Calculate powers of r for decoded
|
||||
r_dec[0] <== 1;
|
||||
for (var i = 1; i < decoded_length; i++) {
|
||||
r_dec[i] <== r_dec[i - 1] * r;
|
||||
}
|
||||
@@ -129,12 +128,4 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) {
|
||||
|
||||
// Check if rlc for decoded is equal to rlc for encoded
|
||||
is_valid <== IsEqual()([ sum_enc[encoded_length - 1], sum_dec[decoded_length - 1]]);
|
||||
}
|
||||
|
||||
component main = RemoveSoftLineBreaks(17, 11);
|
||||
|
||||
/* INPUT = {
|
||||
"encoded": [115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107, 61, 13, 10],
|
||||
"decoded": [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 107],
|
||||
"r": 69
|
||||
} */
|
||||
}
|
||||
56
packages/circuits/tests/remove-soft-line-breaks.test.ts
Normal file
56
packages/circuits/tests/remove-soft-line-breaks.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { wasm as wasm_tester } from "circom_tester";
|
||||
import path from "path";
|
||||
|
||||
describe("RemoveSoftLineBreaks", () => {
|
||||
let circuit: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(
|
||||
__dirname,
|
||||
"./test-circuits/remove-soft-line-breaks-test.circom"
|
||||
),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should correctly remove soft line breaks", async () => {
|
||||
const input = {
|
||||
encoded: [
|
||||
115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107,
|
||||
61, 13, 10,
|
||||
],
|
||||
decoded: [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 107],
|
||||
r: 69,
|
||||
};
|
||||
|
||||
const witness = await circuit.calculateWitness(input);
|
||||
await circuit.checkConstraints(witness);
|
||||
|
||||
await circuit.assertOut(witness, {
|
||||
is_valid: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("should fail when decoded input is incorrect", async () => {
|
||||
const input = {
|
||||
encoded: [
|
||||
115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107,
|
||||
61, 13, 10,
|
||||
],
|
||||
decoded: [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 108], // Changed last character
|
||||
r: 69,
|
||||
};
|
||||
|
||||
const witness = await circuit.calculateWitness(input);
|
||||
await circuit.checkConstraints(witness);
|
||||
|
||||
await circuit.assertOut(witness, {
|
||||
is_valid: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "../../helpers/remove-soft-line-breaks.circom";
|
||||
|
||||
component main = RemoveSoftLineBreaks(17, 11);
|
||||
Reference in New Issue
Block a user