Skip to content
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

Fix: Double-counting time after hat reactivation in HatsTimeFrameModule #124

Merged
merged 6 commits into from
Oct 19, 2024

Conversation

tanapl
Copy link
Collaborator

@tanapl tanapl commented Sep 30, 2024

Test Case Breakdown:

  1. Initial Period:
  • The user wears the hat for 100 seconds.
  • The getWearingElapsedTime function should return 100n after time.increase(100).
  1. Deactivate:
  • After deactivation, the time should pause, and no additional time should be counted.
  • Increasing time by 50 seconds while deactivated should not affect the elapsed time (getWearingElapsedTime should still return 100n).
  1. Reactivate:
  • After reactivating the hat, time should continue counting from 100n, not resetting or counting the deactivated period.
  • After adding 100 seconds post-reactivation, the total elapsed time should now be 200n (100n from before deactivation and 100n after reactivation).
image

@tanapl tanapl closed this Oct 3, 2024
@tanapl tanapl reopened this Oct 3, 2024
@tanapl
Copy link
Collaborator Author

tanapl commented Oct 3, 2024

Problem (Fixed)

  • Test Failures:
    The test suite for HatsTimeFrameModule was failing due to discrepancies between the expected and actual elapsed times calculated by the contract.

  • Time Calculation Errors:
    The getWearingElapsedTime function in the contract was incorrectly calculating the elapsed time, particularly during periods when the hat was inactive.

  • Inconsistent block.timestamp:

  • The tests did not account for how block.timestamp increments during transactions in the test environment, leading to off-by-one errors.

Result

  • Passing Tests:
    All tests now pass, confirming that the HatsTimeFrameModule functions as intended.

  • Accurate Time Tracking:
    The contract correctly calculates the elapsed time a wearer has actively worn a hat, properly accounting for activation and deactivation periods.

  • Robust Testing:
    The improved test suite provides reliable verification of contract behavior, reducing the likelihood of future discrepancies.

@yu23ki14 yu23ki14 merged commit 169e48e into main Oct 19, 2024
1 check passed
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