Add removeHexPrefix util method
This commit is contained in:
@@ -134,9 +134,7 @@ export class CoverageManager {
|
||||
if (traceInfo.address !== constants.NEW_CONTRACT) {
|
||||
// Runtime transaction
|
||||
let runtimeBytecode = (traceInfo as TraceInfoExistingContract).runtimeBytecode;
|
||||
if (runtimeBytecode.startsWith('0x')) {
|
||||
runtimeBytecode = runtimeBytecode.slice(2);
|
||||
}
|
||||
runtimeBytecode = utils.removeHexPrefix(runtimeBytecode);
|
||||
const contractData = _.find(this._contractsData, { runtimeBytecode }) as ContractData;
|
||||
if (_.isUndefined(contractData)) {
|
||||
throw new Error(`Transaction to an unknown address: ${traceInfo.address}`);
|
||||
@@ -161,9 +159,7 @@ export class CoverageManager {
|
||||
} else {
|
||||
// Contract creation transaction
|
||||
let bytecode = (traceInfo as TraceInfoNewContract).bytecode;
|
||||
if (bytecode.startsWith('0x')) {
|
||||
bytecode = bytecode.slice(2);
|
||||
}
|
||||
bytecode = utils.removeHexPrefix(bytecode);
|
||||
const contractData = _.find(this._contractsData, contractDataCandidate =>
|
||||
bytecode.startsWith(contractDataCandidate.bytecode),
|
||||
) as ContractData;
|
||||
|
||||
@@ -4,6 +4,10 @@ export const utils = {
|
||||
compareLineColumn(lhs: LineColumn, rhs: LineColumn): number {
|
||||
return lhs.line !== rhs.line ? lhs.line - rhs.line : lhs.column - rhs.column;
|
||||
},
|
||||
removeHexPrefix(hex: string): string {
|
||||
const hexPrefix = '0x';
|
||||
return hex.startsWith(hexPrefix) ? hex.slice(hexPrefix.length) : hex;
|
||||
},
|
||||
isRangeInside(childRange: SingleFileSourceRange, parentRange: SingleFileSourceRange): boolean {
|
||||
return (
|
||||
utils.compareLineColumn(parentRange.start, childRange.start) <= 0 &&
|
||||
|
||||
Reference in New Issue
Block a user