Stop injecting coverage hash fn definition in interfaces (#383)

pull/385/head
cgewecke 5 years ago committed by GitHub
parent 31bbf10598
commit ccb7bcf358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      lib/parse.js
  2. 12
      test/sources/solidity/contracts/statements/interface.sol
  3. 5
      test/units/statements.js

@ -51,8 +51,10 @@ parse.ContractDefinition = function(contract, expression) {
}; };
parse.ContractOrLibraryStatement = function(contract, expression) { parse.ContractOrLibraryStatement = function(contract, expression) {
// We need to define a method to pass coverage hashes into at top of each contract. // 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. // This lets us get a fresh stack for the hash and avoid stack-too-deep errors.
if (expression.kind !== 'interface'){
const start = expression.range[0]; const start = expression.range[0];
const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1; const end = contract.instrumented.slice(expression.range[0]).indexOf('{') + 1;
const loc = start + end;; const loc = start + end;;
@ -60,6 +62,7 @@ parse.ContractOrLibraryStatement = function(contract, expression) {
(contract.injectionPoints[loc]) (contract.injectionPoints[loc])
? contract.injectionPoints[loc].push({ type: 'injectHashMethod'}) ? contract.injectionPoints[loc].push({ type: 'injectHashMethod'})
: contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}]; : contract.injectionPoints[loc] = [{ type: 'injectHashMethod'}];
}
if (expression.subNodes) { if (expression.subNodes) {
expression.subNodes.forEach(construct => { expression.subNodes.forEach(construct => {

@ -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;
}

@ -53,6 +53,11 @@ describe('generic statements', () => {
util.report(info.solcOutput.errors); 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', () => { it('should NOT pass tests if the contract has a compilation error', () => {
const info = util.instrumentAndCompile('app/SimpleError'); const info = util.instrumentAndCompile('app/SimpleError');
try { try {

Loading…
Cancel
Save