Skip to content

Conversation

markv44
Copy link
Collaborator

@markv44 markv44 commented Sep 15, 2025

Add test case to verify that startVotingPeriod rejects invalid (zero) duration Remove redundant type declaration as it's now provided by hardhat-viem

Summary by CodeRabbit

  • Tests

    • Added a test ensuring a vote cannot be started with a non-positive duration and that voting remains inactive when rejected.
    • Updated tests to align with the latest API usage.
  • Chores

    • Replaced custom local type augmentation with official plugin-provided types.
  • Style

    • Minor formatting cleanups in test assertions.

Copy link

coderabbitai bot commented Sep 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Removes a manual HardhatRuntimeEnvironment viem type augmentation, adds a test that rejects starting voting with a non-positive duration (uses 0) asserting "Invalid duration" and inactive state, updates endVotingPeriod invocation to the two-argument form, and applies minor formatting tweaks in the test file.

Changes

Cohort / File(s) Summary
DEVoterVoting test updates
test/DEVoterVoting.ts
- Removed manual HRE viem type augmentation in favor of plugin-provided types
- Added test: "Should reject start with negative duration" using duration 0, expects revert "Invalid duration", confirms voting remains inactive
- Updated endVotingPeriod invocation from endVotingPeriod({ account }) to endVotingPeriod([], { account })
- Minor formatting/assertion layout changes (no logic change)

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test
  participant Contract as DEVoterVoting

  rect #E8F1FF
    note over Test,Contract: Attempt to start voting with invalid duration
    Test->>Contract: startVotingPeriod(duration = 0)
    Contract-->>Test: revert "Invalid duration"
  end

  rect #F0FFF0
    note over Test,Contract: End voting using updated call signature
    Test->>Contract: endVotingPeriod([], { account: owner })
    Contract-->>Test: tx receipt
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I thump my paw: no negative time!
Types hop home, tidy and bright.
Two-arg endings take their new climb,
Zero-length votes are sent to night.
A rabbit cheers — tests tidy, code light. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "test(DEVoterVoting): add test for invalid voting duration" succinctly and accurately summarizes the primary change in the PR—adding a test to DEVoterVoting that checks invalid/zero voting durations—and is directly aligned with the changes described in test/DEVoterVoting.ts while following conventional commit style.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2f1dfd and a763f57.

📒 Files selected for processing (1)
  • test/DEVoterVoting.ts (2 hunks)

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

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 (3)
test/DEVoterVoting.ts (3)

86-88: Avoid Number() casts; assert with BigInt to keep full precision.

Comparing as BigInt removes unnecessary conversions.

Apply this diff:

-expect(Number(votingEndTime)).to.equal(
-  Number(votingStartTime) + duration
-);
+expect(votingEndTime).to.equal(votingStartTime + BigInt(duration));

95-114: Rename test and make revert assertion less brittle (optional)

  • Test passes 0, so "non‑positive" (or "zero") is more accurate; switch to 0n and accept either the string revert or a custom error.

Apply this diff:

-it("Should reject start with negative duration", async function () {
+it("Should reject start with non-positive duration", async function () {
@@
-        await expect(
-          devoterVoting.write.startVotingPeriod([BigInt(0)], {
-            account: owner.account,
-          })
-        ).to.be.rejectedWith("Invalid duration");
+        await expect(
+          devoterVoting.write.startVotingPeriod([0n], {
+            account: owner.account,
+          })
+        ).to.be.rejectedWith(/Invalid duration|InvalidDuration/);

12-12: Type augmentation cleanup looks good — declare hardhat-viem or ensure peer deps are installed

I ran the check: package.json contains @nomicfoundation/hardhat-toolbox-viem (^4.0.0) and does not list @nomicfoundation/hardhat-viem. The Toolbox bundles hardhat-viem as a peer dependency (so the HRE type-extensions are provided when peer deps are installed), but because peer deps aren't listed in package.json IDEs/TypeScript may not pick up the augmentation — add @nomicfoundation/hardhat-viem to devDependencies or ensure peer deps are installed/pinned. (npmjs.com)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b569f6 and a2f1dfd.

📒 Files selected for processing (1)
  • test/DEVoterVoting.ts (3 hunks)
🔇 Additional comments (2)
test/DEVoterVoting.ts (2)

75-75: Whitespace-only change.


136-136: Explicit empty args array is fine; both forms are valid.

Viem contract instance methods accept (args, options) and allow omitting args for no‑arg functions. Using [] is explicit and TS‑friendly; endVotingPeriod({ account }) is also valid per docs. (viem.sh)

Add test case to verify that startVotingPeriod rejects invalid (zero) duration
Remove redundant type declaration as it's now provided by hardhat-viem
@metanodreamer metanodreamer merged commit 5ab15f6 into main Sep 16, 2025
1 check was pending
@nowak-token nowak-token deleted the test/non-owner branch September 25, 2025 18:31
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.

2 participants