Merge pull request #58 from sc-forks/empty-contract-bug

Instrument empty contract bodies correctly
pull/61/head
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 1c90205c15
  1. 6
      lib/parse.js
  2. 3
      test/sources/statements/empty-contract-ala-melonport.sol
  3. 5
      test/sources/statements/empty-contract-body.sol
  4. 8
      test/statements.js

@ -46,13 +46,13 @@ parse.ContractStatement = function ParseContractStatement(contract, expression)
parse.ContractOrLibraryStatement = function parseContractOrLibraryStatement(contract, expression) { parse.ContractOrLibraryStatement = function parseContractOrLibraryStatement(contract, expression) {
// From the start of this contract statement, find the first '{', and inject there. // 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]) { 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', type: 'eventDefinition',
}); });
} else { } 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', type: 'eventDefinition',
}]; }];
} }

@ -0,0 +1,3 @@
pragma solidity ^0.4.3;
contract Test {}

@ -1,4 +1,5 @@
pragma solidity ^0.4.3; pragma solidity ^0.4.3;
contract Test { contract Test {
} }

@ -46,6 +46,14 @@ describe('generic statements', () => {
const output = solc.compile(info.contract, 1); const output = solc.compile(info.contract, 1);
util.report(output.errors); 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 => { it('should cover a statement following a close brace', done => {
const contract = util.getCode('statements/post-close-brace.sol'); const contract = util.getCode('statements/post-close-brace.sol');
const info = getInstrumentedVersion(contract, filePath); const info = getInstrumentedVersion(contract, filePath);

Loading…
Cancel
Save