From 3718efd7adaf952ba3fa73f4eeaf36cfaf85dc38 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 5 Sep 2019 22:10:09 -0700 Subject: [PATCH 1/2] Stop injecting coverage hash fn definition in interfaces --- lib/parse.js | 18 +++++++++++------- .../contracts/statements/interface.sol | 12 ++++++++++++ test/units/statements.js | 5 +++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 test/sources/solidity/contracts/statements/interface.sol diff --git a/lib/parse.js b/lib/parse.js index d2e71d23..8418d0ff 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -5,6 +5,7 @@ */ const Registrar = require('./registrar'); const register = new Registrar(); +const util = require('util'); const parse = {}; @@ -51,15 +52,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 00000000..c039daf0 --- /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 c5e9e474..ef3ee0de 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 { From 5d01e7ad5d010893ed2e0643e10ec00292e89e5d Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 5 Sep 2019 22:19:17 -0700 Subject: [PATCH 2/2] Remove debugging line --- lib/parse.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 8418d0ff..c2089d73 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -5,7 +5,6 @@ */ const Registrar = require('./registrar'); const register = new Registrar(); -const util = require('util'); const parse = {};