-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
570 additions
and
6 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/contracts/contracts/test-helpers/Helper_GasMeasurer.sol
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,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.7.0; | ||
|
||
contract Helper_GasMeasurer { | ||
function measureCallGas( | ||
address _target, | ||
bytes memory _data | ||
) | ||
public | ||
returns ( uint ) | ||
{ | ||
uint gasBefore; | ||
uint gasAfter; | ||
|
||
uint calldataStart; | ||
uint calldataLength; | ||
assembly { | ||
calldataStart := add(_data,0x20) | ||
calldataLength := mload(_data) | ||
} | ||
|
||
bool success; | ||
assembly { | ||
gasBefore := gas() | ||
success := call(gas(), _target, 0, calldataStart, calldataLength, 0, 0) | ||
gasAfter := gas() | ||
} | ||
require(success, "Call failed, but calls we want to measure gas for should succeed!"); | ||
|
||
return gasBefore - gasAfter; | ||
} | ||
} |
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
Oops, something went wrong.