Skip to content

Commit

Permalink
feat: basefee cheatcode (gakonst#257)
Browse files Browse the repository at this point in the history
* feat: add Fee cheatcode

closes gakonst#255

* test: add basefee cheatcode test

* chore: clippy lints

* test: set vm to london
  • Loading branch information
gakonst authored Dec 19, 2021
1 parent ece3a50 commit cfffa2f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ impl<'a, 'b, B: Backend, P: PrecompileSet> CheatcodeStackExecutor<'a, 'b, B, P>
HEVMCalls::Roll(inner) => {
state.backend.cheats.block_number = Some(inner.0);
}
HEVMCalls::Fee(inner) => {
state.backend.cheats.block_base_fee_per_gas = Some(inner.0);
}
HEVMCalls::Store(inner) => {
state.set_storage(inner.0, inner.1.into(), inner.2.into());
}
Expand Down Expand Up @@ -1078,7 +1081,7 @@ mod tests {

#[test]
fn cheatcodes() {
let config = Config::istanbul();
let config = Config::london();
let vicinity = new_vicinity();
let backend = new_backend(&vicinity, Default::default());
let gas_limit = 10_000_000;
Expand Down
1 change: 1 addition & 0 deletions evm-adapters/src/sputnik/cheatcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ethers::contract::abigen!(
r#"[
roll(uint256)
warp(uint256)
fee(uint256)
store(address,bytes32,bytes32)
load(address,bytes32)(bytes32)
ffi(string[])(bytes)
Expand Down
16 changes: 13 additions & 3 deletions evm-adapters/testdata/CheatCodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface Hevm {
function warp(uint256) external;
// Set block.height (newHeight)
function roll(uint256) external;
// Set block.basefee (newBasefee)
function fee(uint256) external;
// Loads a storage slot from an address (who, slot)
function load(address,bytes32) external returns (bytes32);
// Stores a value to an address' storage slot, (who, slot, value)
Expand Down Expand Up @@ -71,6 +73,14 @@ contract CheatCodes is DSTest {
assertEq(block.timestamp, pre + jump + 1);
}

// Fee

// Sets the basefee
function testFee(uint256 fee) public {
hevm.fee(fee);
require(block.basefee == fee);
}

// Roll

// Underscore does not run the fuzz test?!
Expand Down Expand Up @@ -188,7 +198,7 @@ contract CheatCodes is DSTest {

function testEtch() public {
address rewriteCode = address(1337);

bytes memory newCode = hex"1337";
hevm.etch(rewriteCode, newCode);
bytes memory n_code = getCode(rewriteCode);
Expand All @@ -199,15 +209,15 @@ contract CheatCodes is DSTest {
ExpectRevert target = new ExpectRevert();
hevm.expectRevert("Value too large");
target.stringErr(101);
target.stringErr(99);
target.stringErr(99);
}

function testExpectCustomRevert() public {
ExpectRevert target = new ExpectRevert();
bytes memory data = abi.encodePacked(bytes4(keccak256("InputTooLarge()")));
hevm.expectRevert(data);
target.customErr(101);
target.customErr(99);
target.customErr(99);
}

function testCalleeExpectRevert() public {
Expand Down

0 comments on commit cfffa2f

Please sign in to comment.