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

[test] Allow setting blockchain's clock #196

Merged
merged 4 commits into from
Sep 1, 2023

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented Aug 17, 2023

Depends on: onflow/cadence#2734

Description

Implements the TestFramework.MoveTime(int64), so that users can manipulate the blockchain's time.
It passes a custom Clock implementation to the EmulatorBackend.

Example usage:

import Test

pub fun test() {
    let blockchain = Test.newEmulatorBlockchain()
    // timeDelta is the representation of 35 days,
    // in the form of seconds.
    let timeDelta = Fix64(35 * 24 * 60 * 60)
    blockchain.moveTime(by: timeDelta)
    // A negative time delta moves the time backwards
    blockchain.moveTime(by: timeDelta * -1.0)
}

  • 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
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice!

test/emulator_backend.go Outdated Show resolved Hide resolved
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

Nice!

@SupunS SupunS requested a review from turbolent August 18, 2023 15:43
@m-Peter
Copy link
Contributor Author

m-Peter commented Aug 18, 2023

I would update the cadence dependency to a commit, but there's a breaking change for ReadRandom, so it wouldn't work anyway.

@m-Peter m-Peter force-pushed the testing-framework-move-time-utility branch from b087a9c to 4145e33 Compare September 1, 2023 11:12
@m-Peter
Copy link
Contributor Author

m-Peter commented Sep 1, 2023

@SupunS I have bumped the cadence & flow-go dependencies to certain commits, so I think this is good to be merged 🙏

@SupunS SupunS merged commit c6f5906 into onflow:master Sep 1, 2023
@m-Peter m-Peter deleted the testing-framework-move-time-utility branch September 6, 2023 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants