diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-22 16:39:07 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-22 16:39:07 +0800 |
commit | 3ce295a2af17feef6cd4e3140196501805493719 (patch) | |
tree | 964df912ce86d98a211f81f3d6159d797a37c3b3 /packages/sol-cov/src/utils.ts | |
parent | a30107ab867964d371b2d5fc6791c7b1963f1c7b (diff) | |
parent | 0515c6acded983bba05320895ea2c2891f37055c (diff) | |
download | dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar.gz dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar.bz2 dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar.lz dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar.xz dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.tar.zst dexon-sol-tools-3ce295a2af17feef6cd4e3140196501805493719.zip |
Merge branch 'v2-prototype' into refactor/check-revert-reasons
* v2-prototype: (40 commits)
Use make-promises-safe as a preloader instead of manually importing
Updated compiler runs to be 1,000,000
Add event to setSignatureValidatorApproval, rename signer => signerAddress accross all contracts
Add senderAddress to Fill and Cancel logs, add comments to events and types
Fix Island component
Add missing image assets for Chris and Mel
Fix some bugs in sol-cov
Remove unreachable PreSigned check
Fix linting
Buttons look hella disabled now
Remove border radius, fix width issue for unlock step
Add Chris and Mel to about page
fix linter issues
only call getLocationByOffset if source if defined
Set settleOrder and settleMatchedOrders to private
Prevent prettier issue
Support mobile friendly onboarding flows
Removed MixinSettlement. Moved `settleOrder` into `MixinExchangeCore` and `settleMatchedOrders` into `MixinMatchOrders`
Migrations after rebasing
Linter
...
Diffstat (limited to 'packages/sol-cov/src/utils.ts')
-rw-r--r-- | packages/sol-cov/src/utils.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/sol-cov/src/utils.ts b/packages/sol-cov/src/utils.ts index 4f16a1cda..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)); @@ -66,4 +78,10 @@ export const utils = { } return structLogs; }, + getRange(sourceCode: string, range: SingleFileSourceRange): string { + const lines = sourceCode.split('\n').slice(range.start.line - 1, range.end.line); + lines[lines.length - 1] = lines[lines.length - 1].slice(0, range.end.column); + lines[0] = lines[0].slice(range.start.column); + return lines.join('\n'); + }, }; |