-
Notifications
You must be signed in to change notification settings - Fork 3
test(DEVoterVoting): add test for very short voting durations #105
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
Conversation
WalkthroughRemoved a custom HardhatRuntimeEnvironment viem type augmentation, added a test for a 1-second voting duration in startVotingPeriod, and updated endVotingPeriod calls to pass an empty-array first argument. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
There was a problem hiding this 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 (1)
test/DEVoterVoting.ts (1)
93-121
: Make the 1‑second test fully deterministic and compare as BigInt.Avoid Number() casts and assert expiry deterministically to prevent flakiness under different mining settings.
Apply this minimal diff:
- const duration = 1; // 1 second duration + const duration = 1n; // 1 second duration - await devoterVoting.write.startVotingPeriod([BigInt(duration)], { + await devoterVoting.write.startVotingPeriod([duration], { account: owner.account, }); // Get the actual values from the contract const votingStartTime = await devoterVoting.read.votingStartTime(); const votingEndTime = await devoterVoting.read.votingEndTime(); - const isVotingActive = await devoterVoting.read.isVotingActive(); // Verify that votingEndTime equals votingStartTime + 1 second - expect(Number(votingEndTime)).to.equal(Number(votingStartTime) + duration); + expect(votingEndTime).to.equal(votingStartTime + duration); // Verify that the voting period is active - expect(isVotingActive).to.be.true; + expect(await devoterVoting.read.isVotingActive()).to.be.true; + + // Advance time to ensure the short period elapses and flips to inactive + await time.increase(2); + expect(await devoterVoting.read.isVotingActive()).to.be.false;Note: If time.increase isn’t available in your toolbox-viem version, use setNextBlockTimestamp or provider.send("evm_increaseTime", …) + mine. Please confirm.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
test/DEVoterVoting.ts
(3 hunks)
🔇 Additional comments (2)
test/DEVoterVoting.ts (2)
12-12
: Removing the manual HRE augmentation is correct.Relying on @nomicfoundation/hardhat-viem’s provided types is the right call. Ensure tsconfig.json includes the plugin’s types so this remains stable even if these top‑of‑file imports are later refactored.
144-144
: Correct viem write signature for no‑arg function.Passing an empty args array to write.endVotingPeriod is the correct pattern; good fix.
Add test case to verify contract behavior with 1-second voting duration Remove redundant type declaration as it's now provided by hardhat-viem
5ad23df
to
d79960b
Compare
Add test case to verify contract behavior with 1-second voting duration Remove redundant type declaration as it's now provided by hardhat-viem
Summary by CodeRabbit
New Features
Tests
Chores