@@ -85,7 +85,7 @@ class Injector {
85
85
_getFileScopedHashMethodDefinition ( id , contract ) {
86
86
const hash = web3Utils . keccak256 ( id ) . slice ( 2 , 10 ) ;
87
87
const method = this . _getDefaultMethodIdentifier ( id ) ;
88
- return `\nfunction ${ method } (bytes8 c__${ hash } ) public pure {}\n` ;
88
+ return `\nfunction ${ method } (bytes8 c__${ hash } ) pure {}\n` ;
89
89
}
90
90
91
91
/**
@@ -100,6 +100,19 @@ class Injector {
100
100
return `function ${ method } (bytes8 c__${ hash } ) internal pure returns (bool){ return true; }\n` ;
101
101
}
102
102
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
+
103
116
/**
104
117
* Generates a solidity statement injection defining a method
105
118
* *which returns boolean false* to pass instrumentation hash to.
@@ -112,6 +125,19 @@ class Injector {
112
125
return `function ${ method } (bytes8 c__${ hash } ) internal pure returns (bool){ return false; }\n` ;
113
126
}
114
127
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
+
115
141
_getModifierDefinitions ( contractId , instrumentation ) {
116
142
let injection = '' ;
117
143
@@ -312,11 +338,23 @@ class Injector {
312
338
? this . _getFileScopedHashMethodDefinition ( id )
313
339
: this . _getDefaultMethodDefinition ( id ) ;
314
340
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
+
315
353
contract . instrumented = `${ start } ` +
316
354
`${ methodDefinition } ` +
317
- `${ this . _getTrueMethodDefinition ( id ) } ` +
318
- `${ this . _getFalseMethodDefinition ( id ) } ` +
319
- `${ this . _getModifierDefinitions ( id , instrumentation ) } ` +
355
+ `${ trueMethodDefinition } ` +
356
+ `${ falseMethodDefinition } ` +
357
+ `${ modifierDefinition } ` +
320
358
`${ end } ` ;
321
359
}
322
360
0 commit comments