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

Fuzz Test Snapshotting Concept #1085

Closed
transmissions11 opened this issue Mar 28, 2022 · 6 comments
Closed

Fuzz Test Snapshotting Concept #1085

transmissions11 opened this issue Mar 28, 2022 · 6 comments
Labels
A-cheatcodes Area: cheatcodes A-testing Area: testing C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature

Comments

@transmissions11
Copy link
Contributor

transmissions11 commented Mar 28, 2022

Component

Forge

Describe the feature you would like

a cheatcode or config option that lets u specify a couple of specific inputs to snapshot for a fuzz test would be a repeatable and easy way to benchmark a fuzz tests' gas usage without introducing the variance that comes from mean/medians

here's what that could look like:

function testAdd(uint a, uint b) public {
    vm.snapshot(1, 2);
    vm.snapshot(10, 60);

    assertEq(a + b, b + a);
}

with a modifier it'd be really elegant:

modifier snapshot(uint256 a, uint256 b) {
    vm.snapshot(a, b)
}

function testAdd(uint a, uint b) public snapshot(1, 2) snapshot(10, 60) {
    assertEq(a + b, b + a);
}

could also use comment annotations but i know we dont rly like those

Additional context

related to my complaints in #1081

@transmissions11 transmissions11 added the T-feature Type: feature label Mar 28, 2022
@d-xo
Copy link

d-xo commented Mar 28, 2022

related: #858

@transmissions11
Copy link
Contributor Author

oh interesting @d-xo yeah seems like a lot of the functionality would be shared between them

@onbjerg onbjerg added A-testing Area: testing Cmd-forge-test Command: forge test C-forge Command: forge A-cheatcodes Area: cheatcodes labels Mar 28, 2022
@mds1
Copy link
Collaborator

mds1 commented Mar 28, 2022

In practice I think we'd have to do vm.snapshot(bytes memory) and ABI encode the params, cause there's basically infinite potential function signatures for fuzz tests

@transmissions11
Copy link
Contributor Author

yup agreed, and can have a console.log style lib as an abstraction on top

@onbjerg onbjerg added this to Foundry Apr 17, 2022
@onbjerg onbjerg moved this to Todo in Foundry Apr 17, 2022
@mds1
Copy link
Collaborator

mds1 commented Feb 26, 2023

@transmissions11 Is this worth keeping open? What is the use case for snapshotting only specific values, as opposed to concrete tests for some edge cases you may care about + deterministic seed with fuzz tests for the other cases?

@zerosnacks
Copy link
Member

@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes A-testing Area: testing C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Projects
Archived in project
Development

No branches or pull requests

5 participants