morpho-org / morpho-utils

Repository gathering useful libraries and contracts.
GNU Affero General Public License v3.0
65 stars 1 forks source link

Extract fuzzing test branches to separate, pre-assumed fuzzing test #27

Closed Rubilmax closed 1 year ago

Rubilmax commented 1 year ago

Basically extract every:

function test(uint256 blabla) {
    if (condition) {
        expect(expectation1);
    } else {
        expect(expectation2);
    }
}

to:

function testWhenCondition(uint256 blabla) {
    vm.assume(condition);
    expect(expectation1);
}

function testWhenNotCondition(uint256 blabla) {
    vm.assume(!condition);
    expect(expectation2);
}
QGarchery commented 1 year ago

Why ? Isn't it less efficient ?

MathisGD commented 1 year ago

It is, because we do more iteration in total. But as fuzzing inputs are a « black box », testing each branches with a if else does not ensure that those branches has been tested. With one fuzzing test with an assume per branch, we know that each of them has been fuzzed.