-
Notifications
You must be signed in to change notification settings - Fork 1
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
e553e04
commit a79fd4e
Showing
4 changed files
with
142 additions
and
31 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
"template": "Extract", | ||
"params": [ | ||
12, | ||
2 | ||
3 | ||
] | ||
}, | ||
"value_array": { | ||
|
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
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
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,91 @@ | ||
import { circomkit, WitnessTester } from "../common"; | ||
import { Delimiters, WhiteSpace, Numbers, Escape, INITIAL_IN, INITIAL_OUT } from '.'; | ||
|
||
describe("StateUpdate :: Values", () => { | ||
let circuit: WitnessTester< | ||
["byte", "pointer", "stack", "parsing_string", "parsing_number"], | ||
["next_pointer", "next_stack", "next_parsing_string", "next_parsing_number"] | ||
>; | ||
before(async () => { | ||
circuit = await circomkit.WitnessTester(`GetTopOfStack`, { | ||
file: "circuits/parser", | ||
template: "StateUpdate", | ||
params: [4], | ||
}); | ||
console.log("#constraints:", await circuit.getConstraintCount()); | ||
}); | ||
function generatePassCase(input: any, expected: any, desc: string) { | ||
const description = Object.entries(input) | ||
.map(([key, value]) => `${key} = ${value}`) | ||
.join(", "); | ||
|
||
it(`(valid) witness: ${description}\n${desc}`, async () => { | ||
await circuit.expectPass(input, expected); | ||
}); | ||
} | ||
|
||
function generateFailCase(input: any, desc: string) { | ||
const description = Object.entries(input) | ||
.map(([key, value]) => `${key} = ${value}`) | ||
.join(", "); | ||
|
||
it(`(invalid) witness: ${description}\n${desc}`, async () => { | ||
await circuit.expectFail(input); | ||
}); | ||
} | ||
|
||
|
||
//-TEST_1----------------------------------------------------------// | ||
// idea: Read a number value after a key in an object. | ||
// state: pointer == 2, stack == [1,3,0,0] | ||
// read: `0` | ||
// expect: pointer --> 2 | ||
// stack --> [1,3,0,0] | ||
// parsing_number --> 1 | ||
let read_number = { ...INITIAL_IN }; | ||
read_number.pointer = 2; | ||
read_number.stack = [1, 3, 0, 0]; | ||
read_number.byte = Numbers.ZERO; | ||
let read_number_out = { ...INITIAL_OUT }; | ||
read_number_out.next_pointer = 2; | ||
read_number_out.next_stack = [1, 3, 0, 0]; | ||
read_number_out.next_parsing_number = 1; | ||
generatePassCase(read_number, read_number_out, ">>>> `0` read"); | ||
|
||
//-TEST_2----------------------------------------------------------// | ||
// idea: Inside a number value after a key in an object. | ||
// state: pointer == 2, stack == [1,3,0,0], parsing_number == 1 | ||
// read: `,` | ||
// expect: pointer --> 2 | ||
// stack --> [1,3,0,0] | ||
// parsing_number --> 0 | ||
let inside_number = { ...INITIAL_IN }; | ||
inside_number.pointer = 2; | ||
inside_number.stack = [1, 3, 0, 0]; | ||
inside_number.parsing_number = 1; | ||
inside_number.byte = Delimiters.COMMA; | ||
let inside_number_out = { ...INITIAL_OUT }; | ||
inside_number_out.next_pointer = 2; | ||
inside_number_out.next_stack = [1, 3, 0, 0]; | ||
generatePassCase(inside_number, inside_number_out, ">>>> `,` read"); | ||
|
||
// TODO: Note that reading a space while reading a number will not throw an error! | ||
|
||
//-TEST_2----------------------------------------------------------// | ||
// idea: Inside a number value after a key in an object. | ||
// state: pointer == 2, stack == [1,3,0,0], parsing_number == 1 | ||
// read: `1` | ||
// expect: pointer --> 2 | ||
// stack --> [1,3,0,0] | ||
// parsing_number --> 0 | ||
let inside_number_continue = { ...INITIAL_IN }; | ||
inside_number_continue.pointer = 2; | ||
inside_number_continue.stack = [1, 3, 0, 0]; | ||
inside_number_continue.parsing_number = 1; | ||
inside_number_continue.byte = Numbers.ONE; | ||
let inside_number_continue_out = { ...INITIAL_OUT }; | ||
inside_number_continue_out.next_pointer = 2; | ||
inside_number_continue_out.next_stack = [1, 3, 0, 0]; | ||
inside_number_continue_out.next_parsing_number = 1; | ||
generatePassCase(inside_number_continue, inside_number_continue_out, ">>>> `,` read"); | ||
}); |