-
Notifications
You must be signed in to change notification settings - Fork 4
fix(contract): support inconsistency testing EVM time #386
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -184,7 +184,18 @@ describe("HatsTimeFrameModule", () => { | |||||||||||||
roleHatId, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
expect(elapsedTime - 1n).to.equal(expectedElapsedTime); | ||||||||||||||
/** | ||||||||||||||
* Using increaseTo, it sets the next block’s timestamp, | ||||||||||||||
* but if you immediately query the time or run a transaction, | ||||||||||||||
* the block may not be mined at exactly that timestamp, | ||||||||||||||
* or the contract may use the previous block’s timestamp. | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
expect(elapsedTime).to.oneOf([ | ||||||||||||||
expectedElapsedTime, | ||||||||||||||
expectedElapsedTime + 1n, | ||||||||||||||
expectedElapsedTime - 1n, | ||||||||||||||
]); | ||||||||||||||
Comment on lines
+194
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timing tolerance logic is duplicated across multiple test assertions. Consider extracting this into a helper function like
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
|
||||||||||||||
await time.increaseTo(initialTime + 200n); | ||||||||||||||
|
||||||||||||||
|
@@ -197,7 +208,11 @@ describe("HatsTimeFrameModule", () => { | |||||||||||||
roleHatId, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
expect(elapsedTime - 1n).to.equal(expectedElapsedTime); | ||||||||||||||
expect(elapsedTime).to.oneOf([ | ||||||||||||||
expectedElapsedTime, | ||||||||||||||
expectedElapsedTime + 1n, | ||||||||||||||
expectedElapsedTime - 1n, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
await HatsTimeFrameModule.write.deactivate([roleHatId, address1Validated]); | ||||||||||||||
|
||||||||||||||
|
@@ -216,7 +231,11 @@ describe("HatsTimeFrameModule", () => { | |||||||||||||
roleHatId, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
expect(elapsedTime).to.equal(expectedElapsedTime); | ||||||||||||||
expect(elapsedTime).to.oneOf([ | ||||||||||||||
expectedElapsedTime, | ||||||||||||||
expectedElapsedTime + 1n, | ||||||||||||||
expectedElapsedTime - 1n, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
// Reactivate the hat | ||||||||||||||
await HatsTimeFrameModule.write.reactivate([roleHatId, address1Validated]); | ||||||||||||||
|
@@ -236,7 +255,11 @@ describe("HatsTimeFrameModule", () => { | |||||||||||||
roleHatId, | ||||||||||||||
]); | ||||||||||||||
|
||||||||||||||
expect(elapsedTime - 1n).to.equal(expectedElapsedTime); | ||||||||||||||
expect(elapsedTime).to.oneOf([ | ||||||||||||||
expectedElapsedTime, | ||||||||||||||
expectedElapsedTime + 1n, | ||||||||||||||
expectedElapsedTime - 1n, | ||||||||||||||
]); | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
it("mint hat previous time", async () => { | ||||||||||||||
|
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.
[nitpick] The comment explains the timing behavior well, but it should be moved to the top of the test function or extracted as a module-level comment since this timing issue affects all assertions in the test, not just this specific one.
Copilot uses AI. Check for mistakes.