Skip to content

Commit

Permalink
Collect intrinsicGas for JSON output (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Mar 31, 2024
1 parent 7d48881 commit d255965
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ interface MethodDataItem {
contract: string, // Contract name
method: string, // Method name
fnSig: string, // Full method call signature
callData: number[],
gasData: number[],
callData: number[], // L1 gas used for calldata when emulating L2
gasData: number[], // L1 or L2 evm "execution" gas
intrinsicGas: number[], // Intrinsic gas associated with each gasData entry
numberOfCalls: number,
min?: number,
max?: number,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ export class Collector {
? 0
: getCalldataGasForNetwork(this.options, tx as JsonRpcTx);

const intrinsicGas = getIntrinsicGas(tx.input);

this.data.methods[id].gasData.push(executionGas);
this.data.methods[id].callData.push(calldataGas);
this.data.methods[id].intrinsicGas.push(intrinsicGas);
this.data.methods[id].numberOfCalls += 1;
this.data.methods[id].isCall = this.data.methods[id].isCall || !this.options.includeIntrinsicGas;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/lib/gasData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class GasData {
contract: contract.name,
method: methodIDs[key].name,
fnSig: methodIDs[key].fnSig,
intrinsicGas: [],
callData: [],
gasData: [],
numberOfCalls: 0
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface MethodDataItem {
fnSig: string,
callData: number[],
gasData: number[],
intrinsicGas: number[],
numberOfCalls: number,
min?: number,
max?: number,
Expand Down
5 changes: 4 additions & 1 deletion test/integration/options.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ describe("Default Options", function () {
const dataItem = findMethod(methods, "VariableCosts", "addToMap");
assert.equal(dataItem?.numberOfCalls, 4);
assert.equal(dataItem?.gasData.length, 4);
assert.equal(dataItem?.intrinsicGas.length, 4);
assert.exists(dataItem?.min);
assert.exists(dataItem?.max);
assert.exists(dataItem?.executionGasAverage);
assert(dataItem!.min! < dataItem!.max!);
assert(dataItem!.min! < dataItem!.executionGasAverage!);
assert(dataItem!.executionGasAverage! < dataItem!.max!)
assert(dataItem!.executionGasAverage! < dataItem!.max!);
assert(dataItem?.intrinsicGas[0]! > 21_000);
assert(dataItem?.gasData[0]! > dataItem?.intrinsicGas[0]!);
});

it("should collect deployment data for contracts with names that shadow each other", function(){
Expand Down

0 comments on commit d255965

Please sign in to comment.