@@ -4,10 +4,12 @@ pragma solidity >=0.6.2 <0.9.0;
44pragma experimental ABIEncoderV2;
55
66import {StdStorage, stdStorage} from "./StdStorage.sol " ;
7- import {Vm, VmSafe } from "./Vm.sol " ;
7+ import {Vm} from "./Vm.sol " ;
88
99abstract contract StdCheatsSafe {
10- VmSafe private constant vm = VmSafe (address (uint160 (uint256 (keccak256 ("hevm cheat code " )))));
10+ Vm private constant vm = Vm (address (uint160 (uint256 (keccak256 ("hevm cheat code " )))));
11+
12+ bool private gasMeteringOff;
1113
1214 // Data structures to parse Transaction objects from the broadcast artifact
1315 // that conform to EIP1559. The Raw structs is what is parsed from the JSON
@@ -422,6 +424,45 @@ abstract contract StdCheatsSafe {
422424 require (b.length <= 32 , "StdCheats _bytesToUint(bytes): Bytes length exceeds 32. " );
423425 return abi.decode (abi.encodePacked (new bytes (32 - b.length ), b), (uint256 ));
424426 }
427+
428+ function isFork () internal virtual returns (bool status ) {
429+ try vm.activeFork () {
430+ status = true ;
431+ } catch (bytes memory ) {}
432+ }
433+
434+ modifier skipWhenForking () {
435+ if (! isFork ()) {
436+ _;
437+ }
438+ }
439+
440+ modifier skipWhenNotForking () {
441+ if (isFork ()) {
442+ _;
443+ }
444+ }
445+
446+ modifier noGasMetering () {
447+ vm.pauseGasMetering ();
448+ // To prevent turning gas monitoring back on with nested functions that use this modifier,
449+ // we check if gasMetering started in the off position. If it did, we don't want to turn
450+ // it back on until we exit the top level function that used the modifier
451+ //
452+ // i.e. funcA() noGasMetering { funcB() }, where funcB has noGasMetering as well.
453+ // funcA will have `gasStartedOff` as false, funcB will have it as true,
454+ // so we only turn metering back on at the end of the funcA
455+ bool gasStartedOff = gasMeteringOff;
456+ gasMeteringOff = true ;
457+
458+ _;
459+
460+ // if gas metering was on when this modifier was called, turn it back on at the end
461+ if (! gasStartedOff) {
462+ gasMeteringOff = false ;
463+ vm.resumeGasMetering ();
464+ }
465+ }
425466}
426467
427468// Wrappers around cheatcodes to avoid footguns
@@ -431,8 +472,6 @@ abstract contract StdCheats is StdCheatsSafe {
431472 StdStorage private stdstore;
432473 Vm private constant vm = Vm (address (uint160 (uint256 (keccak256 ("hevm cheat code " )))));
433474
434- bool private gasMeteringOff;
435-
436475 // Skip forward or rewind time by the specified number of seconds
437476 function skip (uint256 time ) internal virtual {
438477 vm.warp (block .timestamp + time);
@@ -523,43 +562,4 @@ abstract contract StdCheats is StdCheatsSafe {
523562 stdstore.target (token).sig (0x18160ddd ).checked_write (totSup);
524563 }
525564 }
526-
527- function isFork () internal virtual returns (bool status ) {
528- try vm.activeFork () {
529- status = true ;
530- } catch (bytes memory ) {}
531- }
532-
533- modifier noGasMetering () {
534- vm.pauseGasMetering ();
535- // To prevent turning gas monitoring back on with nested functions that use this modifier,
536- // we check if gasMetering started in the off position. If it did, we don't want to turn
537- // it back on until we exit the top level function that used the modifier
538- //
539- // i.e. funcA() noGasMetering { funcB() }, where funcB has noGasMetering as well.
540- // funcA will have `gasStartedOff` as false, funcB will have it as true,
541- // so we only turn metering back on at the end of the funcA
542- bool gasStartedOff = gasMeteringOff;
543- gasMeteringOff = true ;
544-
545- _;
546-
547- // if gas metering was on when this modifier was called, turn it back on at the end
548- if (! gasStartedOff) {
549- gasMeteringOff = false ;
550- vm.resumeGasMetering ();
551- }
552- }
553-
554- modifier skipWhenForking () {
555- if (! isFork ()) {
556- _;
557- }
558- }
559-
560- modifier skipWhenNotForking () {
561- if (isFork ()) {
562- _;
563- }
564- }
565565}
0 commit comments