Skip to content

Commit

Permalink
Allow duplicate modifiers on same function (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Jan 6, 2021
1 parent 5ab4857 commit b348134
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const web3Utils = require("web3-utils");
class Injector {
constructor(){
this.hashCounter = 0;
this.modifierCounter = 0;
this.modifiers = {};
}

Expand Down Expand Up @@ -353,11 +354,13 @@ class Injector {
}

injectModifier(contract, fileName, injectionPoint, injection, instrumentation){
this.modifierCounter++;

const type = 'modifier';
const contractId = `${fileName}:${injection.contractName}`;
const modifierId = `${fileName}:${injection.contractName}:` +
`${injection.modifierName}:${injection.fnId}:` +
`${injection.condition}`;
`${injection.condition}:${this.modifierCounter}`;

const {
start,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 17 additions & 0 deletions test/units/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
const mapping = await setupAndRun('modifiers/constructor');
assert.deepEqual(mapping[util.filePath].b, {});
Expand Down

0 comments on commit b348134

Please sign in to comment.