-
Notifications
You must be signed in to change notification settings - Fork 40
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
Coverage Data #20
Comments
https://github.com/sc-forks/solidity-coverage might be a good one to use. More importantly, many major smart contract projects have already implemented the coverage generation script for running it automatically end-to-end. |
@yxliang01 would it be possible to use this tool to get coverage information for each specifc unit test? |
@JoranHonig As far as I know, no. But, do we really need to get the coverage for each unit test? |
I believe that the intention is to only run tests during a mutation that touch the line you're mutating. There may be others, but I'm not familiar with mutation testing in general to be able to comment if there are cleverer improvements beyond that. I agree this is not something that can currently be done with |
@area This is exactly the optimisation that I'm aiming for. If such a feature could be provided by |
I see. But, I feel one thing could possibly already be done is to get the coverage data for one test file by isolating it from others. |
@yxliang01 True. We might also be able to leverage Mocha's grep functionality to execute singular tests. |
The new coverage client continuously updates an in-memory map of
This actually might be the simplest thing to do. The only drawback could be that in practice each file can have many tests. On the other hand, they're often related to the same code. Incidentally, this topic once came up at solidity-coverage in relation to other research in issue 209. In that case, the engineer was trying to do risk assessment based on an academic paper which IIRC suggests you can narrow the field of audit inquiry by looking at how many tests touch a given line of code. It's called the Tarantula Automatic Fault-Localization Technique. (So you might get a 2-for-1 if you build this plus This Week In Ethereum lists/highlights all security related projects with the word 'tarantula' in their title.) |
Hi @cgewecke, Thanks for the extensive response!
Assuming that I can find a cheap way to list all the tests in the project, I could execute a single one of those tests by adding something like
That's very interesting! I'm not opposed to extending Vertigo with a command that allows you to do fault localisation. Ps. Were you planning to extend solidity-coverage to report the coverage per unit test? |
Oh ok, that's great! I will tentatively add tests/line to the work scheduled for solidity-coverage - suspect there might be a number of uses for that data set. May be a bit before it gets done, I'm slightly over-subscribed at the moment. |
@cgewecke You meant you plan to implement reporting coverage per unit test? |
I was thinking something more like:
which would produce an object like: [
FileName.sol: {
8: ['it errors when called by alice', 'it can set an owner'],
13: ['it etc...' ]
},
AnotherFile.sol: {...},
] This data would just be an input that mutation testing and fault localization strategies could use. What are you thinking of? |
@cgewecke Hmm, if we simply get the test description, it's not enough to do fault localization though. I would expect there are repeated names. But, if we can ensure the fact that one test case can only maximally add 1 element onto the array, then this is good enough.e |
@yxliang01 Ah! Some questions...
We can definitely deduplicate the names in the array, that's a good point. |
|
The filename is definitely available within the mocha reporter, but is there a safe way of combining the path and the test descr into one string without potentially making it difficult to isolate the grep-able piece? What do you think about an array of objects there? {
FileName.sol: {
8: [
{
test: 'it errors when called by alice',
file: '/Users/area/code/tests/alice.js'
}, ...
], ...
},
AnotherFile.sol: {...},
} |
@cgewecke Ok, now this object looks really better. But, as suggested, there might be tests with the same description. I can think of two ways to deal with this. For one combination of test file path and test description, we assign a counter which will be incremented whenever we see one test case with such combination execute. This also essentially saying that if in one |
I believe each test has a title and fullTitle. In this case I would think that it makes sense to use full title , because it is more precise (less collisions possible). |
Just leaving an example of what things look like inside the mocha reporter. reporter's 'test' hook (for runner.on("test", info => {
} info (much abbreviated) info: {
suite: {
title: 'Contract: EtherRouter Proxy',
file: '/Users/cgewecke/code/eth-gas-reporter/mock/test/etherrouter.js'
},
test: {
"title": "Resolves methods routed through an EtherRouter proxy",
"file": "/Users/cgewecke/code/eth-gas-reporter/mock/test/etherrouter.js",
}
}, @yxliang01 @JoranHonig When I start working on this I will ping you for review so we can get everything exactly right for your purposes. |
For many mutation testing optimisations it is required / helpful if we have code coverage information.
Specifically we need to be able to determine which tests cover specific lines of code.
The text was updated successfully, but these errors were encountered: