Skip to content

Commit

Permalink
feat(vm): add rpc and eth_getLogs cheats (#475)
Browse files Browse the repository at this point in the history
* feat: add rpc and eth_getLogs cheats

* chore: fmt

* chore: remove shadowed decl

* chore: move rpc cheats into new RPC section

---------

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
  • Loading branch information
Evalir and mds1 authored Nov 13, 2023
1 parent 37a37ab commit 2757ddd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/Vm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ interface VmSafe {
string url;
}

struct EthGetLogs {
address emitter;
bytes32[] topics;
bytes data;
bytes32 blockHash;
uint64 blockNumber;
bytes32 transactionHash;
uint64 transactionIndex;
uint256 logIndex;
bool removed;
}

struct DirEntry {
string errorMessage;
string path;
Expand Down Expand Up @@ -123,6 +135,16 @@ interface VmSafe {
// Resumes gas metering (i.e. gas usage is counted again). Noop if already on.
function resumeGasMetering() external;

// -------- RPC Methods --------

/// Gets all the logs according to specified filter.
function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics)
external
returns (EthGetLogs[] memory logs);

// Performs an Ethereum JSON-RPC request to the current fork URL.
function rpc(string calldata method, string calldata params) external returns (bytes memory data);

// ======== Test Configuration ========

// If the condition is false, discard this run's fuzz inputs and generate new ones.
Expand Down
2 changes: 1 addition & 1 deletion test/Vm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract VmTest is Test {
// inadvertently moved between Vm and VmSafe. This test must be updated each time a function is
// added to or removed from Vm or VmSafe.
function test_interfaceId() public {
assertEq(type(VmSafe).interfaceId, bytes4(0x329f5e71), "VmSafe");
assertEq(type(VmSafe).interfaceId, bytes4(0x1578a242), "VmSafe");
assertEq(type(Vm).interfaceId, bytes4(0x316cedc3), "Vm");
}
}

0 comments on commit 2757ddd

Please sign in to comment.