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

Commit

Permalink
Fix invalid snapshot revert hanging when the shapshot id doesn't exist (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch authored Mar 21, 2019
1 parent 6a68216 commit 27bf5b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions test/snapshotting.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ describe("Checkpointing / Reverting", function() {
assert.strictEqual(oldReceipt, null, "Receipt should be null as it should have been removed");
});

it("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;

Expand Down

0 comments on commit 27bf5b8

Please sign in to comment.