Skip to content

Commit

Permalink
Added single build for circtuits, yaml file reading and specific prin…
Browse files Browse the repository at this point in the history
…ts for diff testing
  • Loading branch information
Owliie authored and Dimo99 committed Oct 23, 2023
1 parent fe3cab3 commit 3b9874c
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 309 deletions.
23 changes: 23 additions & 0 deletions casper-finality-proofs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions casper-finality-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ colored = "2.0.4"
anyhow = "1.0.75"
crossbeam = "0.8.2"
strum = { version = "0.25", features = ["derive"] }
serde_yaml = "0.9.25"
once_cell = "1.18.0"
walkdir = "2.4.0"
itertools = { version = "0.10.0", default-features = false }
clap = { version = "4.4.6", features = ["derive"] }
77 changes: 0 additions & 77 deletions casper-finality-proofs/scripts/diff_tester.sh

This file was deleted.

5 changes: 0 additions & 5 deletions casper-finality-proofs/scripts/differential_setup/lte.json

This file was deleted.

5 changes: 0 additions & 5 deletions casper-finality-proofs/scripts/differential_setup/test.json

This file was deleted.

18 changes: 0 additions & 18 deletions casper-finality-proofs/scripts/reference/ref_lte.py

This file was deleted.

27 changes: 0 additions & 27 deletions casper-finality-proofs/scripts/reference/ref_test.py

This file was deleted.

32 changes: 20 additions & 12 deletions casper-finality-proofs/src/test_engine/TestEngine.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ The test engine is a tool for running unit tests for plonky2 circuits.

```rust
pub struct Inputs {
pub a: U256,
pub b: U256,
pub a: u64,
pub b: u64,
}

pub struct Outputs {
pub c: U256,
pub c: u64,
}

pub struct TestData {
Expand All @@ -35,11 +35,11 @@ The test engine is a tool for running unit tests for plonky2 circuits.
```json
{
"inputs": {
"a": "0xa",
"b": "0x14"
"a": 1,
"b": 2
},
"outputs": {
"c": "0x1e"
"c": 3
}
}
```
Expand All @@ -58,11 +58,11 @@ The test engine is a tool for running unit tests for plonky2 circuits.
let json_data: TestData = read_fixture::<TestData>(path);

input.write::<Variable>(<L as PlonkParameters<D>>::Field::from_canonical_u64(
json_data.inputs.a.as_u64(),
json_data.inputs.a,
));

input.write::<Variable>(<L as PlonkParameters<D>>::Field::from_canonical_u64(
json_data.inputs.b.as_u64(),
json_data.inputs.b,
));
```

Expand All @@ -72,10 +72,12 @@ The test engine is a tool for running unit tests for plonky2 circuits.
let sum = output.read::<Variable>();
assert_equal!(
sum,
<L as PlonkParameters<D>>::Field::from_canonical_u64(json_data.outputs.c.as_u64())
<L as PlonkParameters<D>>::Field::from_canonical_u64(json_data.outputs.c)
);
```

Each wrapper should return a formatted string containing the outputs of the circuit. This is used to print the outputs in the console for differential testing assertions.

- ### Setup

When a new circuit is created with the corresponding setup mentioned above, the data should be registered in the test engine. To do this, add the following to `src/test_engine/utils/setup.rs`:
Expand All @@ -91,7 +93,7 @@ The test engine is a tool for running unit tests for plonky2 circuits.
```rust
pub fn map_test_to_wrapper(test: TestWrappers) -> ... {
match test {
TestWrappers::NewTestCircuit => Box::new(|path| wrapper_new_test(path.as_str())),
TestWrappers::NewTestCircuit => Box::new(|path, should_assert| wrapper_new_test(path.as_str(), should_assert)),
...
}
}
Expand All @@ -116,12 +118,18 @@ The test engine is a tool for running unit tests for plonky2 circuits.
cargo run --bin test_engine --release
```

To run a specific test, use:
To run the tests with specific flags, use the following format:

```sh
cargo run --bin test_engine --release -- NewTestCircuit
cargo run --bin test_engine --release -- -c=NewTestCircuit
```

Flags:

- `-c`, `--circuit` - run a specific circuit
- `-p`, `--path` - run a specific test folder (should be used along with `-c` flag)
- `-r`, `--ref` - run the test engine in a format that is compatible with the differential testing tool

where `NewTestCircuit` is the name of the registered circuit in `TestWrappers` enum in `src/test_engine/utils/setup.rs`.

If a test fails, the console will print its name in red and after all tests have finished it will print out the circuit's name, the json file and the error.
Expand Down
Loading

0 comments on commit 3b9874c

Please sign in to comment.