You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Contracts Bar and Foo are identical in terms of what they are doing, the difference is whether the security check is done in the function modifier or not.
This set of tests doesn't include "try calling as not owner" tests.
contractFoobarTestisTest {
event BarEvent();
event FooEvent();
Foo internal foo;
Bar internal bar;
function setUp() public {
foo =newFoo();
bar =newBar();
}
function testFooAsOwner() public {
vm.expectEmit(true, true, true, true);
emitFooEvent();
foo.foo();
}
function testBarAsOwner() public {
vm.expectEmit(true, true, true, true);
emitBarEvent();
bar.bar();
}
}
Coverage
As you can see, the coverage report hints that the Bar tests are incomplete, but for Foo there's no way to tell that. The coverage for Ownable is missing entirely (contract being non abstract doesn't change anything).
Expected coverage
What I was hoping to see? Ideally, if a function has a few modifiers, the coverage report should not differ too much from the very same function rewritten without any modifiers. Meaning that coverage should give me a clue as to whether the tests are covering not only all branches within the function, but within its modifiers as well.
@rkrasiuk any update for this? I wasn't able to find any good solution to this, and ensuring that the tests cover all functions with "security" modifiers like onlyOwner is kind of crucial.
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (28312e7 2022-10-13T00:10:05.477412592Z)
What command(s) is the bug in?
forge coverage
Operating System
Linux
Describe the bug
Contract example
Contracts
Bar
andFoo
are identical in terms of what they are doing, the difference is whether the security check is done in the function modifier or not.Full example is available here: https://github.com/ChiTimesChi/coverage-modifier
Tests example
This set of tests doesn't include "try calling as not owner" tests.
Coverage
As you can see, the coverage report hints that the
Bar
tests are incomplete, but forFoo
there's no way to tell that. The coverage forOwnable
is missing entirely (contract being non abstract doesn't change anything).Expected coverage
What I was hoping to see? Ideally, if a function has a few modifiers, the coverage report should not differ too much from the very same function rewritten without any modifiers. Meaning that coverage should give me a clue as to whether the tests are covering not only all branches within the function, but within its modifiers as well.
sc-forks/solidity-coverage#286 is a good read as well.
The text was updated successfully, but these errors were encountered: