diff --git a/lib/parse.js b/lib/parse.js index 27cabb2..ac16916 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -46,13 +46,13 @@ parse.ContractStatement = function ParseContractStatement(contract, expression) parse.ContractOrLibraryStatement = function parseContractOrLibraryStatement(contract, expression) { // From the start of this contract statement, find the first '{', and inject there. - const injectionPoint = expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2; + const injectionPoint = expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1; if (contract.injectionPoints[injectionPoint]) { - contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2].push({ + contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1].push({ type: 'eventDefinition', }); } else { - contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 2] = [{ + contract.injectionPoints[expression.start + contract.instrumented.slice(expression.start).indexOf('{') + 1] = [{ type: 'eventDefinition', }]; } diff --git a/test/sources/statements/empty-contract-ala-melonport.sol b/test/sources/statements/empty-contract-ala-melonport.sol new file mode 100644 index 0000000..80744e6 --- /dev/null +++ b/test/sources/statements/empty-contract-ala-melonport.sol @@ -0,0 +1,3 @@ +pragma solidity ^0.4.3; + +contract Test {} \ No newline at end of file diff --git a/test/sources/statements/empty-contract-body.sol b/test/sources/statements/empty-contract-body.sol index 2c26fa8..5c7f276 100644 --- a/test/sources/statements/empty-contract-body.sol +++ b/test/sources/statements/empty-contract-body.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.3; -contract Test { -} \ No newline at end of file +contract Test { +} + diff --git a/test/statements.js b/test/statements.js index de7f9c9..1a61db8 100644 --- a/test/statements.js +++ b/test/statements.js @@ -46,6 +46,14 @@ describe('generic statements', () => { const output = solc.compile(info.contract, 1); util.report(output.errors); }); + + it('should compile after instrumenting an empty-contract-body', () => { + const contract = util.getCode('statements/empty-contract-ala-melonport.sol'); + const info = getInstrumentedVersion(contract, filePath); + const output = solc.compile(info.contract, 1); + util.report(output.errors); + }); + it('should cover a statement following a close brace', done => { const contract = util.getCode('statements/post-close-brace.sol'); const info = getInstrumentedVersion(contract, filePath);