Allow duplicate modifiers on same function (#596)

experimental-options
cgewecke 4 years ago
parent 23f798792b
commit 2be29b2edb
  1. 5
      lib/injector.js
  2. 15
      test/sources/solidity/contracts/modifiers/duplicate-mods-same-fn.sol
  3. 17
      test/units/modifiers.js

@ -3,6 +3,7 @@ const web3Utils = require("web3-utils");
class Injector { class Injector {
constructor(){ constructor(){
this.hashCounter = 0; this.hashCounter = 0;
this.modifierCounter = 0;
this.modifiers = {}; this.modifiers = {};
} }
@ -370,11 +371,13 @@ class Injector {
} }
injectModifier(contract, fileName, injectionPoint, injection, instrumentation){ injectModifier(contract, fileName, injectionPoint, injection, instrumentation){
this.modifierCounter++;
const type = 'modifier'; const type = 'modifier';
const contractId = `${fileName}:${injection.contractName}`; const contractId = `${fileName}:${injection.contractName}`;
const modifierId = `${fileName}:${injection.contractName}:` + const modifierId = `${fileName}:${injection.contractName}:` +
`${injection.modifierName}:${injection.fnId}:` + `${injection.modifierName}:${injection.fnId}:` +
`${injection.condition}`; `${injection.condition}:${this.modifierCounter}`;
const { const {
start, start,

@ -0,0 +1,15 @@
pragma solidity ^0.7.0;
contract Test {
modifier m(string memory val) {
_;
}
function a()
m('ETH')
m('BTC')
public
{
uint x = 5;
}
}

@ -216,6 +216,23 @@ describe('modifiers', () => {
}); });
}); });
it('should cover when same modifier is invoked twice on same fn', async function() {
const mapping = await setupAndRun('modifiers/duplicate-mods-same-fn');
assert.deepEqual(mapping[util.filePath].l, {
"5":2,"13":1
});
assert.deepEqual(mapping[util.filePath].b, {
"1":[1,0],"2":[1,0]
});
assert.deepEqual(mapping[util.filePath].s, {
1: 1
});
assert.deepEqual(mapping[util.filePath].f, {
1: 2, 2: 1
});
});
it('should *not* treat constructor inheritance invocations as branches', async function() { it('should *not* treat constructor inheritance invocations as branches', async function() {
const mapping = await setupAndRun('modifiers/constructor'); const mapping = await setupAndRun('modifiers/constructor');
assert.deepEqual(mapping[util.filePath].b, {}); assert.deepEqual(mapping[util.filePath].b, {});

Loading…
Cancel
Save