aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/utils.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-06-22 04:14:13 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-06-22 04:14:13 +0800
commit4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7 (patch)
treeaa612dce78d93d4084091485254c350d556757e8 /packages/sol-cov/src/utils.ts
parent88500e37146dc9152050fdd810f9f3c3cc5faf9f (diff)
downloaddexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar.gz
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar.bz2
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar.lz
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar.xz
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.tar.zst
dexon-sol-tools-4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7.zip
Fix some bugs in sol-cov
Diffstat (limited to 'packages/sol-cov/src/utils.ts')
-rw-r--r--packages/sol-cov/src/utils.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/sol-cov/src/utils.ts b/packages/sol-cov/src/utils.ts
index d31696636..b696bd463 100644
--- a/packages/sol-cov/src/utils.ts
+++ b/packages/sol-cov/src/utils.ts
@@ -5,6 +5,10 @@ import * as _ from 'lodash';
import { ContractData, LineColumn, SingleFileSourceRange } from './types';
+// This is the minimum length of valid contract bytecode. The Solidity compiler
+// metadata is 86 bytes. If you add the '0x' prefix, we get 88.
+const MIN_CONTRACT_BYTECODE_LENGTH = 88;
+
export const utils = {
compareLineColumn(lhs: LineColumn, rhs: LineColumn): number {
return lhs.line !== rhs.line ? lhs.line - rhs.line : lhs.column - rhs.column;
@@ -38,7 +42,15 @@ export const utils = {
}
const contractData = _.find(contractsData, contractDataCandidate => {
const bytecodeRegex = utils.bytecodeToBytecodeRegex(contractDataCandidate.bytecode);
+ // If the bytecode is less than the minimum length, we are probably
+ // dealing with an interface. This isn't what we're looking for.
+ if (bytecodeRegex.length < MIN_CONTRACT_BYTECODE_LENGTH) {
+ return false;
+ }
const runtimeBytecodeRegex = utils.bytecodeToBytecodeRegex(contractDataCandidate.runtimeBytecode);
+ if (runtimeBytecodeRegex.length < MIN_CONTRACT_BYTECODE_LENGTH) {
+ return false;
+ }
// We use that function to find by bytecode or runtimeBytecode. Those are quasi-random strings so
// collisions are practically impossible and it allows us to reuse that code
return !_.isNull(bytecode.match(bytecodeRegex)) || !_.isNull(bytecode.match(runtimeBytecodeRegex));