Instrument modifiers correctly

leapdao
Alex 6 years ago
parent db4989c5e8
commit b57c8e5122
  1. 2
      lib/parse.js
  2. 23
      test/function.js
  3. 11
      test/sources/function/modifier.sol

@ -130,7 +130,7 @@ parse.Modifiers = function parseModifier(contract, modifiers) {
}
};
parse.ModifierDeclaration = function parseModifierDeclaration(contract, expression) {
parse.ModifierDefinition = function parseModifierDefinition(contract, expression) {
instrumenter.instrumentFunctionDeclaration(contract, expression);
parse[expression.body.type] &&
parse[expression.body.type](contract, expression.body);

@ -96,6 +96,29 @@ describe('function declarations', () => {
}).catch(done);
});
it('should cover a modifier used on a function', done => {
const contract = util.getCode('function/modifier.sol');
const info = getInstrumentedVersion(contract, filePath);
const coverage = new CoverageMap();
coverage.addContract(info, filePath);
vm.execute(info.contract, 'a', [0]).then(events => {
const mapping = coverage.generate(events, pathPrefix);
assert.deepEqual(mapping[filePath].l, {
5: 1, 6: 1, 9: 1,
});
assert.deepEqual(mapping[filePath].b, {});
assert.deepEqual(mapping[filePath].s, {
1: 1
});
assert.deepEqual(mapping[filePath].f, {
1: 1,
2: 1,
});
done();
}).catch(done);
});
it('should cover a constructor that uses the `constructor` keyword', done => {
const contract = util.getCode('function/constructor-keyword.sol');
const info = getInstrumentedVersion(contract, filePath);

@ -0,0 +1,11 @@
pragma solidity ^0.5.0;
contract Test {
modifier b(){
uint y;
_;
}
function a(uint x) b public {
x;
}
}
Loading…
Cancel
Save