diff --git a/circuits/test/http/codegen.test.ts b/circuits/test/http/codegen.test.ts index d46ec48..0355107 100644 --- a/circuits/test/http/codegen.test.ts +++ b/circuits/test/http/codegen.test.ts @@ -41,11 +41,12 @@ interface Response { } -function executeCodegen(inputFilename: string, outputFilename: string) { +function executeCodegen(circuitName: string, inputFileName: string, lockfileName: string, outputFilename: string) { return new Promise((resolve, reject) => { - const inputPath = join(__dirname, "..", "..", "..", "examples", "http", "lockfile", inputFilename); + const inputFilePath = join(__dirname, "..", "..", "..", "examples", "http", inputFileName); + const lockfilePath = join(__dirname, "..", "..", "..", "examples", "http", "lockfile", lockfileName); - const codegen = spawn("cargo", ["run", "http", "--lockfile", inputPath, "--output-filename", outputFilename]); + const codegen = spawn("cargo", ["run", "http", "--circuit-name", circuitName, "--input-file", inputFilePath, "--lockfile", lockfilePath, "--output-filename", outputFilename]); codegen.stdout.on('data', (data) => { console.log(`stdout: ${data}`); @@ -73,7 +74,7 @@ describe("HTTP :: Codegen :: Request", async () => { let inputfile = "get_request.http"; // generate extractor circuit using codegen - await executeCodegen(`${lockfile}.json`, lockfile); + await executeCodegen("get_request_test", inputfile, `${lockfile}.json`, lockfile); const lockData = readLockFile(`${lockfile}.json`); console.log("lockData: ", JSON.stringify(lockData)); @@ -115,7 +116,7 @@ describe("HTTP :: Codegen :: Request", async () => { let inputfile = "get_request.http"; // generate extractor circuit using codegen - await executeCodegen(`${lockfile}.json`, lockfile); + await executeCodegen("get_request_test", inputfile, `${lockfile}.json`, lockfile); const lockData = readLockFile(`${lockfile}.json`); @@ -161,7 +162,7 @@ describe("HTTP :: Codegen :: Response", async () => { let inputfile = "get_response.http"; // generate extractor circuit using codegen - await executeCodegen(`${lockfile}.json`, lockfile); + await executeCodegen("get_response_test", inputfile, `${lockfile}.json`, lockfile); const lockData = readLockFile(`${lockfile}.json`); console.log("lockData: ", JSON.stringify(lockData)); @@ -207,7 +208,7 @@ describe("HTTP :: Codegen :: Response", async () => { let inputfile = "get_response.http"; // generate extractor circuit using codegen - await executeCodegen(`${lockfile}.json`, lockfile); + await executeCodegen("get_response_test", inputfile, `${lockfile}.json`, lockfile); const lockData = readLockFile(`${lockfile}.json`); diff --git a/circuits/test/json/extractor/extractor.test.ts b/circuits/test/json/extractor/extractor.test.ts index 9b9b6b3..eb27317 100644 --- a/circuits/test/json/extractor/extractor.test.ts +++ b/circuits/test/json/extractor/extractor.test.ts @@ -3,11 +3,12 @@ import { join } from "path"; import { spawn } from "child_process"; -function executeCodegen(inputFilename: string, outputFilename: string) { +function executeCodegen(circuitName: string, inputFileName: string, lockfileName: string, outputFilename: string) { return new Promise((resolve, reject) => { - const inputPath = join(__dirname, "..", "..", "..", "..", "examples", "json", "lockfile", inputFilename); + const inputFilePath = join(__dirname, "..", "..", "..", "..", "examples", "json", "test", inputFileName); + const lockfilePath = join(__dirname, "..", "..", "..", "..", "examples", "json", "lockfile", lockfileName); - const codegen = spawn("cargo", ["run", "json", "--template", inputPath, "--output-filename", outputFilename]); + const codegen = spawn("cargo", ["run", "json", "--circuit-name", circuitName, "--input-file", inputFilePath, "--lockfile", lockfilePath, "--output-filename", outputFilename]); codegen.stdout.on('data', (data) => { console.log(`stdout: ${data}`); @@ -34,7 +35,7 @@ describe("ExtractValue", async () => { let filename = "value_string"; // generate extractor circuit using codegen - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); // read JSON input file into bytes let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["k"]); @@ -56,7 +57,7 @@ describe("ExtractValue", async () => { it("two_keys: {\"key1\": \"abc\", \"key2\": \"def\" }", async () => { let filename = "two_keys" - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["key2"]); circuit = await circomkit.WitnessTester(`Extract`, { @@ -71,7 +72,7 @@ describe("ExtractValue", async () => { it("value_number: {\"k\": 69 }", async () => { let filename = "value_number"; - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["k"]); circuit = await circomkit.WitnessTester(`Extract`, { @@ -88,10 +89,11 @@ describe("ExtractValue", async () => { it("value_array_string: { \"k\" : [ 420 , 69 , 4200 , 600 ], \"b\": [ \"ab\" , \"ba\", \"ccc\", \"d\" ] }", async () => { let filename = "value_array_string"; - await executeCodegen(`${filename}.json`, filename); + let inputFileName = "value_array.json"; + await executeCodegen(`${filename}_test`, `${inputFileName}`, `${filename}.json`, filename); for (let i = 0; i < 4; i++) { - let [input, keyUnicode, output] = readJSONInputFile("value_array.json", ["b", i]); + let [input, keyUnicode, output] = readJSONInputFile(`${inputFileName}`, ["b", i]); circuit = await circomkit.WitnessTester(`Extract`, { file: `main/${filename}`, @@ -106,10 +108,12 @@ describe("ExtractValue", async () => { it("value_array_number: { \"k\" : [ 420 , 69 , 4200 , 600 ], \"b\": [ \"ab\" , \"ba\", \"ccc\", \"d\" ] }", async () => { let filename = "value_array_number"; - await executeCodegen(`${filename}.json`, filename); + let inputFileName = "value_array.json"; + + await executeCodegen(`${filename}_test`, `${inputFileName}`, `${filename}.json`, filename); for (let i = 0; i < 4; i++) { - let [input, keyUnicode, output] = readJSONInputFile("value_array.json", ["k", i]); + let [input, keyUnicode, output] = readJSONInputFile(`${inputFileName}`, ["k", i]); circuit = await circomkit.WitnessTester(`Extract`, { file: `main/${filename}`, @@ -125,7 +129,7 @@ describe("ExtractValue", async () => { it("value_array_nested: { \"a\": [[1,0],[0,1,3]] }", async () => { let filename = "value_array_nested"; - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); let index_0 = 1; let index_1 = 0; let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["a", index_0, index_1]); @@ -150,7 +154,7 @@ describe("ExtractValueMultiDepth", () => { it("value_object: { \"a\": { \"d\" : \"e\", \"e\": \"c\" }, \"e\": { \"f\": \"a\", \"e\": \"2\" } }", async () => { let filename = "value_object"; - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["e", "e"]); @@ -176,7 +180,7 @@ describe("ExtractValueArrayObject", () => { it("value_array_object: {\"a\":[{\"b\":[1,4]},{\"c\":\"b\"}]}", async () => { let filename = "value_array_object"; - await executeCodegen(`${filename}.json`, filename); + await executeCodegen(`${filename}_test`, `${filename}.json`, `${filename}.json`, filename); let index_0 = 0; let index_1 = 0; diff --git a/src/codegen.rs b/src/codegen.rs index 584ca0e..86a2b09 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -33,11 +33,11 @@ pub fn write_circuit_config( } std::fs::write( - circomkit_circuits_config, + circomkit_circuits_config.clone(), serde_json::to_string_pretty(&circomkit_circuits)?, )?; - println!("circomkit circuits config updated for {}", name); + println!("config updated: {}", circomkit_circuits_config.display()); Ok(()) } diff --git a/src/http.rs b/src/http.rs index efed67f..a82ee5d 100644 --- a/src/http.rs +++ b/src/http.rs @@ -563,7 +563,6 @@ fn build_circuit_config( params.push(response.status.len()); params.push(response.message.len()); for (key, value) in response.headers.iter() { - println!("{}, {}", key, value); params.push(key.len()); params.push(value.len()); } diff --git a/src/json.rs b/src/json.rs index 3ab9bae..5c95c38 100644 --- a/src/json.rs +++ b/src/json.rs @@ -551,9 +551,9 @@ fn build_circuit_config( let mut curr_stack_height = 1; let mut inside_string: bool = false; - for (i, char) in input[1..].iter().enumerate() { + for (i, char) in input.iter().skip(1).enumerate() { match char { - b'"' if input[i - 1] != b'\\' => inside_string = !inside_string, + b'"' if input[i] != b'\\' => inside_string = !inside_string, b'{' | b'[' if !inside_string => { curr_stack_height += 1; max_stack_height = max_by(max_stack_height, curr_stack_height, |x, y| x.cmp(y));