fix(contract): support inconsistency testing EVM time#386
fix(contract): support inconsistency testing EVM time#386airinterface wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes timing inconsistencies in EVM contract tests by replacing strict equality assertions with more flexible range-based assertions. The change addresses the inherent timing uncertainty in blockchain testing environments where block timestamps may not be precisely controlled.
- Replaces exact timestamp matching with acceptable range assertions (±1 second tolerance)
- Adds comprehensive documentation explaining the EVM timing behavior
- Updates multiple test assertions to handle timing edge cases consistently
| expect(elapsedTime).to.oneOf([ | ||
| expectedElapsedTime, | ||
| expectedElapsedTime + 1n, | ||
| expectedElapsedTime - 1n, | ||
| ]); |
There was a problem hiding this comment.
The timing tolerance logic is duplicated across multiple test assertions. Consider extracting this into a helper function like expectTimeWithTolerance(actualTime, expectedTime, tolerance = 1n) to reduce code duplication and improve maintainability.
| expect(elapsedTime).to.oneOf([ | |
| expectedElapsedTime, | |
| expectedElapsedTime + 1n, | |
| expectedElapsedTime - 1n, | |
| ]); | |
| expectTimeWithTolerance(elapsedTime, expectedElapsedTime); |
| ]); | ||
|
|
||
| expect(elapsedTime - 1n).to.equal(expectedElapsedTime); | ||
| /** |
There was a problem hiding this comment.
[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.
Pull Request Template
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
Screenshots
If applicable, add screenshots to help explain your problem.