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

Fix invalid snapshot revert hanging when the shapshot id doesn't exist #387

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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