aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-07 20:04:58 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-07 20:04:58 +0800
commit9e67e12732a0fc87f0000917e6bbf21c3c2db260 (patch)
treed3ae0b94d8b794bb0a90c0082e29a4172a6eb615 /packages/sol-cov
parent2d30183d658c9d178544e1c14fb779306e5d2778 (diff)
downloaddexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar.gz
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar.bz2
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar.lz
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar.xz
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.tar.zst
dexon-sol-tools-9e67e12732a0fc87f0000917e6bbf21c3c2db260.zip
Add removeHexPrefix util method
Diffstat (limited to 'packages/sol-cov')
-rw-r--r--packages/sol-cov/src/coverage_manager.ts8
-rw-r--r--packages/sol-cov/src/utils.ts4
2 files changed, 6 insertions, 6 deletions
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts
index e932ac081..6a57d07c9 100644
--- a/packages/sol-cov/src/coverage_manager.ts
+++ b/packages/sol-cov/src/coverage_manager.ts
@@ -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;
diff --git a/packages/sol-cov/src/utils.ts b/packages/sol-cov/src/utils.ts
index f155043a1..d970c42ee 100644
--- a/packages/sol-cov/src/utils.ts
+++ b/packages/sol-cov/src/utils.ts
@@ -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 &&