Block: 58

Timestamp: 12:45:39

AuditProfile

Security blog

Managing prank() calls in Foundry

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

Connent with me:

Регистрация прошла успешно! Спасибо за внимание!

loader