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

truffle-plugin
cgewecke 5 years ago
parent 7bc952c74f
commit 1d093e9732
  1. 17
      lib/parse.js
  2. 12
      test/sources/solidity/contracts/statements/interface.sol
  3. 5
      test/units/statements.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 => {

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

Loading…
Cancel
Save