Skip to content

test: crisp circuit tests#978

Merged
ctrlc03 merged 1 commit into
devfrom
test/circuit-crisp-tests
Nov 6, 2025
Merged

test: crisp circuit tests#978
ctrlc03 merged 1 commit into
devfrom
test/circuit-crisp-tests

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Nov 6, 2025

Copy link
Copy Markdown
Collaborator

fix #964

Summary by CodeRabbit

  • Tests
    • Improved error assertion patterns for clearer, more reliable failure checks in the test suite.
    • Added a comprehensive test covering the maximum supported vote value to ensure correct behavior and proof validation for edge cases.

@vercel

vercel Bot commented Nov 6, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
crisp Skipped Skipped Nov 6, 2025 6:59pm
enclave-docs Skipped Skipped Nov 6, 2025 6:59pm

@coderabbitai

coderabbitai Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Refactored rejection assertions in vote.test.ts to use direct awaitable rejects and added a new test validating proof generation/verification when vote values equal the maximum (2^28 - 1).

Changes

Cohort / File(s) Summary
Test Assertion Refactor & Max-value Test
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
Replaced nested async rejection assertions with await expect(...).rejects.toThrow() style. Added test "should succeed when the vote is the maximum value supported" using MAXIMUM_VOTE_VALUE = 2^28 - 1, encoding the vote, signing, building Merkle proof, generating CRISP inputs, producing a proof, and verifying it succeeds.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant encodeVote
    participant encryptInputs as encryptVoteAndGenerateCRISPInputs
    participant prover as generateProof
    participant verifier as verifyProof

    Test->>encodeVote: encode vote at MAXIMUM_VOTE_VALUE
    encodeVote-->>Test: encodedVote

    Test->>encryptInputs: build CRISP inputs (signature, merkle proof, encrypted vote)
    encryptInputs-->>Test: CRISP_inputs

    Test->>prover: generateProof(CRISP_inputs)
    prover-->>Test: proof

    Test->>verifier: verifyProof(proof)
    verifier-->>Test: verificationResult (valid)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus review on correct use/definition of MAXIMUM_VOTE_VALUE and that the new test constructs signature and Merkle proof correctly.
  • Verify proof generation/verification branches are exercised at the boundary value.

Possibly related PRs

Suggested reviewers

  • cedoor
  • 0xjei

Poem

🐇 A peak-value vote, encoded tight,
Proofs hop through the circuit’s light.
Assertions simplified, tidy and neat,
Maxed-out ballots make tests complete.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: crisp circuit tests' clearly relates to the main change: adding and modifying circuit tests. It accurately summarizes the primary content of the changeset.
Linked Issues check ✅ Passed The PR addresses issue #964 by adding end-to-end tests for the Noir circuit using crisp-sdk, including test modifications and a new maximum-value test case.
Out of Scope Changes check ✅ Passed All changes in the PR are focused on circuit testing: refactoring error assertions and adding a maximum-value test case. No out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/circuit-crisp-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)

410-446: Remove variable shadowing to improve clarity.

The test logic is sound and validates an important edge case. However, the local declarations of MAXIMUM_VOTE_VALUE (line 411), votingPowerLeaf (line 412), and VOTE (lines 415-418) shadow identifiers already imported from '../src' and './constants' at lines 22 and 24, reducing code clarity.

Consider either:

  1. Reusing the imported constants if their values match the test intent, or
  2. Renaming the local variables to avoid shadowing (e.g., maxVoteValue, maxVotingPower, maxVote)

Apply this diff to remove shadowing:

-    it('should succeed when the vote is the maximum value supported', { timeout: 100000 }, async () => {
-      const MAXIMUM_VOTE_VALUE = BigInt(Math.pow(2, 28) - 1) // 268,435,455
-      const votingPowerLeaf = MAXIMUM_VOTE_VALUE // Balance at the limit
-
-      // Vote exactly at the maximum
-      const VOTE = {
-        yes: MAXIMUM_VOTE_VALUE,
-        no: 0n,
-      }
+    it('should succeed when the vote is the maximum value supported', { timeout: 100000 }, async () => {
+      const maxVotingPower = MAXIMUM_VOTE_VALUE // Balance at the limit
+
+      // Vote exactly at the maximum
+      const maxVote = {
+        yes: MAXIMUM_VOTE_VALUE,
+        no: 0n,
+      }

-      const encodedVote = encodeVote(VOTE, VotingMode.GOVERNANCE, votingPowerLeaf)
+      const encodedVote = encodeVote(maxVote, VotingMode.GOVERNANCE, maxVotingPower)

       // hardhat default private key
       const privateKey = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
       const account = privateKeyToAccount(privateKey)
       const signature = await account.signMessage({ message: MESSAGE })
-      const leaf = hashLeaf(account.address.toLowerCase(), votingPowerLeaf.toString())
+      const leaf = hashLeaf(account.address.toLowerCase(), maxVotingPower.toString())
       const leaves = [...LEAVES, leaf]
-      const merkleProof = generateMerkleProof(0n, votingPowerLeaf, account.address.toLowerCase(), leaves, 20)
+      const merkleProof = generateMerkleProof(0n, maxVotingPower, account.address.toLowerCase(), leaves, 20)

       const inputs = await encryptVoteAndGenerateCRISPInputs({
         encodedVote,
         publicKey,
         previousCiphertext,
         signature,
         message: MESSAGE,
         merkleData: merkleProof,
-        balance: votingPowerLeaf,
+        balance: maxVotingPower,
         slotAddress: account.address.toLowerCase(),
         isFirstVote: false,
       })
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d14826c and 819c12f.

📒 Files selected for processing (1)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (4)
examples/CRISP/packages/crisp-sdk/src/vote.ts (5)
  • getCircuitOutputValue (286-292)
  • encodeVote (64-90)
  • encryptVoteAndGenerateCRISPInputs (170-208)
  • generateProof (264-272)
  • verifyProof (294-298)
examples/CRISP/packages/crisp-sdk/src/constants.ts (2)
  • MAXIMUM_VOTE_VALUE (23-23)
  • MESSAGE (34-34)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (4)
  • votingPowerLeaf (31-31)
  • VOTE (14-14)
  • MESSAGE (11-11)
  • LEAVES (16-27)
examples/CRISP/packages/crisp-sdk/src/utils.ts (2)
  • hashLeaf (18-20)
  • generateMerkleProof (39-79)
🪛 Gitleaks (8.28.0)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts

[high] 423-423: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: rust_unit
  • GitHub Check: build_sdk
  • GitHub Check: build_enclave_cli
  • GitHub Check: integration_prebuild
  • GitHub Check: test_net
  • GitHub Check: test_contracts
  • GitHub Check: rust_integration
🔇 Additional comments (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)

378-378: LGTM! Cleaner assertion pattern.

The refactored rejection assertions using await expect(...).rejects.toThrow() are more idiomatic and concise than the previous nested async function approach.

Also applies to: 407-407, 474-474

@cedoor cedoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

utACK

@ctrlc03 ctrlc03 linked an issue Nov 6, 2025 that may be closed by this pull request
@ctrlc03 ctrlc03 enabled auto-merge (squash) November 6, 2025 18:50
@ctrlc03 ctrlc03 force-pushed the test/circuit-crisp-tests branch from 819c12f to e4e679d Compare November 6, 2025 18:59
@vercel vercel Bot temporarily deployed to Preview – crisp November 6, 2025 18:59 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs November 6, 2025 18:59 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)

410-446: Consider using the imported MAXIMUM_VOTE_VALUE constant.

The test locally redefines MAXIMUM_VOTE_VALUE, VOTE, and votingPowerLeaf, which shadow the imported constant (line 22) and outer scope variables (line 24). While this makes the test self-contained, it could cause confusion.

Consider these options:

  1. Use the imported MAXIMUM_VOTE_VALUE directly
  2. If local redefinition is intentional for clarity, add a comment explaining why

Apply this diff to use the imported constant:

-    it('should succeed when the vote is the maximum value supported', { timeout: 100000 }, async () => {
-      const MAXIMUM_VOTE_VALUE = BigInt(Math.pow(2, 28) - 1) // 268,435,455
-      const votingPowerLeaf = MAXIMUM_VOTE_VALUE // Balance at the limit
-
-      // Vote exactly at the maximum
-      const VOTE = {
+    it('should succeed when the vote is the maximum value supported', { timeout: 100000 }, async () => {
+      // Use maximum value as both voting power and vote
+      const maxVotingPower = MAXIMUM_VOTE_VALUE
+      const maxVote = {
         yes: MAXIMUM_VOTE_VALUE,
         no: 0n,
       }
 
-      const encodedVote = encodeVote(VOTE, VotingMode.GOVERNANCE, votingPowerLeaf)
+      const encodedVote = encodeVote(maxVote, VotingMode.GOVERNANCE, maxVotingPower)

Note: The hardcoded private key at line 423 is Hardhat's default test key and not a security concern, despite the static analysis warning.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 819c12f and e4e679d.

📒 Files selected for processing (1)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (4)
examples/CRISP/packages/crisp-sdk/src/vote.ts (4)
  • encodeVote (64-90)
  • encryptVoteAndGenerateCRISPInputs (170-208)
  • generateProof (264-272)
  • verifyProof (294-298)
examples/CRISP/packages/crisp-sdk/src/constants.ts (2)
  • MAXIMUM_VOTE_VALUE (23-23)
  • MESSAGE (34-34)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (4)
  • votingPowerLeaf (31-31)
  • VOTE (14-14)
  • MESSAGE (11-11)
  • LEAVES (16-27)
examples/CRISP/packages/crisp-sdk/src/utils.ts (2)
  • hashLeaf (18-20)
  • generateMerkleProof (39-79)
🪛 Gitleaks (8.28.0)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts

[high] 423-423: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: rust_unit
  • GitHub Check: rust_integration
  • GitHub Check: build_enclave_cli
  • GitHub Check: integration_prebuild
  • GitHub Check: test_net
  • GitHub Check: build_sdk
  • GitHub Check: test_contracts
  • GitHub Check: build_e3_support_dev
🔇 Additional comments (3)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3)

378-378: LGTM! Improved rejection assertion syntax.

The refactor to use direct await expect(...).rejects.toThrow() is more concise and follows modern Vitest/Jest patterns.


404-408: LGTM! Consistent refactor with clarifying comment.

The refactored rejection assertion is consistent with the pattern used elsewhere, and the added comment improves clarity about what's being tested.


474-474: LGTM! Consistent refactor.

The refactored rejection assertion maintains consistency with the other test cases in this file.

@ctrlc03 ctrlc03 merged commit 988fc1c into dev Nov 6, 2025
23 checks passed
@ctrlc03 ctrlc03 deleted the test/circuit-crisp-tests branch November 6, 2025 19:51
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.

e2e tests of circuit

2 participants