-
Notifications
You must be signed in to change notification settings - Fork 680
[added temporal snapshot/revert, added evm_decreaseTime, added tests for both] #81
[added temporal snapshot/revert, added evm_decreaseTime, added tests for both] #81
Conversation
…roring evm_increaseTime, added tests for both modifications]
@@ -1042,6 +1042,12 @@ BlockchainDouble.prototype.increaseTime = function(seconds) { | |||
return this.timeAdjustment; | |||
}; | |||
|
|||
BlockchainDouble.prototype.decreaseTime = function(seconds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to let increaseTime
accept negative values? That'd be one fewer public method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainly because "increaseTime" as read by a developer would indicate time is going up, and a negative value on the variable is easy to mistake on a glance, while reading right to left of a function is pretty solid.
increaseTime(forwardValue)
increaseTime(-forwardValue)
vs
increaseTime(forwardValue)
decreaseTime(backwardsValue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plus reading pure function definitions in the readme (which I didn't update in this PR) would be immediately visible, while you'd have to create creating an extra note surrounding a negative value being acceptable in the alternative.
Hi @chris-shyft! Thanks for this! Just so I don't repeat myself, can you please review my comments over on #95 and let me know what you think? Also FWIW, given that this PR seems to more directly address #390, I'm slightly more inclined to accept it than #95. Perhaps you and @PhABC might want to get in touch and coordinate changes? |
sure thing :) so the reason for an additional evm_decreaseTime instead of using the snapshot directly is that I want to create a timelock contract test. B = current blocktime #1, I create a transaction that has a timelock to time B + T. then I continue with tests in the same truffle test file. now, I could revert instead of decreasing the time. that would most likely also produce proper logical test results (probably even more "proper" than decreasing the time after running a transaction), except that because I know the final values of specific interactions, I wanted to keep these known values rolling within the tests instead of making notes that while X value was changed, it has been reverted in the next it(). simply test logic here. my main goal with this was having snapshot/revert function properly, and I added the evm_decreaseTime because it was useful for my test logic flow. I think it'll be useful for people, but I can't specify an exact use-case, so my only proverbial "skin in the game" here is that I'll have to re-write my tests and/or have a fork that uses my methods for evm_decreaseTime. |
Just to make sure you're aware, Truffle automatically runs I agree however that without truffle doing the snapshot/revert adding an |
yep I'm aware. it wasn't between test files (contract("xyx") {}) it was between tests within the same contract("xyz") {}. |
@benjamincburns If #2 was merged and I'm specifically referring to unit tests within the same test, where following time sensitive tests will fail after increasing timestamp. AFAIK, there is no Here's an example where the second test fails when place before after the timestamp increase, but succeed if executed before ; it('should REVERT when expiration is passed', async function () {
//Increasing time
await web3.currentProvider.send({
jsonrpc: "2.0",
method: "evm_increaseTime",
params: [timeToExpire],
id: 0
});
...
});
// This test will fail because of previous test which increase the timestamp
it('should PASS when expiration is NOT passed', async function () {
...
}); |
@PhABC I believe I was mistaken before - truffle calls The correct way to handle this case is still to use In the mean time we've added support for mining a block at an exact timestamp, and we've added the ability to set the time to a specific timestamp. Between these new features and snapshot/revert, hopefully your needs are covered. |
ftw <3