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

Support milliseconds for time delta in Test.moveTime #3015

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented Jan 11, 2024

Description

Although the timeDelta in Test.moveTime accepts a Fix64 value, under the hood it would truncate the value to int64.
We change this to deal with float64, so that we can support millisecond granularity.
Relevant issue: onflow/cadence-tools#264 (comment)


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (24f277e) 80.00% compared to head (913cfcc) 80.00%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3015   +/-   ##
=======================================
  Coverage   80.00%   80.00%           
=======================================
  Files         356      356           
  Lines       83043    83043           
=======================================
  Hits        66437    66437           
  Misses      14247    14247           
  Partials     2359     2359           
Flag Coverage Δ
unittests 80.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -726,7 +726,7 @@ func (t *testEmulatorBackendType) newMoveTimeFunction(
if !ok {
panic(errors.NewUnreachableError())
}
blockchain.MoveTime(int64(timeDelta.ToInt(invocation.LocationRange)))
blockchain.MoveTime(float64(timeDelta) / sema.Fix64Factor)
Copy link
Member

@SupunS SupunS Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting an int64 to float64 could lose precision in some cases. We could instead pass int64 (Fix64Value as is) to MoveTime, and change the parameter's metric to accept nano-seconds (it currently accepts seconds). But might need to pad-right if we do so, since Fix64Factor is 10^8 and nano-seconds factor 10^9. But then there's a risk of padding-right could overflow/underflow. So IDK which one is better.

In reality, these extreme cases would not be even used, so maybe we don't need to worry much, and just support only up to milliseconds and properly documenting might be enough?
@turbolent wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we shouldn't use floating point here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants