foundry-rs / book

A book on all things Foundry, available at https://book.getfoundry.sh.
https://book.getfoundry.sh
Apache License 2.0
777 stars 613 forks source link

docs: document best practices of measuring gas when using transient storage #1289

Open JoseMiguelHerrera opened 3 months ago

JoseMiguelHerrera commented 3 months ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (c2e5297 2024-06-14T00:22:57.565836000Z)

What command(s) is the bug in?

forge test --gas-report

Operating System

macOS (Intel)

Describe the bug

I'm using transient storage for context setting. Just before the function ends, I expect there to be some context in transient storage that I can fetch. This behaviour is working perfectly when I test with "forge test".

However, when I check with forge test --gas-report, the transient storage is empty, as if it has been cleared or never written at all.

What is so different between these 2 modes of operation that would cause this?

Cheers

klkvr commented 3 months ago

since https://github.com/foundry-rs/foundry/pull/7186 --gas-report enables isolation by default. You can verify that by comparing forge test --isolate and forge test --gas-report outputs

JoseMiguelHerrera commented 3 months ago

since foundry-rs/foundry#7186 --gas-report enables isolation by default. You can verify that by comparing forge test --isolate and forge test --gas-report outputs

Thanks, makes sense. So what's the best practice to test features that use transient storage?

zerosnacks commented 2 months ago

Transformed this ticket into a documentation ticket aiming to document best practices in regards to transient storage + gas snapshots