Skip to content

Commit

Permalink
fix: update gas report formatting
Browse files Browse the repository at this point in the history
fix: update gas report formatting
  • Loading branch information
sakulstra committed Nov 15, 2024
1 parent d7513b1 commit 758dac2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 40 deletions.
7 changes: 2 additions & 5 deletions dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -23981,21 +23981,18 @@ function formatValue(before, after) {
}
).format(diff)}%</sup>${after}`;
}
function shouldBeSkipped(name) {
return /[mM]ock/.test(name);
}
function getHtmlGasReport(before, after, options = {}) {
let content = "";
after.map((item) => {
const contractBefore = findContract(item.contract, before);
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item) === JSON.stringify(contractBefore))
return;
const [path, name] = item.contract.split(":");
if (shouldBeSkipped(name)) return;
content += `### [${name}](${options.rootUrl}${path})

`;
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)}
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)} / 49152

`;
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item.functions) === JSON.stringify(contractBefore.functions))
return;
Expand Down
7 changes: 2 additions & 5 deletions dist/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23986,21 +23986,18 @@ function formatValue(before, after) {
}
).format(diff)}%</sup>${after}`;
}
function shouldBeSkipped(name) {
return /[mM]ock/.test(name);
}
function getHtmlGasReport(before, after, options = {}) {
let content = "";
after.map((item) => {
const contractBefore = findContract(item.contract, before);
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item) === JSON.stringify(contractBefore))
return;
const [path, name] = item.contract.split(":");
if (shouldBeSkipped(name)) return;
content += `### [${name}](${options.rootUrl}${path})

`;
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)}
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)} / 49152

`;
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item.functions) === JSON.stringify(contractBefore.functions))
return;
Expand Down
7 changes: 2 additions & 5 deletions dist/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ function formatValue(before, after) {
}
).format(diff)}%</sup>${after}`;
}
function shouldBeSkipped(name) {
return /[mM]ock/.test(name);
}
function getHtmlGasReport(before, after, options = {}) {
let content = "";
after.map((item) => {
const contractBefore = findContract(item.contract, before);
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item) === JSON.stringify(contractBefore))
return;
const [path, name] = item.contract.split(":");
if (shouldBeSkipped(name)) return;
content += `### [${name}](${options.rootUrl}${path})
`;
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)}
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)} / 49152
`;
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item.functions) === JSON.stringify(contractBefore.functions))
return;
Expand Down
7 changes: 2 additions & 5 deletions dist/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ function formatValue(before, after) {
}
).format(diff)}%</sup>${after}`;
}
function shouldBeSkipped(name) {
return /[mM]ock/.test(name);
}
function getHtmlGasReport(before, after, options = {}) {
let content = "";
after.map((item) => {
const contractBefore = findContract(item.contract, before);
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item) === JSON.stringify(contractBefore))
return;
const [path, name] = item.contract.split(":");
if (shouldBeSkipped(name)) return;
content += `### [${name}](${options.rootUrl}${path})
`;
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)}
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)} / 49152
`;
if (options.ignoreUnchanged && contractBefore && JSON.stringify(item.functions) === JSON.stringify(contractBefore.functions))
return;
Expand Down
42 changes: 28 additions & 14 deletions src/__snapshots__/lib.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
exports[`lib > should generate a well formatted report with empty root 1`] = `
"### [Create3Factory](https://github.com/src/contracts/create3/Create3Factory.sol)
- gas: 224263
- gas: 224263 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
create(bytes32,bytes) | 286388 | 296666 | 287062 | 397068 | 6 |
Expand All @@ -12,15 +13,17 @@ predictAddress(address,bytes32) | 1024 | 1024 | 1024 | 1024 | 6 |
### [ProxyAdmin](https://github.com/src/contracts/transparent-proxy/ProxyAdmin.sol)
- gas: 0
- gas: 0 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
owner() | 386 | 386 | 386 | 386 | 6 |
### [TransparentProxyFactory](https://github.com/src/contracts/transparent-proxy/TransparentProxyFactory.sol)
- gas: 1609662
- gas: 1609662 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
createDeterministic(address,address,bytes,bytes32) | 574115 | 534507 | 574589 | 574703 | 6 |
Expand All @@ -31,15 +34,17 @@ predictCreateDeterministicProxyAdmin(bytes32) | 6236 | 6236 | 6236 | 6236 | 6 |
### [TransparentUpgradeableProxy](https://github.com/src/contracts/transparent-proxy/TransparentUpgradeableProxy.sol)
- gas: 0
- gas: 0 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
getFoo() | 1042 | 1042 | 1042 | 1042 | 6 |
### [ImplOwnableWithGuardian](https://github.com/test/OwnableWithGuardian.t.sol)
- gas: 285211
- gas: 285211 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
guardian() | 2286 | 2286 | 2286 | 2286 | 1 |
Expand All @@ -49,7 +54,8 @@ updateGuardian(address) | 25944 | 28245 | 28283 | 30394 | 6 |
### [TestPermissionlessRescuable](https://github.com/test/PermissionlessRescuable.t.sol)
- gas: 879072
- gas: 879072 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
emergencyEtherTransfer(uint256) | 59057 | 59900 | 59900 | 60743 | 2 |
Expand All @@ -64,22 +70,25 @@ whoShouldReceiveFunds() | 2566 | 2566 | 2566 | 2566 | 1 |
exports[`lib > should generate a well formatted report with existing root & skip unchanged 1`] = `
"### [Create3Factory](https://github.com/src/contracts/create3/Create3Factory.sol)
- gas: 224263
- gas: 224263 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
create(bytes32,bytes) | <sup title="296388">↓-3.4%</sup>286388 | 296666 | 287062 | <sup title="297068">↑34%</sup>397068 | 6 |
### [TransparentProxyFactory](https://github.com/src/contracts/transparent-proxy/TransparentProxyFactory.sol)
- gas: 1609662
- gas: 1609662 / 49152
"
`;

exports[`lib > should generate a well formatted report with existing root 1`] = `
"### [Create3Factory](https://github.com/src/contracts/create3/Create3Factory.sol)
- gas: 224263
- gas: 224263 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
create(bytes32,bytes) | <sup title="296388">↓-3.4%</sup>286388 | 296666 | 287062 | <sup title="297068">↑34%</sup>397068 | 6 |
Expand All @@ -88,15 +97,17 @@ predictAddress(address,bytes32) | 1024 | 1024 | 1024 | 1024 | 6 |
### [ProxyAdmin](https://github.com/src/contracts/transparent-proxy/ProxyAdmin.sol)
- gas: 0
- gas: 0 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
owner() | 386 | 386 | 386 | 386 | 6 |
### [TransparentProxyFactory](https://github.com/src/contracts/transparent-proxy/TransparentProxyFactory.sol)
- gas: 1609662
- gas: 1609662 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
createDeterministic(address,address,bytes,bytes32) | 574115 | 534507 | 574589 | 574703 | 6 |
Expand All @@ -107,15 +118,17 @@ predictCreateDeterministicProxyAdmin(bytes32) | 6236 | 6236 | 6236 | 6236 | 6 |
### [TransparentUpgradeableProxy](https://github.com/src/contracts/transparent-proxy/TransparentUpgradeableProxy.sol)
- gas: 0
- gas: 0 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
getFoo() | 1042 | 1042 | 1042 | 1042 | 6 |
### [ImplOwnableWithGuardian](https://github.com/test/OwnableWithGuardian.t.sol)
- gas: 285211
- gas: 285211 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
guardian() | 2286 | 2286 | 2286 | 2286 | 1 |
Expand All @@ -125,7 +138,8 @@ updateGuardian(address) | 25944 | 28245 | 28283 | 30394 | 6 |
### [TestPermissionlessRescuable](https://github.com/test/PermissionlessRescuable.t.sol)
- gas: 879072
- gas: 879072 / 49152
| Method | min | mean | median | max | calls |
| --- | ---: | ---: | ---: | ---: | ---: |
emergencyEtherTransfer(uint256) | 59057 | 59900 | 59900 | 60743 | 2 |
Expand Down
8 changes: 2 additions & 6 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ function formatValue(before: number | undefined, after: number) {
).format(diff)}%</sup>${after}`;
}

function shouldBeSkipped(name: string) {
return /[mM]ock/.test(name);
}

export function getHtmlGasReport(
before: GasSnapshot,
after: GasSnapshot,
Expand All @@ -75,9 +71,9 @@ export function getHtmlGasReport(
)
return;
const [path, name] = item.contract.split(":");
if (shouldBeSkipped(name)) return;
content += `### [${name}](${options.rootUrl}${path})\n\n`;
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)}\n`;
// limit 49152
content += `- gas: ${formatValue(contractBefore?.deployment.gas, item.deployment.gas)} / 49152\n\n`;
// Commented out because it's not used atm.
// Not exactly sure if "gas" is helpful for anything.
// content += `- size: ${formatValue(contractBefore?.deployment.size, item.deployment.size)}\n\n`
Expand Down

0 comments on commit 758dac2

Please sign in to comment.