forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
cool
cheatcode (foundry-rs#5830)
* feat: `cool` cheatcode * refactor: extract to a function, remove check
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity 0.8.18; | ||
|
||
import "../lib/ds-test/src/test.sol"; | ||
import "./Vm.sol"; | ||
|
||
contract CoolTest is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
uint256 public slot0 = 1; | ||
|
||
function testCool_SLOAD_normal() public { | ||
uint256 startGas; | ||
uint256 endGas; | ||
uint256 val; | ||
uint256 beforeCoolGas; | ||
uint256 noCoolGas; | ||
|
||
startGas = gasleft(); | ||
val = slot0; | ||
endGas = gasleft(); | ||
beforeCoolGas = startGas - endGas; | ||
|
||
startGas = gasleft(); | ||
val = slot0; | ||
endGas = gasleft(); | ||
noCoolGas = startGas - endGas; | ||
|
||
assertGt(beforeCoolGas, noCoolGas); | ||
} | ||
|
||
function testCool_SLOAD() public { | ||
uint256 startGas; | ||
uint256 endGas; | ||
uint256 val; | ||
uint256 beforeCoolGas; | ||
uint256 afterCoolGas; | ||
uint256 noCoolGas; | ||
|
||
startGas = gasleft(); | ||
val = slot0; | ||
endGas = gasleft(); | ||
beforeCoolGas = startGas - endGas; | ||
|
||
vm.cool(address(this)); | ||
|
||
startGas = gasleft(); | ||
val = slot0; | ||
endGas = gasleft(); | ||
afterCoolGas = startGas - endGas; | ||
|
||
assertEq(beforeCoolGas, afterCoolGas); | ||
|
||
startGas = gasleft(); | ||
val = slot0; | ||
endGas = gasleft(); | ||
noCoolGas = startGas - endGas; | ||
|
||
assertGt(beforeCoolGas, noCoolGas); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters