Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve state of the anvil fork after the test (forge test) has been completed #4033

Closed
KirillDogadin-std opened this issue Jan 4, 2023 · 1 comment
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature

Comments

@KirillDogadin-std
Copy link

Component

Forge

Describe the feature you would like

Being able to provide a flag to forge test command that turns off fork reset for every test. E.g. forge test --preserve-fork-state

Additional context

Thanks for the great project, we love the execution speed and the possibility to write concise solidity-based tests.

But according to the docs, the blockchain state is being reset between the tests, and it's not possible to overwrite this behaviour (via, let's say --preserve-state flag). The reason it will be helpful: to reuse solidity test code for other purposes.

  • Simple use-case: after executing one specific test the user connects to the (still running) anvil fork via RPC and validates something by hand. Useful for debugging frontend
  • Complex use-case: run hardhat tests on top of the state changes produced by the solidity test. Useful when execution parameters coming off-chain (i.e. routing data)

One other possible implementation of the same functionality would be via cheat codes that work inside anvil fork, but outside tests. E.g. a user deploys t.sol contract, then executes specific "test" function via RPC to reach desired state. There is no documentation on this, but according to our trials cheat codes don't work outside tests (i.e. when ran by foundry test)

Please let me know what you think about this functionality and if we're using it wrong!

@KirillDogadin-std KirillDogadin-std added the T-feature Type: feature label Jan 4, 2023
@rkrasiuk rkrasiuk added Cmd-forge-test Command: forge test C-forge Command: forge labels Jan 6, 2023
@zerosnacks
Copy link
Member

This would likely be achievable through vm.dumpState / anvil_dumpState: #4027 + foundry-rs/forge-std#499

Feel free to re-open if this is not the case

@zerosnacks zerosnacks closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

3 participants