Skip to content

Commit 63ad677

Browse files
committed
Fix true/false scoped method definition function visibilities
1 parent df84fbf commit 63ad677

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

lib/injector.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Injector {
8585
_getFileScopedHashMethodDefinition(id, contract){
8686
const hash = web3Utils.keccak256(id).slice(2,10);
8787
const method = this._getDefaultMethodIdentifier(id);
88-
return `\nfunction ${method}(bytes8 c__${hash}) public pure {}\n`;
88+
return `\nfunction ${method}(bytes8 c__${hash}) pure {}\n`;
8989
}
9090

9191
/**
@@ -100,6 +100,19 @@ class Injector {
100100
return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return true; }\n`;
101101
}
102102

103+
/**
104+
* Generates a solidity statement injection defining a method
105+
* *which returns boolean true* to pass instrumentation hash to.
106+
* Declared once per file. (Has no visibility modifier)
107+
* @param {String} fileName
108+
* @return {String} ex: bytes32[1] memory _sc_82e0891
109+
*/
110+
_getFileScopeTrueMethodDefinition(id){
111+
const hash = web3Utils.keccak256(id).slice(2,10);
112+
const method = this._getTrueMethodIdentifier(id);
113+
return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return true; }\n`;
114+
}
115+
103116
/**
104117
* Generates a solidity statement injection defining a method
105118
* *which returns boolean false* to pass instrumentation hash to.
@@ -112,6 +125,19 @@ class Injector {
112125
return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return false; }\n`;
113126
}
114127

128+
/**
129+
* Generates a solidity statement injection defining a method
130+
* *which returns boolean false* to pass instrumentation hash to.
131+
* Declared once per file. (Has no visibility modifier)
132+
* @param {String} fileName
133+
* @return {String} ex: bytes32[1] memory _sc_82e0891
134+
*/
135+
_getFileScopedFalseMethodDefinition(id){
136+
const hash = web3Utils.keccak256(id).slice(2,10);
137+
const method = this._getFalseMethodIdentifier(id);
138+
return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return false; }\n`;
139+
}
140+
115141
_getModifierDefinitions(contractId, instrumentation){
116142
let injection = '';
117143

@@ -312,11 +338,23 @@ class Injector {
312338
? this._getFileScopedHashMethodDefinition(id)
313339
: this._getDefaultMethodDefinition(id);
314340

341+
const trueMethodDefinition = (injection.isFileScoped)
342+
? this._getFileScopeTrueMethodDefinition(id)
343+
: this._getTrueMethodDefinition(id);
344+
345+
const falseMethodDefinition = (injection.isFileScoped)
346+
? this._getFileScopedFalseMethodDefinition(id)
347+
: this._getFalseMethodDefinition(id);
348+
349+
const modifierDefinition = (injection.isFileScoped)
350+
? ""
351+
: this._getModifierDefinitions(id, instrumentation);
352+
315353
contract.instrumented = `${start}` +
316354
`${methodDefinition}` +
317-
`${this._getTrueMethodDefinition(id)}` +
318-
`${this._getFalseMethodDefinition(id)}` +
319-
`${this._getModifierDefinitions(id, instrumentation)}` +
355+
`${trueMethodDefinition}` +
356+
`${falseMethodDefinition}` +
357+
`${modifierDefinition}` +
320358
`${end}`;
321359
}
322360

0 commit comments

Comments
 (0)