Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more tests #361

Merged
merged 18 commits into from
Sep 26, 2024
Merged

chore: add more tests #361

merged 18 commits into from
Sep 26, 2024

Conversation

guorong009
Copy link

Description

It is needed to add more unit and negative tests for the codebase.

Related issues

Changes

  • add unit tests for frontend/dev modules

@guorong009 guorong009 self-assigned this Aug 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 98.21162% with 12 lines in your changes missing coverage. Please review.

Project coverage is 85.07%. Comparing base (977fc5f) to head (3971b7f).

Files with missing lines Patch % Lines
halo2_frontend/src/dev/failure.rs 98.57% 6 Missing ⚠️
halo2_frontend/src/dev/gates.rs 95.38% 3 Missing ⚠️
halo2_frontend/src/dev/tfp.rs 98.18% 2 Missing ⚠️
halo2_middleware/src/expression.rs 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #361      +/-   ##
==========================================
+ Coverage   82.02%   85.07%   +3.05%     
==========================================
  Files          85       85              
  Lines       17989    18658     +669     
==========================================
+ Hits        14755    15874    +1119     
+ Misses       3234     2784     -450     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guorong009 guorong009 marked this pull request as ready for review September 24, 2024 09:22
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments. But overall LGTM

halo2_backend/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_frontend/src/dev/cost.rs Outdated Show resolved Hide resolved
halo2_frontend/src/dev/tfp.rs Outdated Show resolved Hide resolved
halo2_proofs/tests/serialization.rs Outdated Show resolved Hide resolved
Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM , just some comments and I think that we should avoid using temporally files.

halo2_backend/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_frontend/src/dev/failure.rs Show resolved Hide resolved
halo2_middleware/src/expression.rs Outdated Show resolved Hide resolved
halo2_frontend/src/plonk/circuit/expression.rs Outdated Show resolved Hide resolved
halo2_proofs/tests/serialization.rs Outdated Show resolved Hide resolved
Comment on lines +146 to +166
// serialization test for vk
let f = File::create("serialization-test.vk").unwrap();
let mut writer = BufWriter::new(f);
vk.write(&mut writer, SerdeFormat::RawBytes).unwrap();
writer.flush().unwrap();

let f = File::open("serialization-test.vk").unwrap();
let mut reader = BufReader::new(f);
#[allow(clippy::unit_arg)]
let vk = vk_read::<G1Affine, _, StandardPlonk>(
&mut reader,
SerdeFormat::RawBytes,
k,
&circuit,
compress_selectors,
)
.unwrap();

std::fs::remove_file("serialization-test.vk").unwrap();

// serialization test for pk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO is better to use an internal buffer, and when not possible use something like https://crates.io/crates/tempfile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how about leaving the current use of std::fs::File as is?
The goal of this test is to show the file operations and use of pk/vk_read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this test is to show the file operations and use of pk/vk_read.

If we want to show the usage, I think that the proper way is to add it halo2_proofs/examples, or, if there's no File/Networking I/O as a documentation test (like https://doc.rust-lang.org/1.81.0/src/core/array/mod.rs.html#107)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create example in b81e32d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove it, since now it's in the examples?

halo2_frontend/src/dev/gates.rs Show resolved Hide resolved
halo2_frontend/src/dev/cost.rs Outdated Show resolved Hide resolved
halo2_frontend/src/dev/cost.rs Outdated Show resolved Hide resolved
let cost = CircuitCost::<Eq, MyCircuit<Fp, 2>>::measure(K, &my_circuit);

let marginal_proof_size = cost.marginal_proof_size();
assert_eq!(usize::from(marginal_proof_size), 1376);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point in create this complex circuit to check the cost?
Are we checking in any way that 1376 is the expected result for this circuit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no.
I add this test to show how to use the tool, and the output from tool usage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto in #361 (comment), it should go into examples, because there's no proper test here. I think that this could make sense as a test if we want to be absolutely sure that costs does not change due some side effects, but I do not think that this is the case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create example in b81e32d

Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we have to remove the tests that aready copied as an example files, AFAIR test coverage will cover it.

The rest is LGTM.

@guorong009
Copy link
Author

I think that we have to remove the tests that aready copied as an example files, AFAIR test coverage will cover it.

The rest is LGTM.

Thanks for indication!
In 3971b7f, I get rid of unit test from cost.
But, I leave the serialization test since it is integration test, and it serves another purpose - assert proof.

@guorong009 guorong009 merged commit 81c7058 into main Sep 26, 2024
6 checks passed
@guorong009 guorong009 deleted the gr@add-more-tests branch September 26, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants