Skip to content

Commit

Permalink
Tolerate whitespace between require and terminating ; (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Apr 5, 2024
1 parent 09a7c83 commit 4f5626d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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

0 comments on commit 4f5626d

Please sign in to comment.