Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Snapshot API saves and restores time deltas. #2

Merged
merged 3 commits into from
Apr 12, 2018

Conversation

scnale
Copy link
Contributor

@scnale scnale commented Jul 7, 2017

When running tests, the snapshot API wasn't saving the time adjustments made through the evm_timeIncrease JSON-RPC command. I added the code necessary to save and restore the appropriate state but I'm not sure this is the best way to do it. According to my own tests it seems to be working.

This offers better support for unit testing.
@hiqua
Copy link

hiqua commented Dec 12, 2017

Is there a reason not to merge these changes?

@madvas
Copy link

madvas commented Dec 12, 2017

Please merge, much needed

benjamincburns pushed a commit that referenced this pull request Dec 26, 2017
@benjamincburns benjamincburns changed the base branch from master to develop December 26, 2017 05:25
@benjamincburns
Copy link
Contributor

@scnale sorry it has taken us so long to circle 'round to this PR! Unfortunately, I don't think it's working. I've pushed a (failing) test to this PR which demonstrates how I think it's meant to work. Can you please either update the test to correct my misunderstanding, or update your solution to make the test pass?

@benjamincburns
Copy link
Contributor

I don't know why, but the new test isn't showing in the latest travis build. I promise it's there, and if you run it locally it fails.

@scnale
Copy link
Contributor Author

scnale commented Dec 26, 2017

Ah, I see. Comparing timestamps won't work because the time adjustment is added to the current timestamp. I think the best way to test this would be to:

  • take a snapshot
  • call evm_increaseTime with any value other than zero
  • restore the snapshot
  • call evm_increaseTime with nonzero value k (preferably different from the previous one) and check its return value for equality with k.

Edit: Nevermind, I thought it was comparing timestamps. I will look into it once I get it setup.

@benjamincburns
Copy link
Contributor

@scnale it's been quite a while - no pressure, but do you intend to fix up the test failures? If not, I'll take it on if I have time, or if I don't I'll just close this PR and flag the issue as needshelp.

@ouziel-slama
Copy link

Please fix/merge, much needed to write real tests. Thanks.

@benjamincburns
Copy link
Contributor

@ouziel-slama, per comments above, the changes in this PR don't work as intended. Since I haven't heard back from @scnale in quite a while I'll close this to avoid confusion. If you'd like to fork @scnale's changes and submit a new PR yourself, I strongly encourage it!

chris-shyft referenced this pull request in ShyftNetwork/shyft_ganache-core Mar 8, 2018
@PhABC
Copy link

PhABC commented Apr 2, 2018

@benjamincburns and @scnale the fix works as intended. There is a mistake in the new test case, where revert should revert to snapshots[1]. Line 87 should therefore be send("evm_revert",[1], function(err, result) { ... }); instead of send("evm_revert", function(err, result) { ... });.

Trace with current test implementation

  1. timeAdjustement : -50652919
  2. evm_increaseTime (line 46)
  3. timeAdjustement : -50634919
  4. evm_snapshot: (line 75, snapshot 1, timeAdjustement == -50634919)
  5. evm_increaseTime (line 77)
  6. timeAdjustement : -50616919
  7. send("evm_revert", function(err, result) {...}) (line 87)
  8. timeAdjustement : -50616919

The current test assert that 4. should be equal to 8, which is false. By specifying snapshot to 1, the timeAdjustment is correctly reverted to the value stored at 4.

@benjamincburns
Copy link
Contributor

There is a mistake in the new test case

But... but I wrote that test case! 😊

Thanks so much for pointing this out, @PhABC - I'll have a look!

@benjamincburns
Copy link
Contributor

I merged this PR, but forgot the --no-ff flag :-(

// Adjust time
web3.eth.getBlock('latest', function(err, block){
if(err) return done(err)
var previousBlockTime = block.timestamp

Choose a reason for hiding this comment

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

Unused var, fyi

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

Successfully merging this pull request may close these issues.

7 participants