Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop injecting coverage hash fn definition in interfaces #383

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 12 additions & 0 deletions test/sources/solidity/contracts/statements/interface.sol
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 5 additions & 0 deletions test/units/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down