Skip to content

Commit

Permalink
first pass (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-chain authored Nov 20, 2020
1 parent a72141f commit ea3785b
Show file tree
Hide file tree
Showing 5 changed files with 570 additions and 6 deletions.
32 changes: 32 additions & 0 deletions packages/contracts/contracts/test-helpers/Helper_GasMeasurer.sol
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;
}
}
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"build:typechain": "buidler typechain",
"test": "yarn run test:contracts",
"test:contracts": "buidler test --show-stack-traces",
"test:gas": "buidler test \"test/contracts/OVM/execution/OVM_StateManager.gas-spec.ts\" --no-compile --show-stack-traces",
"lint": "yarn run lint:typescript",
"lint:typescript": "tslint --format stylish --project .",
"lint:fix": "yarn run lint:fix:typescript",
"lint:fix:typescript": "prettier --config prettier-config.json --write \"buidler.config.ts\" \"{src,test}/**/*.ts\"",
"clean": "rm -rf ./artifacts ./build ./cache",
"deploy": "./bin/deploy.js"
Expand Down
Loading

0 comments on commit ea3785b

Please sign in to comment.