Skip to content

Commit 6839e92

Browse files
authored
Improve organization of edge case code in collector (#869)
1 parent e6df717 commit 6839e92

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

lib/collector.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ class DataCollector {
4949
} catch (err) { /*Ignore*/ };
5050
}
5151

52-
// Temporarily disabled because some relevant traces aren't available
53-
/**
54-
* Converts pushData value to string and registers in instrumentation map.
55-
* @param {HardhatEVMTraceInstruction} instruction
56-
*/
57-
/*trackHardhatEVMInstruction(instruction){
58-
if (instruction && instruction.pushData){
59-
let hash = `0x` + instruction.pushData.toString('hex');
60-
this._registerHash(hash)
61-
}
62-
}*/
63-
6452
/**
6553
* Normalizes has string and marks hit.
6654
* @param {String} hash bytes32 hash
@@ -78,20 +66,6 @@ class DataCollector {
7866
}
7967
return;
8068
}
81-
82-
// Detect and recover from viaIR mangled hashes by left-padding single `0`
83-
if(this.viaIR && hash.length === 18) {
84-
hash = hash.slice(2);
85-
hash = '0' + hash;
86-
hash = hash.slice(0,16);
87-
hash = '0x' + hash;
88-
if(this.instrumentationData[hash]){
89-
if (this.lastHash !== hash) {
90-
this.lastHash = hash;
91-
this.instrumentationData[hash].hits++
92-
}
93-
}
94-
}
9569
}
9670

9771
/**
@@ -107,6 +81,15 @@ class DataCollector {
10781
// but it doesn't preserve leading zeroes when it does this
10882
if (this.viaIR && hash.length >= 18) {
10983
hash = hash.slice(0,18);
84+
85+
// Detect and recover from viaIR mangled hashes by left-padding single `0`
86+
if(!this.instrumentationData[hash]) {
87+
hash = hash.slice(2);
88+
hash = '0' + hash;
89+
hash = hash.slice(0,16);
90+
hash = '0x' + hash;
91+
}
92+
11093
} else if (hash.length < 18 && hash.length > 11){
11194
hash = hash.slice(2);
11295
while(hash.length < 16) hash = '0' + hash;
@@ -124,4 +107,4 @@ class DataCollector {
124107
}
125108
}
126109

127-
module.exports = DataCollector;
110+
module.exports = DataCollector;

0 commit comments

Comments
 (0)