balancer / balancer-v3-monorepo

GNU General Public License v3.0
38 stars 10 forks source link

Alternate test for BaseHooks #774

Closed EndymionJkb closed 2 months ago

EndymionJkb commented 2 months ago

Description

Based on #772, which ensures modifiers on hook examples, this provides a way to meaningfully test BaseHooks.

This PR:

1) Moves HookFlags from inside the IHooks interface to VaultTypes. I can see both sides here, but I don't think it's best practice generally to define structs inside interfaces (especially if widely used), and putting it next to HooksConfig makes it really clear that the HooksConfig = HookFlags + hook contract address, and we can visually inspect to ensure they don't start diverging.

2) Leaves BaseHooks abstract, but changes the visibility of the hook functions from external to public, so that derived contracts can call them.

3) Creates a BaseHooksMock concrete contract that overrides all the hook functions and calls the base class. The corresponding test ensures that BaseHooks functions all return false. We're checking here that if a misconfigured hook contract doesn't define a given hook, and the Vault calls it, it will fall back on BaseHooks and return false/revert.

It doesn't really make sense to test onlyVault constraints here, as real hook contracts will not be calling the base contract functions, so the modifiers would never be executed. onlyVault constraints have to be tested at the most derived level (e.g., in the tests for the example hook contracts).

Type of change

Checklist:

Issue Resolution