Skip to content

Commit

Permalink
Remove logs removal upon snapshot reverting.
Browse files Browse the repository at this point in the history
  • Loading branch information
nebojsa94 committed Feb 19, 2020
1 parent f2086ed commit 2f03b8d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 70 deletions.
27 changes: 1 addition & 26 deletions packages/buidler-core/src/internal/buidler-evm/provider/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ import { VMTracer } from "../stack-traces/vm-tracer";
import { Blockchain } from "./blockchain";
import { InternalError, InvalidInputError } from "./errors";
import { bloomFilter, Filter, filterLogs, LATEST_BLOCK, Type } from "./filter";
import {
getRpcBlock,
getRpcLog,
numberToRpcQuantity,
RpcLogOutput
} from "./output";
import { getRpcBlock, getRpcLog, RpcLogOutput } from "./output";
import { getCurrentTimestamp } from "./utils";

const log = debug("buidler:core:buidler-evm:node");
Expand Down Expand Up @@ -669,9 +664,6 @@ export class BuidlerNode extends EventEmitter {
this._blockHashToTxBlockResults = snapshot.blockHashToTxBlockResults;
this._blockHashToTotalDifficulty = snapshot.blockHashToTotalDifficulty;

// Mark logs in log filters as removed
this._removeLogs(snapshot.latestBlock);

// We delete this and the following snapshots, as they can only be used
// once in Ganache
this._snapshots.splice(snapshotIndex);
Expand Down Expand Up @@ -1373,23 +1365,6 @@ export class BuidlerNode extends EventEmitter {
}
}

private _removeLogs(block: Block) {
const blockNumber = new BN(block.header.number);
this._filters.forEach(filter => {
if (filter.type !== Type.LOGS_SUBSCRIPTION) {
return;
}

for (let i = filter.logs.length - 1; i >= 0; i--) {
if (new BN(filter.logs[i].blockNumber!).lte(blockNumber)) {
break;
}

filter.logs[i].removed = true;
}
});
}

private async _computeFilterParams(
filterParams: FilterParams,
isFilter: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,50 +1096,6 @@ describe("Eth module", function() {
1
);
});

it("Supports get filter logs with revert", async function() {
const exampleContract = await deployContract(
this.provider,
`0x${EXAMPLE_CONTRACT.bytecode.object}`
);

const newState =
"000000000000000000000000000000000000000000000000000000000000003b";

const filterId = await this.provider.send("eth_newFilter", [
{
address: exampleContract,
topics: [
[
"0x3359f789ea83a10b6e9605d460de1088ff290dd7b3c9a155c896d45cf495ed4d"
]
]
}
]);

const snapshotId: string = await this.provider.send("evm_snapshot", []);

await this.provider.send("eth_sendTransaction", [
{
to: exampleContract,
from: DEFAULT_ACCOUNTS_ADDRESSES[0],
data: EXAMPLE_CONTRACT.selectors.modifiesState + newState
}
]);

await this.provider.send("evm_revert", [snapshotId]);

const logs = await this.provider.send("eth_getFilterLogs", [filterId]);
assert.lengthOf(logs, 1);

const log = logs[0];
assert.equal(log.removed, true);
assert.equal(log.logIndex, "0x0");
assert.equal(log.transactionIndex, "0x0");
assert.equal(log.blockNumber, "0x2");
assert.equal(log.address, exampleContract);
assert.equal(log.data, `0x${newState}`);
});
});

describe("eth_getLogs", async function() {
Expand Down

0 comments on commit 2f03b8d

Please sign in to comment.