Skip to content

Commit b348134

Browse files
authored
Allow duplicate modifiers on same function (#596)
1 parent 5ab4857 commit b348134

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/injector.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const web3Utils = require("web3-utils");
33
class Injector {
44
constructor(){
55
this.hashCounter = 0;
6+
this.modifierCounter = 0;
67
this.modifiers = {};
78
}
89

@@ -353,11 +354,13 @@ class Injector {
353354
}
354355

355356
injectModifier(contract, fileName, injectionPoint, injection, instrumentation){
357+
this.modifierCounter++;
358+
356359
const type = 'modifier';
357360
const contractId = `${fileName}:${injection.contractName}`;
358361
const modifierId = `${fileName}:${injection.contractName}:` +
359362
`${injection.modifierName}:${injection.fnId}:` +
360-
`${injection.condition}`;
363+
`${injection.condition}:${this.modifierCounter}`;
361364

362365
const {
363366
start,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pragma solidity ^0.7.0;
2+
3+
contract Test {
4+
modifier m(string memory val) {
5+
_;
6+
}
7+
8+
function a()
9+
m('ETH')
10+
m('BTC')
11+
public
12+
{
13+
uint x = 5;
14+
}
15+
}

test/units/modifiers.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ describe('modifiers', () => {
216216
});
217217
});
218218

219+
it('should cover when same modifier is invoked twice on same fn', async function() {
220+
const mapping = await setupAndRun('modifiers/duplicate-mods-same-fn');
221+
222+
assert.deepEqual(mapping[util.filePath].l, {
223+
"5":2,"13":1
224+
});
225+
assert.deepEqual(mapping[util.filePath].b, {
226+
"1":[1,0],"2":[1,0]
227+
});
228+
assert.deepEqual(mapping[util.filePath].s, {
229+
1: 1
230+
});
231+
assert.deepEqual(mapping[util.filePath].f, {
232+
1: 2, 2: 1
233+
});
234+
});
235+
219236
it('should *not* treat constructor inheritance invocations as branches', async function() {
220237
const mapping = await setupAndRun('modifiers/constructor');
221238
assert.deepEqual(mapping[util.filePath].b, {});

0 commit comments

Comments
 (0)