From ccb7bcf358bf4e2c2f50c3c4f4f5378c8a5bd95c Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 5 Sep 2019 22:23:35 -0700 Subject: [PATCH] Stop injecting coverage hash fn definition in interfaces (#383) --- lib/parse.js | 17 ++++++++++------- .../solidity/contracts/statements/interface.sol | 12 ++++++++++++ test/units/statements.js | 5 +++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 test/sources/solidity/contracts/statements/interface.sol diff --git a/lib/parse.js b/lib/parse.js index d2e71d2..c2089d7 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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 => { diff --git a/test/sources/solidity/contracts/statements/interface.sol b/test/sources/solidity/contracts/statements/interface.sol new file mode 100644 index 0000000..c039daf --- /dev/null +++ b/test/sources/solidity/contracts/statements/interface.sol @@ -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; +} \ No newline at end of file diff --git a/test/units/statements.js b/test/units/statements.js index c5e9e47..ef3ee0d 100644 --- a/test/units/statements.js +++ b/test/units/statements.js @@ -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 {