Skip to content

Create a test to replicate this issue and fix the bug in the proposal…#116

Open
bighumus wants to merge 1 commit into
mainfrom
issue-115-fix
Open

Create a test to replicate this issue and fix the bug in the proposal…#116
bighumus wants to merge 1 commit into
mainfrom
issue-115-fix

Conversation

@bighumus

@bighumus bighumus commented Jul 18, 2025

Copy link
Copy Markdown
Collaborator

Implement a test to replicate the issue and fix the bug in the proposal reader
Fixes #115

Summary by CodeRabbit

  • New Features
    • Improved quorum calculation by introducing a new utility that accurately determines quorum requirements based on contract data.
  • Bug Fixes
    • Enhanced vote result evaluation to ensure proposals only pass when the correct quorum is reached.
  • Tests
    • Added an integration test to verify proposals with unanimous votes do not pass if the quorum is not met.

@vercel

vercel Bot commented Jul 18, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
e-vsd ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2025 10:19pm

@coderabbitai

coderabbitai Bot commented Jul 18, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce a new utility function, calculateQuorumFromContracts, to centralize quorum calculation logic using contract data. This function is now used in both the useQuorum React hook and the BlockchainProposalReader class, replacing previous manual calculations. Corresponding tests were updated to dynamically determine quorum values.

Changes

File(s) Change Summary
hooks/use-quorum.tsx Replaced manual quorum calculation with call to calculateQuorumFromContracts.
lib/proposal-services/blockchain/blockchain-proposal-reader.ts Integrated calculateQuorumFromContracts to determine quorum for proposal vote result logic.
lib/utils.ts Added ceil helper and new calculateQuorumFromContracts async function.
test/blockchain-proposal-service/membership-accept.test.ts Added integration test for proposal acceptance when votes are just below quorum.

Sequence Diagram(s)

sequenceDiagram
  participant UI as UI (React Hook)
  participant Utils as Utils (calculateQuorumFromContracts)
  participant Gov as EvsdGovernor Contract
  participant Tok as EvsdToken Contract

  UI->>Utils: calculateQuorumFromContracts(governor, token)
  Utils->>Tok: totalSupply()
  Utils->>Gov: quorumNumerator()
  Utils->>Gov: quorumDenominator()
  Utils-->>UI: quorum (bigint)
Loading
sequenceDiagram
  participant ProposalReader as BlockchainProposalReader
  participant Utils as Utils (calculateQuorumFromContracts)
  participant Gov as EvsdGovernor Contract
  participant Tok as EvsdToken Contract
  participant Vote as getVoteResultForItem

  ProposalReader->>Utils: calculateQuorumFromContracts(governor, token)
  Utils->>Tok: totalSupply()
  Utils->>Gov: quorumNumerator()
  Utils->>Gov: quorumDenominator()
  Utils-->>ProposalReader: quorum (bigint)
  ProposalReader->>Vote: getVoteResultForItem(item, quorum)
Loading

Poem

In the warren of code, a quorum we seek,
Now one function does the math—no more hide and peek!
Contracts queried, results combined,
Logic refactored, all neatly aligned.
With every vote tallied, the rules are quite clear—
The rabbits rejoice: the quorum is here! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-18T22_21_03_782Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f96665 and e2c9b9c.

📒 Files selected for processing (4)
  • hooks/use-quorum.tsx (2 hunks)
  • lib/proposal-services/blockchain/blockchain-proposal-reader.ts (2 hunks)
  • lib/utils.ts (2 hunks)
  • test/blockchain-proposal-service/membership-accept.test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
test/blockchain-proposal-service/membership-accept.test.ts (4)
lib/proposal-services/blockchain/blockchain-proposal-service.ts (1)
  • BlockchainProposalService (22-96)
types/proposal.ts (3)
  • User (1-4)
  • UIAddVoterVotableItem (15-18)
  • UIProposal (26-31)
lib/utils.ts (1)
  • calculateQuorumFromContracts (102-111)
test/utils.ts (1)
  • fastForwardTime (165-173)
lib/proposal-services/blockchain/blockchain-proposal-reader.ts (1)
lib/utils.ts (2)
  • calculateQuorumFromContracts (102-111)
  • getVoteResultForItem (91-96)
hooks/use-quorum.tsx (1)
lib/utils.ts (1)
  • calculateQuorumFromContracts (102-111)
⏰ 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). (2)
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
🔇 Additional comments (9)
lib/utils.ts (3)

16-16: LGTM! Import statement correctly updated.

The import statement appropriately includes both contract types needed for the new utility function.


98-100: LGTM! Correct implementation of ceiling division for bigint.

The ceiling division implementation using (a + b - 1n) / b is mathematically correct and follows the standard formula for integer ceiling division.


102-111: LGTM! Well-designed utility function for centralizing quorum calculation.

The function correctly:

  • Fetches total supply from the token contract
  • Retrieves quorum parameters from the governor contract
  • Applies ceiling division to compute the final quorum
  • Returns the result as a bigint for precision

This centralization will improve maintainability and consistency across the codebase.

lib/proposal-services/blockchain/blockchain-proposal-reader.ts (2)

15-15: LGTM! Import statement correctly includes the new utility function.


83-87: BigInt→Number conversion is safe for expected quorum values

I searched the codebase for any large hard-coded token supplies or quorum settings and only found small, test-scoped numeric values (e.g. initial voter counts, quorums of 5, etc.). In production the token supply is minted 1:1 to voter addresses, so it will always stay well below Number.MAX_SAFE_INTEGER.

No further changes needed.

hooks/use-quorum.tsx (1)

3-3: LGTM! Import statement correctly includes the utility function.

test/blockchain-proposal-service/membership-accept.test.ts (3)

7-9: LGTM! Import statements correctly updated for the new test.

The imports properly include the necessary types and utility function for the enhanced test coverage.


17-18: LGTM! Contract instance variables properly declared and initialized.

The addition of evsdToken and evsdGovernor variables provides the necessary contract instances for the new quorum calculation test.

Also applies to: 31-32


138-170: Excellent test case for quorum threshold edge case.

This test properly verifies the critical scenario where:

  • All votes are in favor (unanimous)
  • Total votes are just below the quorum threshold
  • The proposal should correctly fail due to insufficient quorum

The test uses the same calculateQuorumFromContracts utility as the production code, ensuring consistency and proper integration testing.

Comment thread hooks/use-quorum.tsx
Comment on lines +18 to 21
const quorum = calculateQuorumFromContracts(governor, token);
try {
setQuorum(Number(quorum));
} catch (error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bug: Missing await for async function call.

The calculateQuorumFromContracts function is async but is not being awaited. This will cause quorum to be a Promise object instead of a bigint, and Number(quorum) will result in NaN.

Apply this fix:

-      const quorum = calculateQuorumFromContracts(governor, token);
+      const quorum = await calculateQuorumFromContracts(governor, token);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const quorum = calculateQuorumFromContracts(governor, token);
try {
setQuorum(Number(quorum));
} catch (error) {
const quorum = await calculateQuorumFromContracts(governor, token);
try {
setQuorum(Number(quorum));
} catch (error) {
🤖 Prompt for AI Agents
In hooks/use-quorum.tsx around lines 18 to 21, the call to the async function
calculateQuorumFromContracts is missing an await, causing quorum to be a Promise
instead of the expected bigint. Fix this by adding the await keyword before
calculateQuorumFromContracts to properly wait for the Promise to resolve before
converting it to a Number and setting the state.

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.

Dialog to accept membership is shown even when someone is not eligible to become a member

1 participant