Skip to content
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
10 changes: 9 additions & 1 deletion lib/registrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class Registrar {
this.modifierWhitelist = [];
}

_seekSemiColon(contract, pos) {
const end = pos + 5;
for(pos; pos <= end; pos++) {
if (contract[pos] === ';') break;
}
return pos;
}

/**
* Adds injection point to injection points map
* @param {Object} contract instrumentation target
Expand Down Expand Up @@ -441,7 +449,7 @@ class Registrar {
);
this._createInjectionPoint(
contract,
expression.range[1] + 2,
this._seekSemiColon(contract.instrumented, expression.range[1] + 1) + 1,
{
type: 'injectRequirePost',
branchId: contract.branchId,
Expand Down
9 changes: 9 additions & 0 deletions test/sources/solidity/contracts/statements/require.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity >=0.8.0 <0.9.0;

contract Test {
function a(uint x) public {
require(true);
require(true) ;
require(true) ;
}
}
5 changes: 5 additions & 0 deletions test/units/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ describe('generic statements', () => {
util.report(info.solcOutput.errors);
});

it('should instrument require statements when semi-colon is separated by spaces', () => {
const info = util.instrumentAndCompile('statements/require');
util.report(info.solcOutput.errors);
});

it('should cover an emitted event statement', async function() {
const contract = await util.bootstrapCoverage('statements/emit-coverage', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
Expand Down