diff --git a/lib/registrar.js b/lib/registrar.js index f44af4f..0e3081f 100644 --- a/lib/registrar.js +++ b/lib/registrar.js @@ -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 @@ -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, diff --git a/test/sources/solidity/contracts/statements/require.sol b/test/sources/solidity/contracts/statements/require.sol new file mode 100644 index 0000000..1cdd22b --- /dev/null +++ b/test/sources/solidity/contracts/statements/require.sol @@ -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) ; + } +} diff --git a/test/units/statements.js b/test/units/statements.js index 5120250..c908d74 100644 --- a/test/units/statements.js +++ b/test/units/statements.js @@ -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);