forge-std icon indicating copy to clipboard operation
forge-std copied to clipboard

Meta: Unbundling the cheats from the assertions (leg 2)

Open PaulRBerg opened this issue 3 years ago • 1 comments

Description

This is the 2nd leg of my proposal to unbundle the cheats from the assertions. Here I'll assume that you have read the 1st leg.

The fact that the custom cheats are added in the same namespace as the testing assertions has two inconveniences.

  1. The API is inconsistent. Users need to remember that certain cheats are available only via the vm variable, while others are to be found in the default namespace of Test. For example, vm.startPrank and changePrank.
  2. Namespace pollution. Users may prefer to implement their own versions of, say, the bound function. This is what happened in https://github.com/foundry-rs/forge-std/pull/92.

Solution

Instead of inheriting from Cheats in Test, we create an instance of Cheats in Test:

contract Test {
    Cheats internal cheats;
}

The vm would have to be re-instantiated in Test, but IMO that's a fair price to pay.

This way, users would know that all custom cheats offered by Forge Std are available only via cheats, and the namespace would be tidier.

PaulRBerg avatar Jul 15 '22 13:07 PaulRBerg

I have begun working on this on the refactor-cheats-2 branch of my fork, but it's not done yet (I couldn't get the prank tests to pass). Happy to open a PR so we can discuss the issues I stumbled upon if there is interest for making this proposed change.

PaulRBerg avatar Jul 15 '22 13:07 PaulRBerg