From 42a2e0c3a16467b2f4741ab8483f0db98fd3529d Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Mon, 18 Mar 2019 15:55:22 -0400 Subject: [PATCH 1/3] make sure snapshot revert always calls the callback --- lib/statemanager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/statemanager.js b/lib/statemanager.js index 13aaedd8af..6d6b7ad76b 100644 --- a/lib/statemanager.js +++ b/lib/statemanager.js @@ -815,6 +815,8 @@ StateManager.prototype.revert = function(snapshotId, callback) { this.logger.log("Reverting to snapshot #" + snapshotId); if (snapshotId > this.snapshots.length) { + // the snapshot doesn't exist now, or it has already been reverted + callback(null, false); return false; } From 4531a44b2787686d0dcad3809e6caf98fae1c585 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Mon, 18 Mar 2019 16:15:10 -0400 Subject: [PATCH 2/3] add tests --- test/snapshotting.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/snapshotting.js b/test/snapshotting.js index 5ab627522f..6e8c04e9cc 100644 --- a/test/snapshotting.js +++ b/test/snapshotting.js @@ -69,6 +69,21 @@ describe("Checkpointing / Reverting", function() { assert.strictEqual(oldReceipt, null, "Receipt should be null as it should have been removed"); }); + it.only("returns false when reverting a snapshot that doesn't exist", async() => { + const { send } = context; + + const snapShotId1 = await send("evm_snapshot"); + const snapShotId2 = await send("evm_snapshot"); + const response1 = await send("evm_revert", snapShotId1.result); + assert.strictEqual(response1.result, true, "Reverting a snapshot that exists does not work"); + const response2 = await send("evm_revert", snapShotId2.result); + assert.strictEqual(response2.result, false, "Reverting a snapshot that no longer exists does not work"); + const response3 = await send("evm_revert", snapShotId1.result); + assert.strictEqual(response3.result, false, "Reverting a snapshot that hasn't already been reverted does not work"); + const response4 = await send("evm_revert", 999); + assert.strictEqual(response4.result, false, "Reverting a snapshot that has never existed does not work"); + }); + it("checkpoints and reverts without persisting contract storage", async() => { const { accounts, instance, send } = context; From ea331bd84974186968ebb088e516867778d5d279 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Mon, 18 Mar 2019 16:17:24 -0400 Subject: [PATCH 3/3] remove .only from new test --- test/snapshotting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/snapshotting.js b/test/snapshotting.js index 6e8c04e9cc..8514e66d06 100644 --- a/test/snapshotting.js +++ b/test/snapshotting.js @@ -69,7 +69,7 @@ describe("Checkpointing / Reverting", function() { assert.strictEqual(oldReceipt, null, "Receipt should be null as it should have been removed"); }); - it.only("returns false when reverting a snapshot that doesn't exist", async() => { + it("returns false when reverting a snapshot that doesn't exist", async() => { const { send } = context; const snapShotId1 = await send("evm_snapshot");