Skip to content

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

@codecov
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

3 participants