Refactor out sol-cov, sol-profiler and sol-trace into their separate packages

This commit is contained in:
Leonid Logvinov 2019-01-08 12:23:33 +01:00
parent 0ac36cef28
commit 2c974b5f3f
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
129 changed files with 1130 additions and 624 deletions

View File

@ -118,7 +118,7 @@ jobs:
- run: yarn wsrun test:circleci @0x/order-utils
- run: yarn wsrun test:circleci @0x/order-watcher
- run: yarn wsrun test:circleci @0x/sol-compiler
- run: yarn wsrun test:circleci @0x/sol-cov
- run: yarn wsrun test:circleci @0x/sol-trace-based-tools-common
- run: yarn wsrun test:circleci @0x/sol-doc
- run: yarn wsrun test:circleci @0x/subproviders
- run: yarn wsrun test:circleci @0x/web3-wrapper
@ -169,9 +169,9 @@ jobs:
paths:
- ~/repo/packages/sol-compiler/coverage/lcov.info
- save_cache:
key: coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
key: coverage-sol-trace-based-tools-common-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/sol-cov/coverage/lcov.info
- ~/repo/packages/sol-trace-based-tools-common/coverage/lcov.info
- save_cache:
key: coverage-sol-doc-{{ .Environment.CIRCLE_SHA1 }}
paths:
@ -342,7 +342,7 @@ jobs:
- coverage-sol-compiler-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
- coverage-sol-trace-based-tools-common-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-sol-doc-{{ .Environment.CIRCLE_SHA1 }}

View File

@ -13,7 +13,10 @@ instant: ['packages/instant']
abi-gen-templates: ['packages/abi-gen-templates']
abi-gen: ['packages/abi-gen']
website: ['packages/website']
sol-cov: ['packages/sol-cov']
sol-coverage: ['packages/sol-coverage']
sol-profiler: ['packages/sol-profiler']
sol-trace: ['packages/sol-trace']
sol-trace-based-tools-common: ['packages/sol-trace-based-tools-common']
utils: ['packages/utils']
tslint-config: ['packages/tslint-config']
asset-buyer: ['packages/asset-buyer']

2
.gitignore vendored
View File

@ -91,7 +91,7 @@ contracts/interfaces/generated-artifacts/
contracts/tokens/generated-artifacts/
contracts/examples/generated-artifacts/
contracts/extensions/generated-artifacts/
packages/sol-cov/test/fixtures/artifacts/
packages/sol-trace-based-tools-common/test/fixtures/artifacts/
packages/metacoin/artifacts/
# generated contract wrappers

View File

@ -26,4 +26,4 @@ lib
/packages/sra-spec/public/
package.json
scripts/postpublish_utils.js
packages/sol-cov/test/fixtures/artifacts
packages/sol-coverage/test/fixtures/artifacts

View File

@ -24,7 +24,10 @@ packages/metacoin/ @LogvinovLeon
packages/monorepo-scripts/ @fabioberger
packages/order-utils/ @fabioberger @LogvinovLeon
packages/sol-compiler/ @LogvinovLeon
packages/sol-cov/ @LogvinovLeon
packages/sol-coverage/ @LogvinovLeon
packages/sol-profiler/ @LogvinovLeon
packages/sol-trace/ @LogvinovLeon
packages/sol-trace-based-tools-common/ @LogvinovLeon
packages/sol-resolver/ @LogvinovLeon
packages/subproviders/ @fabioberger @dekz
packages/verdaccio/ @albrow

View File

@ -54,7 +54,9 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`@0x/web3-wrapper`](/packages/web3-wrapper) | [![npm](https://img.shields.io/npm/v/@0x/web3-wrapper.svg)](https://www.npmjs.com/package/@0x/web3-wrapper) | An Ethereum JSON RPC client |
| [`@0x/sol-compiler`](/packages/sol-compiler) | [![npm](https://img.shields.io/npm/v/@0x/sol-compiler.svg)](https://www.npmjs.com/package/@0x/sol-compiler) | A wrapper around solc-js that adds smart re-compilation, ability to compile an entire project, Solidity version specific compilation, standard input description support and much more. |
| [`@0x/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0x/sol-cov.svg)](https://www.npmjs.com/package/@0x/sol-cov) | A solidity test coverage tool |
| [`@0x/sol-coverage`](/packages/sol-coverage) | [![npm](https://img.shields.io/npm/v/@0x/sol-coverage.svg)](https://www.npmjs.com/package/@0x/sol-coverage) | A solidity test coverage tool |
| [`@0x/sol-profiler`](/packages/sol-profiler) | [![npm](https://img.shields.io/npm/v/@0x/sol-profiler.svg)](https://www.npmjs.com/package/@0x/sol-profiler) | A solidity gas cost profiler |
| [`@0x/sol-trace`](/packages/sol-trace) | [![npm](https://img.shields.io/npm/v/@0x/sol-trace.svg)](https://www.npmjs.com/package/@0x/sol-trace) | A solidity stack trace tool |
| [`@0x/sol-resolver`](/packages/sol-resolver) | [![npm](https://img.shields.io/npm/v/@0x/sol-resolver.svg)](https://www.npmjs.com/package/@0x/sol-resolver) | Import resolver for smart contracts dependencies |
| [`@0x/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0x/subproviders.svg)](https://www.npmjs.com/package/@0x/subproviders) | Web3 provider middlewares (e.g. LedgerSubprovider) |
| [`@0x/sol-doc`](/packages/sol-doc) | [![npm](https://img.shields.io/npm/v/@0x/sol-doc.svg)](https://www.npmjs.com/package/@0x/sol-doc) | Solidity documentation generator |

View File

@ -20,7 +20,7 @@ TEST_PROVIDER=geth yarn test
## Code coverage
In order to see the Solidity code coverage output generated by `@0x/sol-cov`, run:
In order to see the Solidity code coverage output generated by `@0x/sol-coverage`, run:
```
yarn test:coverage

View File

@ -37,7 +37,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -49,7 +49,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -48,7 +48,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -48,7 +48,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -47,7 +47,6 @@
"@0x/abi-gen": "^1.0.19",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -44,7 +44,9 @@
"@0x/dev-utils": "^1.0.21",
"@0x/order-utils": "^3.0.7",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/sol-coverage": "^1.0.0",
"@0x/sol-profiler": "^1.0.0",
"@0x/sol-trace": "^1.0.0",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@0x/types": "^1.4.1",

View File

@ -1,5 +1,5 @@
import { devConstants } from '@0x/dev-utils';
import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-cov';
import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-coverage';
import * as _ from 'lodash';
let coverageSubprovider: CoverageSubprovider;

View File

@ -1,5 +1,5 @@
import { devConstants } from '@0x/dev-utils';
import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-cov';
import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-profiler';
import * as _ from 'lodash';
let profilerSubprovider: ProfilerSubprovider;

View File

@ -1,5 +1,5 @@
import { devConstants } from '@0x/dev-utils';
import { RevertTraceSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-cov';
import { RevertTraceSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-trace';
import * as _ from 'lodash';
let revertTraceSubprovider: RevertTraceSubprovider;

View File

@ -48,7 +48,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -48,7 +48,6 @@
"@0x/contracts-test-utils": "^1.0.2",
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",
"@0x/sol-cov": "^2.1.16",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@types/bn.js": "^4.11.0",

View File

@ -41,7 +41,7 @@
},
"config": {
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic",
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-cov ethereum-types asset-buyer migrations"
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer migrations"
},
"bundlewatch": {
"files": [
@ -62,6 +62,9 @@
"repoBranchBase": "development"
}
},
"resolutions": {
"graceful-fs": "4.1.15"
},
"devDependencies": {
"@0x-lerna-fork/lerna": "3.0.0-beta.26",
"@0xproject/npm-cli-login": "^0.0.11",

View File

@ -32,7 +32,8 @@
"@0x/abi-gen": "^1.0.19",
"@0x/abi-gen-templates": "^1.0.1",
"@0x/base-contract": "^3.0.10",
"@0x/sol-cov": "^2.1.16",
"@0x/sol-coverage": "^1.0.0",
"@0x/sol-profiler": "^1.0.0",
"@0x/subproviders": "^2.1.8",
"@0x/tslint-config": "^2.0.0",
"@0x/types": "^1.4.1",

View File

@ -1,5 +1,5 @@
import { devConstants } from '@0x/dev-utils';
import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-cov';
import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-coverage';
import * as _ from 'lodash';
import { config } from './config';

View File

@ -1,5 +1,5 @@
import { devConstants } from '@0x/dev-utils';
import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-cov';
import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-profiler';
import * as _ from 'lodash';
import { config } from './config';

View File

@ -1,6 +0,0 @@
{
"extends": ["@0x/tslint-config"],
"rules": {
"completed-docs": false
}
}

View File

@ -0,0 +1,12 @@
[
{
"version": "1.0.0",
"changes": [
{
"note":
"Initial release as a separate package. For historic entries check @0x/sol-trace-based-tools-common",
"pr": 1492
}
]
}
]

View File

@ -1,25 +1,25 @@
## @0x/sol-cov
## @0x/sol-coverage
A Solidity code coverage tool.
### Read the [Documentation](https://0xproject.com/docs/sol-cov).
### Read the [Documentation](https://0xproject.com/docs/sol-coverage).
## Installation
```bash
yarn add @0x/sol-cov
yarn add @0x/sol-coverage
```
**Import**
```javascript
import { CoverageSubprovider } from '@0x/sol-cov';
import { CoverageSubprovider } from '@0x/sol-coverage';
```
or
```javascript
var CoverageSubprovider = require('@0x/sol-cov').CoverageSubprovider;
var CoverageSubprovider = require('@0x/sol-coverage').CoverageSubprovider;
```
## Contributing
@ -47,13 +47,13 @@ yarn install
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
```bash
PKG=@0x/sol-cov yarn build
PKG=@0x/sol-coverage yarn build
```
Or continuously rebuild on change:
```bash
PKG=@0x/sol-cov yarn watch
PKG=@0x/sol-coverage yarn watch
```
### Clean

View File

@ -0,0 +1,52 @@
{
"name": "@0x/sol-coverage",
"version": "1.0.0",
"engines": {
"node": ">=6.12"
},
"description": "Generate coverage reports for Solidity code",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"lint": "tslint --format stylish --project .",
"clean": "shx rm -rf lib src/artifacts generated_docs",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
"assets": []
}
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x-monorepo.git"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/0xProject/0x-monorepo/issues"
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-coverage/README.md",
"dependencies": {
"@0x/subproviders": "^2.1.8",
"@0x/sol-trace-based-tools-common": "^2.1.16",
"@0x/typescript-typings": "^3.0.6",
"ethereum-types": "^1.1.4",
"lodash": "^4.17.5"
},
"devDependencies": {
"@0x/tslint-config": "^2.0.0",
"@types/node": "*",
"npm-run-all": "^4.1.2",
"nyc": "^11.0.1",
"shx": "^0.2.2",
"sinon": "^4.0.0",
"tslint": "5.11.0",
"typedoc": "0.13.0",
"typescript": "3.0.1"
},
"publishConfig": {
"access": "public"
}
}

View File

@ -1,22 +1,22 @@
import * as _ from 'lodash';
import { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
import { collectCoverageEntries } from './collect_coverage_entries';
import { SingleFileSubtraceHandler, TraceCollector } from './trace_collector';
import { TraceInfoSubprovider } from './trace_info_subprovider';
import {
AbstractArtifactAdapter,
BranchCoverage,
collectCoverageEntries,
ContractData,
Coverage,
FunctionCoverage,
FunctionDescription,
SingleFileSubtraceHandler,
SourceRange,
StatementCoverage,
StatementDescription,
Subtrace,
TraceCollector,
TraceInfo,
} from './types';
import { utils } from './utils';
TraceInfoSubprovider,
utils,
} from '@0x/sol-trace-based-tools-common';
import * as _ from 'lodash';
/**
* This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface.

View File

@ -0,0 +1,23 @@
export { CoverageSubprovider } from './coverage_subprovider';
export {
SolCompilerArtifactAdapter,
TruffleArtifactAdapter,
AbstractArtifactAdapter,
ContractData,
} from '@0x/sol-trace-based-tools-common';
export {
JSONRPCRequestPayload,
Provider,
JSONRPCErrorCallback,
JSONRPCResponsePayload,
JSONRPCResponseError,
} from 'ethereum-types';
export {
JSONRPCRequestPayloadWithMethod,
NextCallback,
ErrorCallback,
OnNextCompleted,
Callback,
} from '@0x/subproviders';

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*"]
}

View File

@ -0,0 +1,3 @@
{
"extends": ["@0x/tslint-config"]
}

View File

@ -0,0 +1,6 @@
.*
yarn-error.log
/src/
/scripts/
tsconfig.json
/lib/src/monorepo_scripts/

View File

@ -0,0 +1,12 @@
[
{
"version": "1.0.0",
"changes": [
{
"note":
"Initial release as a separate package. For historic entries check @0x/sol-trace-based-tools-common",
"pr": 1492
}
]
}
]

View File

@ -0,0 +1,75 @@
## @0x/sol-profiler
Solidity line-by-line gas profiler.
### Read the [Documentation](https://0xproject.com/docs/sol-profiler).
## Installation
```bash
yarn add @0x/sol-profiler
```
**Import**
```javascript
import { ProfilerSubprovider } from '@0x/sol-profiler';
```
or
```javascript
var ProfilerSubprovider = require('@0x/sol-profiler').ProfilerSubprovider;
```
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Build
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
```bash
PKG=@0x/sol-profiler yarn build
```
Or continuously rebuild on change:
```bash
PKG=@0x/sol-profiler yarn watch
```
### Clean
```bash
yarn clean
```
### Lint
```bash
yarn lint
```
### Run Tests
```bash
yarn test
```

View File

@ -0,0 +1,50 @@
{
"name": "@0x/sol-profiler",
"version": "1.0.0",
"engines": {
"node": ">=6.12"
},
"description": "Generate profiler reports for Solidity code",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"lint": "tslint --format stylish --project .",
"clean": "shx rm -rf lib src/artifacts generated_docs",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
"assets": []
}
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x-monorepo.git"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/0xProject/0x-monorepo/issues"
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-profiler/README.md",
"dependencies": {
"@0x/subproviders": "^2.1.8",
"@0x/typescript-typings": "^3.0.6",
"@0x/sol-trace-based-tools-common": "^2.1.16",
"ethereum-types": "^1.1.4",
"lodash": "^4.17.5"
},
"devDependencies": {
"@0x/tslint-config": "^2.0.0",
"@types/node": "*",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.11.0",
"typedoc": "0.13.0",
"typescript": "3.0.1"
},
"publishConfig": {
"access": "public"
}
}

View File

@ -0,0 +1,7 @@
// tslint:disable:completed-docs
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

View File

@ -1,13 +1,13 @@
export { CoverageSubprovider } from './coverage_subprovider';
export { SolCompilerArtifactAdapter } from './artifact_adapters/sol_compiler_artifact_adapter';
export { TruffleArtifactAdapter } from './artifact_adapters/truffle_artifact_adapter';
export { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
export {
AbstractArtifactAdapter,
SolCompilerArtifactAdapter,
TruffleArtifactAdapter,
ContractData,
} from '@0x/sol-trace-based-tools-common';
// HACK: ProfilerSubprovider is a hacky way to do profiling using coverage tools. Not production ready
export { ProfilerSubprovider } from './profiler_subprovider';
export { RevertTraceSubprovider } from './revert_trace_subprovider';
export { ContractData } from './types';
export {
JSONRPCRequestPayload,
Provider,

View File

@ -1,11 +1,18 @@
import * as _ from 'lodash';
import { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
import { collectCoverageEntries } from './collect_coverage_entries';
import { SingleFileSubtraceHandler, TraceCollector } from './trace_collector';
import { TraceInfoSubprovider } from './trace_info_subprovider';
import { ContractData, Coverage, SourceRange, Subtrace, TraceInfo } from './types';
import { utils } from './utils';
import {
AbstractArtifactAdapter,
collectCoverageEntries,
ContractData,
Coverage,
SingleFileSubtraceHandler,
SourceRange,
Subtrace,
TraceCollector,
TraceInfo,
TraceInfoSubprovider,
utils,
} from '@0x/sol-trace-based-tools-common';
/**
* This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface.

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*"]
}

View File

@ -0,0 +1,3 @@
{
"extends": ["@0x/tslint-config"]
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*"]
}

View File

@ -0,0 +1,6 @@
.*
yarn-error.log
/src/
/scripts/
tsconfig.json
/lib/src/monorepo_scripts/

View File

@ -1,4 +1,13 @@
[
{
"version": "3.0.0",
"changes": [
{
"note": "Move out specific tools and leave just the common part",
"pr": 1492
}
]
},
{
"version": "2.1.16",
"changes": [

View File

@ -0,0 +1,61 @@
## @0x/sol-trace-based-tools-common
Common code for all solidity trace-based tools (sol-coverage, sol-profiler, sol-trace).
## Installation
```bash
yarn add @0x/sol-sol-trace-based-tools-common
```
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Build
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
```bash
PKG=@0x/sol-trace-based-tools-common yarn build
```
Or continuously rebuild on change:
```bash
PKG=@0x/sol-trace-based-tools-common yarn watch
```
### Clean
```bash
yarn clean
```
### Lint
```bash
yarn lint
```
### Run Tests
```bash
yarn test
```

View File

@ -1,10 +1,10 @@
{
"name": "@0x/sol-cov",
"name": "@0x/sol-trace-based-tools-common",
"version": "2.1.16",
"engines": {
"node": ">=6.12"
},
"description": "Generate coverage reports for Solidity code",
"description": "Common part of trace based solidity tools (sol-coverage, sol-trace, sol-profiler)",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
@ -34,13 +34,13 @@
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x.js.git"
"url": "https://github.com/0xProject/0x-monorepo.git"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/0xProject/0x.js/issues"
"url": "https://github.com/0xProject/0x-monorepo/issues"
},
"homepage": "https://github.com/0xProject/0x.js/packages/sol-cov/README.md",
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-trace-based-tools-common/README.md",
"dependencies": {
"@0x/dev-utils": "^1.0.21",
"@0x/sol-compiler": "^1.1.16",

View File

@ -80,7 +80,7 @@ export class TruffleArtifactAdapter extends AbstractArtifactAdapter {
throw new Error(
`${artifact.contractName} was compiled with solidity ${compilerVersion} but specified version is ${
this._solcVersion
} making it impossible for sol-cov to process traces`,
} making it impossible to process traces`,
);
}
}

View File

@ -15,6 +15,11 @@ interface ASTInfo {
// Parsing source code for each transaction/code is slow and therefore we cache it
const parsedSourceByHash: { [sourceHash: string]: Parser.ASTNode } = {};
/**
* Gets the source range snippet by source range to be used by revert trace.
* @param sourceRange source range
* @param sourceCode source code
*/
export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: string): SourceSnippet | null {
const sourceHash = ethUtil.sha3(sourceCode).toString('hex');
if (_.isUndefined(parsedSourceByHash[sourceHash])) {

View File

@ -0,0 +1,7 @@
// tslint:disable:completed-docs
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

View File

@ -0,0 +1,39 @@
export { SolCompilerArtifactAdapter } from './artifact_adapters/sol_compiler_artifact_adapter';
export { TruffleArtifactAdapter } from './artifact_adapters/truffle_artifact_adapter';
export { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
export {
ContractData,
EvmCallStack,
SourceRange,
SourceSnippet,
StatementCoverage,
StatementDescription,
BranchCoverage,
BranchDescription,
Subtrace,
TraceInfo,
Coverage,
LineColumn,
LineCoverage,
FunctionCoverage,
FunctionDescription,
SingleFileSourceRange,
BranchMap,
EvmCallStackEntry,
FnMap,
LocationByOffset,
StatementMap,
TraceInfoBase,
TraceInfoExistingContract,
TraceInfoNewContract,
} from './types';
export { collectCoverageEntries } from './collect_coverage_entries';
export { TraceCollector, SingleFileSubtraceHandler } from './trace_collector';
export { TraceInfoSubprovider } from './trace_info_subprovider';
export { utils } from './utils';
export { constants } from './constants';
export { parseSourceMap } from './source_maps';
export { getSourceRangeSnippet } from './get_source_range_snippet';
export { getRevertTrace } from './revert_trace';
export { TraceCollectionSubprovider } from './trace_collection_subprovider';

View File

@ -6,6 +6,11 @@ import * as _ from 'lodash';
import { EvmCallStack } from './types';
import { utils } from './utils';
/**
* Converts linear trace to a call stack by following calls and returns
* @param structLogs Linear trace
* @param startAddress The address of initial context
*/
export function getRevertTrace(structLogs: StructLog[], startAddress: string): EvmCallStack {
const evmCallStack: EvmCallStack = [];
const addressStack = [startAddress];
@ -55,7 +60,7 @@ export function getRevertTrace(structLogs: StructLog[], startAddress: string): E
// TODO: Refactor this logic to fetch the sub-called contract bytecode before the selfdestruct is called
// in order to handle this edge-case.
logUtils.warn(
"Detected a selfdestruct. Sol-cov currently doesn't support that scenario. We'll just skip the trace part for a destructed contract",
"Detected a selfdestruct. We currently do not support that scenario. We'll just skip the trace part for a destructed contract",
);
}
} else if (structLog.op === OpCode.Revert) {
@ -67,7 +72,7 @@ export function getRevertTrace(structLogs: StructLog[], startAddress: string): E
} else if (structLog.op === OpCode.Create) {
// TODO: Extract the new contract address from the stack and handle that scenario
logUtils.warn(
"Detected a contract created from within another contract. Sol-cov currently doesn't support that scenario. We'll just skip that trace",
"Detected a contract created from within another contract. We currently do not support that scenario. We'll just skip that trace",
);
return [];
} else {

View File

@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { getPcToInstructionIndexMapping } from './instructions';
import { LineColumn, LocationByOffset, SourceRange } from './types';
import { LocationByOffset, SourceRange } from './types';
const RADIX = 10;
@ -11,6 +11,10 @@ export interface SourceLocation {
fileIndex: number;
}
/**
* Receives a string with newlines and returns a hash of byte offset to LineColumn
* @param str A string to process
*/
export function getLocationByOffset(str: string): LocationByOffset {
const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } };
let currentOffset = 0;
@ -26,8 +30,14 @@ export function getLocationByOffset(str: string): LocationByOffset {
return locationByOffset;
}
// Parses a sourcemap string
// The solidity sourcemap format is documented here: https://github.com/ethereum/solidity/blob/develop/docs/miscellaneous.rst#source-mappings
/**
* Parses a sourcemap string.
* The solidity sourcemap format is documented here: https://github.com/ethereum/solidity/blob/develop/docs/miscellaneous.rst#source-mappings
* @param sourceCodes sources contents
* @param srcMap source map string
* @param bytecodeHex contract bytecode
* @param sources sources file names
*/
export function parseSourceMap(
sourceCodes: string[],
srcMap: string,

View File

@ -8,6 +8,11 @@ export interface TraceByContractAddress {
[contractAddress: string]: StructLog[];
}
/**
* Converts linear stack trace to `TraceByContractAddress`.
* @param structLogs stack trace
* @param startAddress initial context address
*/
export function getTracesByContractAddress(structLogs: StructLog[], startAddress: string): TraceByContractAddress {
const traceByContractAddress: TraceByContractAddress = {};
let currentTraceSegment = [];
@ -58,13 +63,13 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
// TODO: Refactor this logic to fetch the sub-called contract bytecode before the selfdestruct is called
// in order to handle this edge-case.
logUtils.warn(
"Detected a selfdestruct. Sol-cov currently doesn't support that scenario. We'll just skip the trace part for a destructed contract",
"Detected a selfdestruct. We currently do not support that scenario. We'll just skip the trace part for a destructed contract",
);
}
} else if (structLog.op === OpCode.Create) {
// TODO: Extract the new contract address from the stack and handle that scenario
logUtils.warn(
"Detected a contract created from within another contract. Sol-cov currently doesn't support that scenario. We'll just skip that trace",
"Detected a contract created from within another contract. We currently do not support that scenario. We'll just skip that trace",
);
return traceByContractAddress;
} else {

View File

@ -51,7 +51,7 @@ export class TraceCollector {
singleFileSubtraceHandler: SingleFileSubtraceHandler,
) {
this._artifactAdapter = artifactAdapter;
this._logger = getLogger('sol-cov');
this._logger = getLogger('sol-trace-based-tools-common');
this._logger.setLevel(isVerbose ? levels.TRACE : levels.ERROR);
this._singleFileSubtraceHandler = singleFileSubtraceHandler;
}

View File

@ -0,0 +1,3 @@
{
"extends": ["@0x/tslint-config"]
}

View File

@ -0,0 +1,6 @@
.*
yarn-error.log
/src/
/scripts/
tsconfig.json
/lib/src/monorepo_scripts/

View File

@ -0,0 +1,12 @@
[
{
"version": "1.0.0",
"changes": [
{
"note":
"Initial release as a separate package. For historic entries check @0x/sol-trace-based-tools-common",
"pr": 1492
}
]
}
]

View File

@ -0,0 +1,75 @@
## @0x/sol-trace
Prints code traces when revert happens.
### Read the [Documentation](https://0xproject.com/docs/sol-trace).
## Installation
```bash
yarn add @0x/sol-trace
```
**Import**
```javascript
import { RevertTraceSubprovider } from '@0x/sol-trace';
```
or
```javascript
var RevertTraceSubprovider = require('@0x/sol-trace').RevertTraceSubprovider;
```
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Build
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
```bash
PKG=@0x/sol-trace yarn build
```
Or continuously rebuild on change:
```bash
PKG=@0x/sol-trace yarn watch
```
### Clean
```bash
yarn clean
```
### Lint
```bash
yarn lint
```
### Run Tests
```bash
yarn test
```

View File

@ -0,0 +1,52 @@
{
"name": "@0x/sol-trace",
"version": "1.0.0",
"engines": {
"node": ">=6.12"
},
"description": "Prints stack trace on Solidity revert",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"lint": "tslint --format stylish --project .",
"clean": "shx rm -rf lib src/artifacts generated_docs",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
"assets": []
}
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x-monorepo.git"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/0xProject/0x-monorepo/issues"
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-trace/README.md",
"dependencies": {
"@0x/subproviders": "^2.1.8",
"@0x/typescript-typings": "^3.0.6",
"@0x/sol-trace-based-tools-common": "^2.1.16",
"ethereum-types": "^1.1.4",
"ethereumjs-util": "^5.1.1",
"lodash": "^4.17.5",
"loglevel": "^1.6.1"
},
"devDependencies": {
"@0x/tslint-config": "^2.0.0",
"@types/loglevel": "^1.5.3",
"@types/node": "*",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.11.0",
"typescript": "3.0.1"
},
"publishConfig": {
"access": "public"
}
}

7
packages/sol-trace/src/globals.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
// tslint:disable:completed-docs
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

View File

@ -0,0 +1,24 @@
export {
AbstractArtifactAdapter,
TruffleArtifactAdapter,
SolCompilerArtifactAdapter,
ContractData,
} from '@0x/sol-trace-based-tools-common';
export { RevertTraceSubprovider } from './revert_trace_subprovider';
export {
JSONRPCRequestPayload,
Provider,
JSONRPCErrorCallback,
JSONRPCResponsePayload,
JSONRPCResponseError,
} from 'ethereum-types';
export {
JSONRPCRequestPayloadWithMethod,
NextCallback,
ErrorCallback,
OnNextCompleted,
Callback,
} from '@0x/subproviders';

View File

@ -1,16 +1,20 @@
import {
AbstractArtifactAdapter,
constants,
ContractData,
EvmCallStack,
getRevertTrace,
getSourceRangeSnippet,
parseSourceMap,
SourceRange,
SourceSnippet,
TraceCollectionSubprovider,
utils,
} from '@0x/sol-trace-based-tools-common';
import { stripHexPrefix } from 'ethereumjs-util';
import * as _ from 'lodash';
import { getLogger, levels, Logger } from 'loglevel';
import { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
import { constants } from './constants';
import { getSourceRangeSnippet } from './get_source_range_snippet';
import { getRevertTrace } from './revert_trace';
import { parseSourceMap } from './source_maps';
import { TraceCollectionSubprovider } from './trace_collection_subprovider';
import { ContractData, EvmCallStack, SourceRange, SourceSnippet } from './types';
import { utils } from './utils';
/**
* This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface.
* It is used to report call stack traces whenever a revert occurs.
@ -35,7 +39,7 @@ export class RevertTraceSubprovider extends TraceCollectionSubprovider {
};
super(defaultFromAddress, traceCollectionSubproviderConfig);
this._artifactAdapter = artifactAdapter;
this._logger = getLogger('sol-cov');
this._logger = getLogger('sol-trace');
this._logger.setLevel(isVerbose ? levels.TRACE : levels.ERROR);
}
// tslint:disable-next-line:no-unused-variable

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*"]
}

View File

@ -0,0 +1,3 @@
{
"extends": ["@0x/tslint-config"]
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*"]
}

View File

@ -1,12 +1,12 @@
# Schemas
The [JSON schemas](http://json-schema.org/) for the API payloads and responses can be found in [@0xproject/json-schemas](https://github.com/0xProject/0x.js/tree/development/packages/json-schemas). Examples of each payload and response can be found in the library's [test suite](https://github.com/0xProject/0x.js/blob/development/packages/json-schemas/test/schema_test.ts#L1).
The [JSON schemas](http://json-schema.org/) for the API payloads and responses can be found in [@0xproject/json-schemas](https://github.com/0xProject/0x-monorepo/tree/development/packages/json-schemas). Examples of each payload and response can be found in the library's [test suite](https://github.com/0xProject/0x-monorepo/blob/development/packages/json-schemas/test/schema_test.ts#L1).
```bash
npm install @0xproject/json-schemas --save
```
You can easily validate your API's payloads and responses using the [@0xproject/json-schemas](https://github.com/0xProject/0x.js/tree/development/packages/json-schemas) package:
You can easily validate your API's payloads and responses using the [@0xproject/json-schemas](https://github.com/0xProject/0x-monorepo/tree/development/packages/json-schemas) package:
```js
import {SchemaValidator, ValidatorResult, schemas} from '@0xproject/json-schemas';

View File

@ -1,17 +0,0 @@
**Install**
```bash
yarn add @0xproject/sol-cov
```
**Import**
```javascript
import { CoverageSubprovider } from '@0xproject/sol-cov';
```
or
```javascript
var CoverageSubprovider = require('@0xproject/sol-cov').CoverageSubprovider;
```

View File

@ -1 +0,0 @@
Welcome to the [@0xproject/sol-cov](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-cov) documentation! Sol-cov is a Solidity coverage tool for your smart contract tests.

View File

@ -1,17 +0,0 @@
**Install**
```bash
yarn add @0x/sol-cov
```
**Import**
```javascript
import { CoverageSubprovider } from '@0x/sol-cov';
```
or
```javascript
var CoverageSubprovider = require('@0x/sol-cov').CoverageSubprovider;
```

View File

@ -1 +0,0 @@
Welcome to the [sol-cov](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-cov) documentation! Sol-cov is a Solidity coverage tool for your smart contract tests.

View File

@ -0,0 +1,17 @@
**Install**
```bash
yarn add @0x/sol-coverage
```
**Import**
```javascript
import { CoverageSubprovider } from '@0x/sol-coverage';
```
or
```javascript
var CoverageSubprovider = require('@0x/sol-coverage').CoverageSubprovider;
```

View File

@ -0,0 +1 @@
Welcome to the [sol-coverage](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-coverage) documentation! Sol-coverage is a Solidity coverage tool for your smart contract tests.

View File

@ -1,4 +1,4 @@
Sol-cov uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `CoverageSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with ProviderEngine, please read the [Web3 Provider explained](https://0x.org/wiki#Web3-Provider-Explained) wiki article.
Sol-coverage uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `CoverageSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with ProviderEngine, please read the [Web3 Provider explained](https://0x.org/wiki#Web3-Provider-Explained) wiki article.
The CoverageSubprovider eavesdrops on the `eth_sendTransaction` and `eth_call` RPC calls and collects traces after each call using `debug_traceTransaction`. `eth_call`'s' don't generate traces - so we take a snapshot, re-submit it as a transaction, get the trace and then revert the snapshot.
@ -11,7 +11,7 @@ In order to use `CoverageSubprovider` with your favorite framework you need to p
If you are generating your artifacts with [@0x/sol-compiler](https://0x.org/docs/sol-compiler) you can use the `SolCompilerArtifactsAdapter` we've implemented for you.
```typescript
import { SolCompilerArtifactsAdapter } from '@0x/sol-cov';
import { SolCompilerArtifactsAdapter } from '@0x/sol-coverage';
const artifactsPath = 'src/artifacts';
const contractsPath = 'src/contracts';
const artifactsAdapter = new SolCompilerArtifactsAdapter(artifactsPath, contractsPath);
@ -22,7 +22,7 @@ const artifactsAdapter = new SolCompilerArtifactsAdapter(artifactsPath, contract
If your project is using [Truffle](https://truffleframework.com/), we've written a `TruffleArtifactsAdapter`for you.
```typescript
import { TruffleArtifactAdapter } from '@0x/sol-cov';
import { TruffleArtifactAdapter } from '@0x/sol-coverage';
const contractsPath = 'src/contracts';
const artifactAdapter = new TruffleArtifactAdapter(contractsDir);
```
@ -37,7 +37,7 @@ Look at the code of the two adapters above for examples.
### Usage
```typescript
import { CoverageSubprovider } from '@0x/sol-cov';
import { CoverageSubprovider } from '@0x/sol-coverage';
import ProviderEngine = require('web3-provider-engine');
const provider = new ProviderEngine();

View File

@ -0,0 +1,17 @@
**Install**
```bash
yarn add @0x/sol-profiler
```
**Import**
```javascript
import { ProfilerSubprovider } from '@0x/sol-profiler';
```
or
```javascript
var ProfilerSubprovider = require('@0x/sol-profiler').ProfilerSubprovider;
```

View File

@ -0,0 +1 @@
Welcome to the [sol-profiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-profiler) documentation! Sol-profiler is a Solidity profiler tool.

Some files were not shown because too many files have changed in this diff Show More