JoinColony / solcover

Code coverage for solidity
MIT License
64 stars 8 forks source link

Instrumentation breaks constructor call chained to a method call #60

Closed cgewecke closed 7 years ago

cgewecke commented 7 years ago

This problem came up covering the ENS contracts. When a contract is instantiated using an address and one of its methods is immediately invoked by chaining - e.g:

contract Chainable {
    function chainWith(uint y, uint z){}
}

contract Test {
    function Test(){
        Chainable(0x00).chainWith(3, 4);
    }
}

the AST will have nested CallExpression nodes and the instrumenter will mistakenly inject two statement events:

function Test(){
__FunctionCoverageChainable('test.sol',3);
__CoverageChainable('test.sol',13);
         __StatementCoverageChainable('test.sol',3);
 __StatementCoverageChainable('test.sol',1);
Chainable().chainWith __StatementCoverageChainable('test.sol',2);
(3, 4);
    }
}

resulting in:

 Error: Instrumented solidity invalid: :27:27: Error: Expected token Semicolon got 'Identifier'
Chainable().chainWith __StatementCoverageChainable('test.sol',2);

Have a pushed a fix and compilation check unit test for this case to truffle3 branch with this commit

cgewecke commented 7 years ago

Previous fix needed another fix Was crashing on this line in the Chronobank SmartContracts repo:

_getAsset().__process.value(msg.value)(msg.data, msg.sender);

Have added some coverage tests for CallExpressions as well to try to make sure events are being injected correctly.

area commented 7 years ago

Fixed in solidity-coverage.