Skip to content

Commit

Permalink
Stop injecting coverage hash fn definition in interfaces (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Sep 25, 2019
1 parent 7bc952c commit 1d093e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ parse.ContractDefinition = function(contract, expression) {
};

parse.ContractOrLibraryStatement = function(contract, expression) {

// We need to define a method to pass coverage hashes into at top of each contract.
// This lets us get a fresh stack for the hash and avoid stack-too-deep errors.
const start = expression.range[0];
const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1;
const loc = start + end;;

(contract.injectionPoints[loc])
? contract.injectionPoints[loc].push({ type: 'injectHashMethod'})
: contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}];
if (expression.kind !== 'interface'){
const start = expression.range[0];
const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1;
const loc = start + end;;

(contract.injectionPoints[loc])
? contract.injectionPoints[loc].push({ type: 'injectHashMethod'})
: contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}];
}

if (expression.subNodes) {
expression.subNodes.forEach(construct => {
Expand Down
12 changes: 12 additions & 0 deletions test/sources/solidity/contracts/statements/interface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity ^0.5.8;

interface IInterface {
event Assign(address indexed token, address indexed from, address indexed to, uint256 amount);
event Withdraw(address indexed token, address indexed from, address indexed to, uint256 amount);

// TODO: remove init from the interface, all the initialization should be outside the court
function init(address _owner) external;

function assign(uint _token, address _to, uint256 _amount) external;
function withdraw(uint _token, address _to, uint256 _amount) external;
}
5 changes: 5 additions & 0 deletions test/units/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ describe('generic statements', () => {
util.report(info.solcOutput.errors);
});

it('should instrument an interface contract', () => {
const info = util.instrumentAndCompile('statements/interface');
util.report(info.solcOutput.errors);
})

it('should NOT pass tests if the contract has a compilation error', () => {
const info = util.instrumentAndCompile('app/SimpleError');
try {
Expand Down

0 comments on commit 1d093e9

Please sign in to comment.