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

feat: add inclusion proofs txe tests #11711

Closed

Conversation

sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Feb 4, 2025

Adding inclusion proof txe tests to hopefully replace flaky_e2e_inclusion_tests

Copy link
Contributor Author

sklppy88 commented Feb 4, 2025

@sklppy88 sklppy88 mentioned this pull request Feb 4, 2025
@sklppy88 sklppy88 changed the title init feat: add inclusion proofs txe test Feb 4, 2025
@sklppy88 sklppy88 changed the title feat: add inclusion proofs txe test feat: add inclusion proofs txe tests Feb 4, 2025
@sklppy88 sklppy88 changed the base branch from ek/fix/txe-block-headers to graphite-base/11711 February 4, 2025 16:11
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from 93133f7 to d31fc38 Compare February 4, 2025 16:55
@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from ae7c789 to 65b3357 Compare February 5, 2025 12:03
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from d31fc38 to 3410f84 Compare February 5, 2025 12:03
@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from 65b3357 to 20d86fd Compare February 5, 2025 13:00
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch 3 times, most recently from 1abffff to 282a5bc Compare February 5, 2025 13:40
@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from 20d86fd to aa5d4ba Compare February 5, 2025 13:40
@sklppy88 sklppy88 marked this pull request as ready for review February 5, 2025 15:17
@sklppy88 sklppy88 requested review from benesjan and Thunkar February 5, 2025 17:24
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

Why not delete the e2e test?

let owner = env.create_account();
env.impersonate(owner);

// Advance a block so we know that at block 2 our contract has not been deployed yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment

Copy link
Contributor Author

@sklppy88 sklppy88 Feb 7, 2025

Choose a reason for hiding this comment

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

Yeah reading this back its definitely not thorough enough. Addressed in 85902d8

}

#[test(should_fail_with = "Nullifier witness not found for nullifier")]
unconstrained fn test_contract_not_initialized() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unconstrained fn test_contract_not_initialized() {
unconstrained fn contract_not_initialized() {

for consistency

Copy link
Contributor Author

@sklppy88 sklppy88 Feb 7, 2025

Choose a reason for hiding this comment

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

Ah very good point thank you 🙏. Have reworked some of the naming in 85902d8

}

#[test(should_fail_with = "Nullifier witness not found for nullifier")]
unconstrained fn test_contract_not_deployed() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test seems to be equal to the one above.

Copy link
Contributor Author

@sklppy88 sklppy88 Feb 7, 2025

Choose a reason for hiding this comment

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

Hmm to me it seems to not be equal to the above test, one checks for the fail of initialization, the other for the fail of deployment. But I think it's definitely not clear enough so thank you for pointing that out. Have added some comments to explain this in 85902d8

let NOTE_VALUE = 69;
InclusionProofs::at(contract_address).create_note(owner, NOTE_VALUE).call(&mut env.private());

env.advance_block_by(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 2?

Copy link
Contributor Author

@sklppy88 sklppy88 Feb 7, 2025

Choose a reason for hiding this comment

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

I'm not sure anymore 😅. Changed to the default (1) in 85902d8

@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from aa5d4ba to c96f3fb Compare February 6, 2025 10:06
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch 2 times, most recently from d5127ab to f317db5 Compare February 7, 2025 10:09
@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from c96f3fb to bb58c87 Compare February 7, 2025 10:09
@sklppy88 sklppy88 changed the base branch from graphite-base/11711 to master February 7, 2025 10:09
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from f317db5 to df09858 Compare February 7, 2025 11:18
@sklppy88 sklppy88 changed the base branch from master to graphite-base/11711 February 7, 2025 12:52
@sklppy88 sklppy88 force-pushed the graphite-base/11711 branch from baa69a2 to edbd170 Compare February 7, 2025 12:52
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from df09858 to 0882c5b Compare February 7, 2025 12:52
@sklppy88 sklppy88 changed the base branch from graphite-base/11711 to ek/fix/make-block-number-in-txe-make-sense February 7, 2025 12:52
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from 0882c5b to 353748e Compare February 7, 2025 13:05
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch from edbd170 to 3bb2506 Compare February 7, 2025 13:05
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch 5 times, most recently from 955f6b0 to a750023 Compare February 7, 2025 16:35
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch 2 times, most recently from 57bee7d to e763b46 Compare February 7, 2025 17:17
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch 4 times, most recently from 20a0708 to 01742d6 Compare February 10, 2025 11:30
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch from e763b46 to 35cc0c4 Compare February 10, 2025 11:30
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from 01742d6 to b729ebb Compare February 10, 2025 14:19
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch from 35cc0c4 to cd72a0e Compare February 10, 2025 14:19
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch from cd72a0e to 69c913c Compare February 10, 2025 15:18
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from b729ebb to 4ae6c08 Compare February 10, 2025 15:18
@sklppy88 sklppy88 requested a review from benesjan February 10, 2025 15:46
@sklppy88 sklppy88 force-pushed the ek/feat/add-inclusion-proofs-txe-tests branch from 4ae6c08 to 85902d8 Compare February 10, 2025 15:52
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

😝

env.advance_block_by(1);

let current_contract_address = get_contract_address();
cheatcodes::set_contract_address(contract_address);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we do this?

assert(note.owner.eq(owner));
assert(note.value.eq(NOTE_VALUE));

// Each of these tests (note inclusion, note non-nullification, and validity (inclusion & non-nullification)) check the assertion at the block of creation of note, as well as at the "current" block
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that block with number 0 is used. Is that the current block? That's kinda weird. Also as far as I remember block 0 is not a legitimate block number (we start from 1).

Copy link
Contributor

Choose a reason for hiding this comment

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

i see that the InclusionProof contract ignores it.

Please nuke the use_block_number param from InclusionProofs contract and always use the block number.

It used to be there because from TS we don't have a direct control over block numbers (which we do in TXE tests)

}

#[test]
unconstrained fn note_flow() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unconstrained fn note_flow() {
unconstrained fn note_validity() {

I think note_validity is a better name here as it communicates what is being tested.

#[test]
unconstrained fn nullify_note_flow() {
// This test creates a note, nullifies it, and checks certain properties about it, namely its inclusion in the trees,
// the non-inclusion of its nullifier, and its validity (the combination of the previous two). These properties are checked before nullification.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is weird. It says that you nullify the note and then you prove that it's not nullified.

}

#[test]
unconstrained fn nullify_note_flow() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test can be merged with the previous one as both test note validity.

  1. create note,
  2. test note validity at current block,
  3. nullify note,
  4. test note validity at historical block.

This test is only slightly more strict by checking the the nullifier non-inclusion is handled correctly.

}

#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
unconstrained fn note_not_nullified_after_nullified() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unconstrained fn note_not_nullified_after_nullified() {
unconstrained fn nullifier_non_inclusion_failure() {


InclusionProofs::at(contract_address).create_note(owner, 5).call(&mut env.private());

env.advance_block_by(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we automine now? And if it's not yet implemente do we have an issue?

If we have an issue would include a todo everywhere here.

}

#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
unconstrained fn note_not_nullified_after_nullified_no_block_number() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test looks like the same thing as the previous one and hence would merge it. Note that we are not testing the InclusionsProof contract but the history library and it triggers the same code paths.

@benesjan
Copy link
Contributor

Shouldn't we also nuke the inclusion_proofs test in the Counter contract?

@sklppy88 sklppy88 changed the base branch from ek/fix/make-block-number-in-txe-make-sense to graphite-base/11711 February 27, 2025 08:59
@sklppy88
Copy link
Contributor Author

Superceded by #12215 and #12360.

@sklppy88 sklppy88 closed this Feb 28, 2025
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.

3 participants