Skip to content
Discussion options

You must be logged in to vote

Not in the “deploy once for the whole test file” sense. In Forge’s normal Solidity test model, setUp() runs before each test, so each test gets its own setup phase. The state snapshot cheatcodes are for snapshotting and restoring EVM state inside a test execution context; they are not a cross-test fixture cache that survives into the next test.

So this works for branching inside one test:

function test_manyBranches() public {
    uint256 snap = vm.snapshotState();

    // branch A
    // ...

    vm.revertToState(snap);

    // branch B from the same setup state
    // ...
}

but it is not a way to do:

deploy once -> run 40 independent test functions from that deployed state

If the expens…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sigittt1998
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants