Skip to content

Improve modifer coverage report #286

@nventuro

Description

@nventuro

As of 0.5, modifers report being hit on their definition, but not at the call site. This is an issue because modifiers are mostly used to check preconditions e.g. onlyOwner, so not knowing if both branches of the require statements inside the modifiers were taken prevents developers from knowing if their test suite is thorough. For example, OpenZeppelin's Pausable is Ownable, but its tests fail to account for this (all transactions come from the owner account), and yet coverage is reported to be 100%.

Something we'd need to solve in order to implement this is deciding which line we should assign the coverage report to. If we can't indicate a range (e.g. line 4 columns 20 to 26), I think just pointing to the function declaration would be fine for now (though some extra logic would be needed for contracts with multiple modifiers).

Regarding instrumentation, I'm not completely sure. The main difficulty lies in that modifiers can be overridden and inherited, so we can't simply inline their body at the call site. Transforming them into internal functions would work, but that wouldn't solve the problem of not knowing if both require branches were taken (since all we'd see is the function call, not what happened inside of it). Ideas are welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions