Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): add gas reports for tests #637

Merged
merged 5 commits into from
Jan 30, 2022
Merged

Conversation

brockelmore
Copy link
Member

@brockelmore brockelmore commented Jan 30, 2022

Adds --gas-report flag to forge test.

Adds gas_reports into foundry.toml which lets the user specify which contracts they want gas reports for, i.e:

gas_reports = ["MyContract", "MyContractFactory"]

or to produce a report for everything:

gas_reports = ["*"]

then if the user does forge test --gas-report they will get an output like:
image

Note: the colors you see here are a bit different than what may show up for you. My terminal theme is a bit off and it shows green as yellow and yellow as green.

Partially addresses #137

@brockelmore brockelmore added the T-feature Type: feature label Jan 30, 2022
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

@brockelmore
Copy link
Member Author

note: we dont current include calldata costs in this snapshot - we could change how we calculate gas in call traces to include calldata costs to make it more realistic for an EOA to call a function

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another banger by brock
image

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

cli/src/cmd/test.rs Show resolved Hide resolved
evm-adapters/src/gas_report.rs Outdated Show resolved Hide resolved
@fubhy
Copy link
Contributor

fubhy commented Jan 30, 2022

Awesome. I think it may be useful to also include the name of the test that caused the max gas cost. Would that be easy to add as a column?

@brockelmore
Copy link
Member Author

Awesome. I think it may be useful to also include the name of the test that caused the max gas cost. Would that be easy to add as a column?

ye just keep parent CallArenaTrace decoded function name in the GasReport and replace as you see a max value. I don't want to support this right now though because thats actually a slightly different usecase than high level gas usage reports

@brockelmore brockelmore merged commit 46327e2 into master Jan 30, 2022
@brockelmore brockelmore deleted the brock/gas_reports branch January 30, 2022 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants