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

Commit

Permalink
Explicitly check for behavior during a revert
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoulter authored and davidmurdoch committed Nov 16, 2020
1 parent 9922d72 commit 03ef260
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/chains/ethereum/tests/api/debug/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("api", () => {
let from: string;
let contractAddress: string;
let transactionHash: string;
let revertTransactionHash: string;
let initialValue: string;
let methods: Record<string, string>;

Expand Down Expand Up @@ -85,6 +86,10 @@ describe("api", () => {
]);

await provider.once("message");

revertTransactionHash = await provider.send("eth_sendTransaction", [
{ from, to: contractAddress, data: "0x" + methods["doARevert()"] }
]);
});

it("should trace a successful transaction without changing state", async () => {
Expand Down Expand Up @@ -120,7 +125,7 @@ describe("api", () => {

assert.strictEqual(lastop.op, "STOP");
assert.strictEqual(lastop.gasCost, 0);
assert.strictEqual(lastop.pc, 191);
assert.strictEqual(lastop.pc, 202); // This will change if you edit Debug.sol

// This makes sure we get the initial value back (the first transaction to setValue())
// and not the value of the second setValue() transaction
Expand All @@ -143,6 +148,22 @@ describe("api", () => {
);
});

it("should still trace reverted transactions", async () => {
let { structLogs } = await provider.send("debug_traceTransaction", [
transactionHash,
{}
]);

// This test mostly ensures we didn't get some type of error message
// from the virtual machine on a reverted transaction.
// If we haven't errored at this state, we're doing pretty good.

// Let's make sure the last operation is a STOP instruction.
let op = structLogs.pop();

assert.strictEqual(op.op, "STOP");
});

it("should have a low memory footprint", async () => {
// This test is more of a change signal than it is looking
// for correct output. By including this test, we assert that
Expand All @@ -155,7 +176,7 @@ describe("api", () => {
// in the final trace is found through execution. Again,
// this test is meant as a change detector, not necessarily a
// failure detector.
let expectedObjectsInFinalTrace = 22843;
let expectedObjectsInFinalTrace = 22814;
let timesToRunLoop = 100;
let address = "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1";
let privateKey =
Expand Down
4 changes: 3 additions & 1 deletion src/chains/ethereum/tests/contracts/Debug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ contract Debug {
}
}


function doARevert() public {
revert("all your base");
}
}

0 comments on commit 03ef260

Please sign in to comment.