Once I posted a note of how to manage different users addresses in your Foundry tests.
And today, in PoolTogether contest on Code4rena, I saw another interesting way to manage prank() calls from different users / roles in a single function.
Imagine the situation in a function where you need to switch a call to another user, perform an action, and then return to the initial user to hold the rest of the function calls.
For example:
We can easily do it with prank() / startPrank() / stopPrank() / hoax(), but we end up with a bunch of code lines that could clutter up out test.
Here is what PoolTogether team did.
Create a modifier that will change users:
Now you can add some internal functions with actions that you want another user to perform:
Finally, you can include this function within another to provide a test.
I like how clear and easy to understand this test could be, with all the unnecessary Foundry cheat codes in the modifier!
Great job, PoolTogether team
#foundry
#prank
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