Skip to content

Commit ccb7bcf

Browse files
authored
Stop injecting coverage hash fn definition in interfaces (#383)
1 parent 31bbf10 commit ccb7bcf

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

lib/parse.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ parse.ContractDefinition = function(contract, expression) {
5151
};
5252

5353
parse.ContractOrLibraryStatement = function(contract, expression) {
54+
5455
// We need to define a method to pass coverage hashes into at top of each contract.
5556
// This lets us get a fresh stack for the hash and avoid stack-too-deep errors.
56-
const start = expression.range[0];
57-
const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1;
58-
const loc = start + end;;
59-
60-
(contract.injectionPoints[loc])
61-
? contract.injectionPoints[loc].push({ type: 'injectHashMethod'})
62-
: contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}];
57+
if (expression.kind !== 'interface'){
58+
const start = expression.range[0];
59+
const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1;
60+
const loc = start + end;;
61+
62+
(contract.injectionPoints[loc])
63+
? contract.injectionPoints[loc].push({ type: 'injectHashMethod'})
64+
: contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}];
65+
}
6366

6467
if (expression.subNodes) {
6568
expression.subNodes.forEach(construct => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pragma solidity ^0.5.8;
2+
3+
interface IInterface {
4+
event Assign(address indexed token, address indexed from, address indexed to, uint256 amount);
5+
event Withdraw(address indexed token, address indexed from, address indexed to, uint256 amount);
6+
7+
// TODO: remove init from the interface, all the initialization should be outside the court
8+
function init(address _owner) external;
9+
10+
function assign(uint _token, address _to, uint256 _amount) external;
11+
function withdraw(uint _token, address _to, uint256 _amount) external;
12+
}

test/units/statements.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ describe('generic statements', () => {
5353
util.report(info.solcOutput.errors);
5454
});
5555

56+
it('should instrument an interface contract', () => {
57+
const info = util.instrumentAndCompile('statements/interface');
58+
util.report(info.solcOutput.errors);
59+
})
60+
5661
it('should NOT pass tests if the contract has a compilation error', () => {
5762
const info = util.instrumentAndCompile('app/SimpleError');
5863
try {

0 commit comments

Comments
 (0)