Skip to main content
The Hooks Trampoline testing framework uses Foundry to verify contract behavior including gas limits, hook reverts, and settlement protection.

Running Tests

Execute all tests:
Run with verbose output and stack traces:

Test Organization

The test suite is organized into two primary test contracts: The main test setup deploys a trampoline with a mock settlement address:

Core Test Scenarios

Authorization Verification

The trampoline rejects calls from non-settlement addresses:

Gas Allocation

Tests confirm hooks receive their specified gas allowances using a GasRecorder helper contract:

Revert Tolerance

Multiple hooks execute sequentially even when individual hooks fail:

Sequential Execution

Hook ordering is enforced through a CallInOrder helper:

Out-of-Gas Protection

The trampoline limits gas usage to approximately the specified amount plus call overhead:

Helper Contracts

The test suite uses several mock contracts:

Writing Custom Hook Tests

1

Create test contract

Inherit from forge-std/Test.sol:
2

Deploy hook in setUp

3

Build hook arrays

4

Execute via settlement context

Always use vm.prank(settlement) before calling execute():
5

Verify state and gas

6

Test authorization

If your hook validates msg.sender:

Gas Testing Constants

Key values used in gas calculations:

Best Practices

Call execute() from the settlement address using vm.prank(settlement). Direct calls will revert with NotASettlement.
Verify behavior when hooks don’t receive enough gas. The trampoline should revert by consuming all remaining gas.
Test that a reverting hook doesn’t prevent subsequent hooks from executing.
Use helper contracts like CallInOrder to verify hooks execute in the correct order.
Create focused mock contracts that test specific behaviors rather than complex multi-purpose mocks.
Test authorization failures, out-of-gas conditions, empty hook arrays, and hooks targeting EOAs.
Last modified on March 4, 2026