There was a small nuance in the Foundry tests that should be considered when working with transient storage and Dencun update.
Here is a detailed review of it:
Lets write a couple of contracts. There are the simplest to show you an example of how transient storage works. In general, data is stored in a contract storage during a tx and cleared right after it.
By the way, you should update Foundry before writing tests, as it should use the Cancun upgrade and the 0.8.25 Solidity version
Now we can write a test to check if transient storage is cleared after the tx and contract storage slot is ready to be used for other data
The contract code is correct, so is the test code. However, if we run
`forge test -vvvv`
we'll see this
Test failed! But wtf?! Why it failed?!
The answer is simple and it is in the EIP-1153: "transient storage... is discarded after every transaction". In other words our function calls in test_CallMe() are not done after main.callMe(). So the transient storage remains!
So, we need to isolate tx from each other in our test. Luckily, Foundry is awesome and we can run a command:
`forge test -vvvv -isolate`
And "Boom!", it passed! Now you know how to work with transient storage in your Foundry tests!
Share and spread the knowledge!
#foundry
#transient
#storage
Completely free courses
Learn more about the blockchain world
Free education videos
by RareSkills
by Jeiwan
by RareSkills
by RareSkills
by Andreas M. Antonopoulos, Gavin Wood
by Micah Dameron
Compare execution layer differences between chains
Dive deep into the storage of any contract