Skip to content

Commit

Permalink
Fix true/false scoped method definition function visibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Apr 26, 2022
1 parent 21ca46e commit 8ea8ec9
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions lib/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Injector {
_getFileScopedHashMethodDefinition(id, contract){
const hash = web3Utils.keccak256(id).slice(2,10);
const method = this._getDefaultMethodIdentifier(id);
return `\nfunction ${method}(bytes8 c__${hash}) public pure {}\n`;
return `\nfunction ${method}(bytes8 c__${hash}) pure {}\n`;
}

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

/**
* Generates a solidity statement injection defining a method
* *which returns boolean true* to pass instrumentation hash to.
* Declared once per file. (Has no visibility modifier)
* @param {String} fileName
* @return {String} ex: bytes32[1] memory _sc_82e0891
*/
_getFileScopeTrueMethodDefinition(id){
const hash = web3Utils.keccak256(id).slice(2,10);
const method = this._getTrueMethodIdentifier(id);
return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return true; }\n`;
}

/**
* Generates a solidity statement injection defining a method
* *which returns boolean false* to pass instrumentation hash to.
Expand All @@ -112,6 +125,19 @@ class Injector {
return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return false; }\n`;
}

/**
* Generates a solidity statement injection defining a method
* *which returns boolean false* to pass instrumentation hash to.
* Declared once per file. (Has no visibility modifier)
* @param {String} fileName
* @return {String} ex: bytes32[1] memory _sc_82e0891
*/
_getFileScopedFalseMethodDefinition(id){
const hash = web3Utils.keccak256(id).slice(2,10);
const method = this._getFalseMethodIdentifier(id);
return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return false; }\n`;
}

_getModifierDefinitions(contractId, instrumentation){
let injection = '';

Expand Down Expand Up @@ -312,11 +338,23 @@ class Injector {
? this._getFileScopedHashMethodDefinition(id)
: this._getDefaultMethodDefinition(id);

const trueMethodDefinition = (injection.isFileScoped)
? this._getFileScopeTrueMethodDefinition(id)
: this._getTrueMethodDefinition(id);

const falseMethodDefinition = (injection.isFileScoped)
? this._getFileScopedFalseMethodDefinition(id)
: this._getFalseMethodDefinition(id);

const modifierDefinition = (injection.isFileScoped)
? ""
: this._getModifierDefinitions(id, instrumentation);

contract.instrumented = `${start}` +
`${methodDefinition}` +
`${this._getTrueMethodDefinition(id)}` +
`${this._getFalseMethodDefinition(id)}` +
`${this._getModifierDefinitions(id, instrumentation)}` +
`${trueMethodDefinition}` +
`${falseMethodDefinition}` +
`${modifierDefinition}` +
`${end}`;
}

Expand Down

0 comments on commit 8ea8ec9

Please sign in to comment.