From cfffa2f7700989a193bf3ba5cc735af10c40651f Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sun, 19 Dec 2021 20:15:52 +0200 Subject: [PATCH] feat: basefee cheatcode (#257) * feat: add Fee cheatcode closes #255 * test: add basefee cheatcode test * chore: clippy lints * test: set vm to london --- .../src/sputnik/cheatcodes/cheatcode_handler.rs | 5 ++++- evm-adapters/src/sputnik/cheatcodes/mod.rs | 1 + evm-adapters/testdata/CheatCodes.sol | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs b/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs index ae41ece7b..941ef18b8 100644 --- a/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs +++ b/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs @@ -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()); } @@ -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; diff --git a/evm-adapters/src/sputnik/cheatcodes/mod.rs b/evm-adapters/src/sputnik/cheatcodes/mod.rs index c4828b993..6a42193c9 100644 --- a/evm-adapters/src/sputnik/cheatcodes/mod.rs +++ b/evm-adapters/src/sputnik/cheatcodes/mod.rs @@ -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) diff --git a/evm-adapters/testdata/CheatCodes.sol b/evm-adapters/testdata/CheatCodes.sol index 48fa154a9..f9616a0e3 100644 --- a/evm-adapters/testdata/CheatCodes.sol +++ b/evm-adapters/testdata/CheatCodes.sol @@ -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) @@ -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?! @@ -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); @@ -199,7 +209,7 @@ 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 { @@ -207,7 +217,7 @@ contract CheatCodes is DSTest { bytes memory data = abi.encodePacked(bytes4(keccak256("InputTooLarge()"))); hevm.expectRevert(data); target.customErr(101); - target.customErr(99); + target.customErr(99); } function testCalleeExpectRevert() public {