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 vm.lastCallGas cheatcode #7573

Merged
merged 35 commits into from
Apr 8, 2024

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Apr 5, 2024

Motivation

Closes #7272

Solution

  • Add the lastCallGas cheatcode, primarily to be used in isolation mode for accurate measurements.
  • Adds exclude_contracts to test filter
  • Returns a Gas struct instead of proposed uint256, with details like gas spend on memory and gas refunds

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.

this looks clean, only have one comment re name,

wdyt @klkvr ?

crates/cheatcodes/spec/src/vm.rs Outdated Show resolved Hide resolved
@mds1
Copy link
Collaborator

mds1 commented Apr 5, 2024

Before merge let's make sure this feature is actually the best solution to the problem, ref #7272 (comment)

crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
crates/forge/tests/it/isolate.rs Outdated Show resolved Hide resolved
testdata/default/isolation/RecordGas.t.sol Outdated Show resolved Hide resolved
crates/cheatcodes/src/evm.rs Outdated Show resolved Hide resolved
@klkvr
Copy link
Member

klkvr commented Apr 5, 2024

Can't we make this work for non-isolated tests as well?

@zerosnacks zerosnacks changed the title feat(forge): add vm.lastGasUsed cheatcode feat(forge): add vm.lastCallGas cheatcode Apr 8, 2024
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

excited to see this, i think it's going to be pretty useful. nits:

crates/cheatcodes/src/evm.rs Outdated Show resolved Hide resolved
crates/forge/tests/it/test_helpers.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/evm.rs Outdated Show resolved Hide resolved
@zerosnacks zerosnacks marked this pull request as ready for review April 8, 2024 11:27
Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

nice work! lgtm overall, would like to improve tests for this a bit

testdata/default/cheats/LastCallGas.t.sol Outdated Show resolved Hide resolved
…ment subset of cheats that require to be tested in isolation mode as well
…est filter, not just individual tests or paths
Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

tests look great, lgtm

@zerosnacks zerosnacks merged commit b88d167 into master Apr 8, 2024
19 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/add-vm-lastGasUsed branch April 8, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a lastGasUsed() function in Vm.sol
5 participants