balancer-v2-monorepo icon indicating copy to clipboard operation
balancer-v2-monorepo copied to clipboard

Foundry gas reporting

Open EndymionJkb opened this issue 2 years ago • 2 comments

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.

EndymionJkb avatar Sep 20 '22 16:09 EndymionJkb

Should we update CI to check that these snapshots are kept up to date?

TomAFrench avatar Sep 20 '22 18:09 TomAFrench

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.

EndymionJkb avatar Sep 22 '22 13:09 EndymionJkb

Closed for lack of interest

EndymionJkb avatar Sep 29 '22 17:09 EndymionJkb