From 749ec0cefe095805f76dca2f81025ebfbd98de2a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 13:38:40 +0200 Subject: Add a TODO for failed transactions --- packages/sol-cov/src/trace_collection_subprovider.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/src/trace_collection_subprovider.ts b/packages/sol-cov/src/trace_collection_subprovider.ts index b530b59db..0aa592bd5 100644 --- a/packages/sol-cov/src/trace_collection_subprovider.ts +++ b/packages/sol-cov/src/trace_collection_subprovider.ts @@ -176,6 +176,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider { const txHash = await this._web3Wrapper.sendTransactionAsync(fakeTxData); await this._web3Wrapper.awaitTransactionMinedAsync(txHash, 0); } catch (err) { + // TODO(logvinov) Check that transaction failed and not some other exception // Even if this transaction failed - we've already recorded it's trace. _.noop(); } -- cgit v1.2.3 From c94168981c13de52ed0334bac5fee2e0ea14a4ef Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 13:42:05 +0200 Subject: Use CallDataRPC in subprovider --- packages/sol-cov/src/trace_collection_subprovider.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/src/trace_collection_subprovider.ts b/packages/sol-cov/src/trace_collection_subprovider.ts index 0aa592bd5..b6486e6f7 100644 --- a/packages/sol-cov/src/trace_collection_subprovider.ts +++ b/packages/sol-cov/src/trace_collection_subprovider.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { Callback, ErrorCallback, NextCallback, Subprovider } from '@0xproject/subproviders'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { CallData, JSONRPCRequestPayload, Provider, TxData } from 'ethereum-types'; +import { CallDataRPC, marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; +import { JSONRPCRequestPayload, Provider, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import { Lock } from 'semaphore-async-await'; @@ -152,7 +152,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider { cb(); } private async _onCallOrGasEstimateExecutedAsync( - callData: Partial, + callData: Partial, _err: Error | null, _callResult: string, cb: Callback, @@ -160,20 +160,21 @@ export abstract class TraceCollectionSubprovider extends Subprovider { await this._recordCallOrGasEstimateTraceAsync(callData); cb(); } - private async _recordCallOrGasEstimateTraceAsync(callData: Partial): Promise { + private async _recordCallOrGasEstimateTraceAsync(callData: Partial): Promise { // We don't want other transactions to be exeucted during snashotting period, that's why we lock the // transaction execution for all transactions except our fake ones. await this._lock.acquire(); const blockchainLifecycle = new BlockchainLifecycle(this._web3Wrapper); await blockchainLifecycle.startAsync(); - const fakeTxData: MaybeFakeTxData = { - gas: BLOCK_GAS_LIMIT, + const fakeTxData = { + gas: BLOCK_GAS_LIMIT.toString(16), // tslint:disable-line:custom-no-magic-numbers isFakeTransaction: true, // This transaction (and only it) is allowed to come through when the lock is locked ...callData, from: callData.from || this._defaultFromAddress, }; try { - const txHash = await this._web3Wrapper.sendTransactionAsync(fakeTxData); + const txData = marshaller.unmarshalTxData(fakeTxData); + const txHash = await this._web3Wrapper.sendTransactionAsync(txData); await this._web3Wrapper.awaitTransactionMinedAsync(txHash, 0); } catch (err) { // TODO(logvinov) Check that transaction failed and not some other exception -- cgit v1.2.3 From e80fa6e311e7f975e2e9f47b0dec65829894bde3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 13:42:47 +0200 Subject: Read truffle compiler config from truffle.js and assert that the passed solidity version matches the one in artifacts --- .../artifact_adapters/truffle_artifact_adapter.ts | 58 +++++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts index 53b77aed5..c662b62b1 100644 --- a/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts +++ b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts @@ -1,25 +1,40 @@ import { Compiler, CompilerOptions } from '@0xproject/sol-compiler'; -import * as rimraf from 'rimraf'; +import * as fs from 'fs'; +import * as glob from 'glob'; +import * as path from 'path'; import { ContractData } from '../types'; import { AbstractArtifactAdapter } from './abstract_artifact_adapter'; import { SolCompilerArtifactAdapter } from './sol_compiler_artifact_adapter'; +const DEFAULT_TRUFFLE_ARTIFACTS_DIR = './build/contracts'; + +interface TruffleConfig { + solc?: any; + contracts_build_directory?: string; +} + export class TruffleArtifactAdapter extends AbstractArtifactAdapter { private readonly _solcVersion: string; - private readonly _sourcesPath: string; - constructor(sourcesPath: string, solcVersion: string) { + private readonly _projectRoot: string; + constructor(projectRoot: string, solcVersion: string) { super(); this._solcVersion = solcVersion; - this._sourcesPath = sourcesPath; + this._projectRoot = projectRoot; } public async collectContractsDataAsync(): Promise { const artifactsDir = '.0x-artifacts'; + const contractsDir = path.join(this._projectRoot, 'contracts'); + const truffleConfig = this._getTruffleConfig(); + const solcConfig = truffleConfig.solc || {}; + const truffleArtifactsDirectory = truffleConfig.contracts_build_directory || DEFAULT_TRUFFLE_ARTIFACTS_DIR; + this._assertSolidityVersionIsCorrect(truffleArtifactsDirectory); const compilerOptions: CompilerOptions = { - contractsDir: this._sourcesPath, + contractsDir, artifactsDir, compilerSettings: { + ...solcConfig, outputSelection: { ['*']: { ['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'], @@ -31,9 +46,38 @@ export class TruffleArtifactAdapter extends AbstractArtifactAdapter { }; const compiler = new Compiler(compilerOptions); await compiler.compileAsync(); - const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, this._sourcesPath); + const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, contractsDir); const contractsDataFrom0xArtifacts = await solCompilerArtifactAdapter.collectContractsDataAsync(); - rimraf.sync(artifactsDir); return contractsDataFrom0xArtifacts; } + private _getTruffleConfig(): TruffleConfig { + const truffleConfigFileShort = path.resolve(path.join(this._projectRoot, 'truffle.js')); + const truffleConfigFileLong = path.resolve(path.join(this._projectRoot, 'truffle-config.js')); + if (fs.existsSync(truffleConfigFileShort)) { + const truffleConfig = require(truffleConfigFileShort); + return truffleConfig; + } else if (fs.existsSync(truffleConfigFileLong)) { + const truffleConfig = require(truffleConfigFileLong); + return truffleConfig; + } else { + throw new Error( + `Neither ${truffleConfigFileShort} nor ${truffleConfigFileLong} exists. Make sure the project root is correct`, + ); + } + } + private _assertSolidityVersionIsCorrect(truffleArtifactsDirectory: string): void { + const artifactsGlob = `${truffleArtifactsDirectory}/**/*.json`; + const artifactFileNames = glob.sync(artifactsGlob, { absolute: true }); + for (const artifactFileName of artifactFileNames) { + const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString()); + const compilerVersion = artifact.compiler.version; + if (!compilerVersion.startsWith(this._solcVersion)) { + throw new Error( + `${artifact.contractName} was compiled with solidity ${compilerVersion} but specified version is ${ + this._solcVersion + } it will make sol-cov unable to process traces. Please pass the correct version`, + ); + } + } + } } -- cgit v1.2.3 From 81f689e6933881702ed95798b45b7347de1dff77 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 13:57:19 +0200 Subject: Add sol-cov CHANGELOG --- packages/sol-cov/CHANGELOG.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/CHANGELOG.json b/packages/sol-cov/CHANGELOG.json index 5a1fdc712..ddf81517e 100644 --- a/packages/sol-cov/CHANGELOG.json +++ b/packages/sol-cov/CHANGELOG.json @@ -1,4 +1,24 @@ [ + { + "version": "2.0.0", + "changes": [ + { + "note": "Fix a bug when eth_call coverage was not computed because of silent schema validation failures" + }, + { + "note": "Make `TruffleArtifactAdapter` read the `truffle.js` config for `solc` settings" + }, + { + "note": + "Change the first param of `TruffleArtifactAdapter` to be the `projectRoot` instead of `sourcesDir`" + }, + { + "note": + "Throw a helpful error message if truffle artifacts were generated with a different solc version than the one passed in" + } + ], + "timestamp": 1532619515 + }, { "version": "1.0.3", "changes": [ -- cgit v1.2.3 From 477c3dc4f6a0db036b803f77347c0515d617ca61 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 16:28:00 +0200 Subject: Add PR numbers --- packages/sol-cov/CHANGELOG.json | 16 ++++++++++------ .../src/artifact_adapters/truffle_artifact_adapter.ts | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/CHANGELOG.json b/packages/sol-cov/CHANGELOG.json index ddf81517e..1a0fe43ca 100644 --- a/packages/sol-cov/CHANGELOG.json +++ b/packages/sol-cov/CHANGELOG.json @@ -3,21 +3,25 @@ "version": "2.0.0", "changes": [ { - "note": "Fix a bug when eth_call coverage was not computed because of silent schema validation failures" + "note": + "Fix a bug when eth_call coverage was not computed because of silent schema validation failures", + "pr": 938 }, { - "note": "Make `TruffleArtifactAdapter` read the `truffle.js` config for `solc` settings" + "note": "Make `TruffleArtifactAdapter` read the `truffle.js` config for `solc` settings", + "pr": 938 }, { "note": - "Change the first param of `TruffleArtifactAdapter` to be the `projectRoot` instead of `sourcesDir`" + "Change the first param of `TruffleArtifactAdapter` to be the `projectRoot` instead of `sourcesDir`", + "pr": 938 }, { "note": - "Throw a helpful error message if truffle artifacts were generated with a different solc version than the one passed in" + "Throw a helpful error message if truffle artifacts were generated with a different solc version than the one passed in", + "pr": 938 } - ], - "timestamp": 1532619515 + ] }, { "version": "1.0.3", diff --git a/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts index c662b62b1..2706435cc 100644 --- a/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts +++ b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts @@ -75,7 +75,7 @@ export class TruffleArtifactAdapter extends AbstractArtifactAdapter { throw new Error( `${artifact.contractName} was compiled with solidity ${compilerVersion} but specified version is ${ this._solcVersion - } it will make sol-cov unable to process traces. Please pass the correct version`, + } making it impossible for sol-cov to process traces`, ); } } -- cgit v1.2.3 From 6e2e658162a5a128b722ba105f92fa5267c4bd62 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 8 Aug 2018 11:27:38 -0700 Subject: Update TypeScript to version 2.9.2 --- packages/sol-cov/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index ee87543db..41758b30d 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -89,7 +89,7 @@ "sinon": "^4.0.0", "tslint": "5.11.0", "typedoc": "0xProject/typedoc", - "typescript": "2.7.1" + "typescript": "2.9.2" }, "publishConfig": { "access": "public" -- cgit v1.2.3 From f3761af5678503320b7a3e989a743b847ef4245f Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Thu, 9 Aug 2018 11:33:32 -0700 Subject: fix: Update dependencies --- packages/sol-cov/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index 41758b30d..ae53191cf 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -61,7 +61,7 @@ "ethereumjs-util": "^5.1.1", "glob": "^7.1.2", "istanbul": "^0.4.5", - "lodash": "^4.17.4", + "lodash": "^4.17.5", "loglevel": "^1.6.1", "mkdirp": "^0.5.1", "rimraf": "^2.6.2", @@ -82,7 +82,7 @@ "copyfiles": "^1.2.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", - "mocha": "^4.0.1", + "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "nyc": "^11.0.1", "shx": "^0.2.2", -- cgit v1.2.3 From 7c8a7a24209ae518d7a7d3c45829d75d224ce3a3 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 13 Aug 2018 18:34:37 -0700 Subject: Updated CHANGELOGS --- packages/sol-cov/CHANGELOG.json | 3 ++- packages/sol-cov/CHANGELOG.md | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/CHANGELOG.json b/packages/sol-cov/CHANGELOG.json index 1a0fe43ca..5f6b1685b 100644 --- a/packages/sol-cov/CHANGELOG.json +++ b/packages/sol-cov/CHANGELOG.json @@ -21,7 +21,8 @@ "Throw a helpful error message if truffle artifacts were generated with a different solc version than the one passed in", "pr": 938 } - ] + ], + "timestamp": 1534210131 }, { "version": "1.0.3", diff --git a/packages/sol-cov/CHANGELOG.md b/packages/sol-cov/CHANGELOG.md index aeeaa5b62..d7bdb9614 100644 --- a/packages/sol-cov/CHANGELOG.md +++ b/packages/sol-cov/CHANGELOG.md @@ -5,6 +5,13 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v2.0.0 - _August 13, 2018_ + + * Fix a bug when eth_call coverage was not computed because of silent schema validation failures (#938) + * Make `TruffleArtifactAdapter` read the `truffle.js` config for `solc` settings (#938) + * Change the first param of `TruffleArtifactAdapter` to be the `projectRoot` instead of `sourcesDir` (#938) + * Throw a helpful error message if truffle artifacts were generated with a different solc version than the one passed in (#938) + ## v1.0.3 - _July 26, 2018_ * Dependencies updated @@ -17,7 +24,7 @@ CHANGELOG * Dependencies updated -## v1.0.0 - _July 20, 2018_ +## v1.0.0 - _July 19, 2018_ * Add artifact adapter as a parameter for `CoverageSubprovider`. Export `AbstractArtifactAdapter` (#589) * Implement `SolCompilerArtifactAdapter` and `TruffleArtifactAdapter` (#589) @@ -50,7 +57,7 @@ CHANGELOG * Dependencies updated -## v0.1.0 - _June 1, 2018_ +## v0.1.0 - _May 31, 2018_ * Incorrect publish that was unpublished @@ -58,7 +65,7 @@ CHANGELOG * Dependencies updated -## v0.0.10 - _May 5, 2018_ +## v0.0.10 - _May 4, 2018_ * Dependencies updated -- cgit v1.2.3 From fadd292ecf367e42154856509d0ea0c20b23f2f1 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 13 Aug 2018 18:34:51 -0700 Subject: Publish - 0x.js@1.0.1-rc.3 - @0xproject/abi-gen@1.0.5 - @0xproject/assert@1.0.5 - @0xproject/base-contract@2.0.0-rc.1 - @0xproject/connect@1.0.5 - @0xproject/contract-wrappers@1.0.1-rc.3 - contracts@2.1.40 - @0xproject/dev-utils@1.0.4 - ethereum-types@1.0.4 - @0xproject/fill-scenarios@1.0.1-rc.3 - @0xproject/json-schemas@1.0.1-rc.4 - @0xproject/metacoin@0.0.15 - @0xproject/migrations@1.0.4 - @0xproject/monorepo-scripts@1.0.5 - @0xproject/order-utils@1.0.1-rc.3 - @0xproject/order-watcher@1.0.1-rc.3 - @0xproject/react-docs@1.0.5 - @0xproject/react-docs-example@0.0.20 - @0xproject/react-shared@1.0.6 - @0xproject/sol-compiler@1.0.5 - @0xproject/sol-cov@2.0.0 - @0xproject/sol-resolver@1.0.5 - @0xproject/sra-api@1.0.1-rc.4 - @0xproject/sra-report@1.0.5 - @0xproject/subproviders@1.0.5 - @0xproject/testnet-faucets@1.0.41 - @0xproject/tslint-config@1.0.5 - @0xproject/types@1.0.1-rc.4 - @0xproject/typescript-typings@1.0.4 - @0xproject/utils@1.0.5 - @0xproject/web3-wrapper@1.2.0 - @0xproject/website@0.0.44 --- packages/sol-cov/package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index ae53191cf..4c3000360 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/sol-cov", - "version": "1.0.3", + "version": "2.0.0", "engines": { "node": ">=6.12" }, @@ -50,14 +50,14 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/sol-cov/README.md", "dependencies": { - "@0xproject/dev-utils": "^1.0.3", - "@0xproject/sol-compiler": "^1.0.4", - "@0xproject/subproviders": "^1.0.4", - "@0xproject/typescript-typings": "^1.0.3", - "@0xproject/utils": "^1.0.4", - "@0xproject/web3-wrapper": "^1.1.2", + "@0xproject/dev-utils": "^1.0.4", + "@0xproject/sol-compiler": "^1.0.5", + "@0xproject/subproviders": "^1.0.5", + "@0xproject/typescript-typings": "^1.0.4", + "@0xproject/utils": "^1.0.5", + "@0xproject/web3-wrapper": "^1.2.0", "@types/solidity-parser-antlr": "^0.2.1", - "ethereum-types": "^1.0.3", + "ethereum-types": "^1.0.4", "ethereumjs-util": "^5.1.1", "glob": "^7.1.2", "istanbul": "^0.4.5", @@ -69,8 +69,8 @@ "solidity-parser-antlr": "^0.2.12" }, "devDependencies": { - "@0xproject/monorepo-scripts": "^1.0.4", - "@0xproject/tslint-config": "^1.0.4", + "@0xproject/monorepo-scripts": "^1.0.5", + "@0xproject/tslint-config": "^1.0.5", "@types/istanbul": "^0.4.30", "@types/loglevel": "^1.5.3", "@types/mkdirp": "^0.5.1", -- cgit v1.2.3