balancer-v2-monorepo
balancer-v2-monorepo copied to clipboard
Foundry gas reporting
This adds yarn tasks for measuring and reporting gas in Foundry tests. It only works when there is a deployed contract; hence changes to use existing Mock contracts instead of calling the library directly. (ManagedPoolStorageLib tests could be covered if there were a Mock for it.)
yarn test-gas
runs the gas report on the Foundry test functions.
yarn test-snapshot-gas
creates a .gas-snapshot file with current results
yarn test-snapshot-gas --diff
runs tests and compares them to the stored .snapshot, letting you see any changes (e.g., if you're testing to see whether a given change saves gas).
You can control what the gas report covers with the gas_reports
option in foundry.toml:
gas_reports = ["*"]
tests everything, which seems to be the default, so I don't think we need to change anything in the .toml files unless we have a reason to exclude something.
Should we update CI to check that these snapshots are kept up to date?
It only works when there is a deployed contract; hence changes to use existing Mock contracts instead of calling the library directly. (ManagedPoolStorageLib tests could be covered if there were a Mock for it.)
Is this really the case? I'm getting snapshots for tests even if they have no mocks.
Can our settings be different somehow? I get no output without a mock.
Closed for lack of interest