From eb89926cee2c50ef657b3c033b5637f527d73c6a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 9 Apr 2018 22:23:25 +0200 Subject: Implement the resolver --- packages/sol-cov/package.json | 4 +- packages/sol-cov/src/collect_contract_data.ts | 22 ++------ packages/sol-cov/src/types.ts | 1 - .../sol-cov/test/collect_contracts_data_test.ts | 1 - .../sol-cov/test/collect_coverage_entries_test.ts | 4 +- .../test/fixtures/artifacts/SimpleStorage.json | 64 ---------------------- .../sol-cov/test/fixtures/artifacts/Simplest.json | 20 ------- .../test/fixtures/contracts/SimpleStorage.sol | 2 + 8 files changed, 13 insertions(+), 105 deletions(-) delete mode 100644 packages/sol-cov/test/fixtures/artifacts/SimpleStorage.json delete mode 100644 packages/sol-cov/test/fixtures/artifacts/Simplest.json (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index f92850db5..277f40130 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -7,13 +7,14 @@ "scripts": { "build:watch": "tsc -w", "lint": "tslint --project . 'src/**/*.ts'", - "test": "run-s clean build run_mocha", + "test": "run-s clean build compile_test run_mocha", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "test:circleci": "yarn test:coverage", "run_mocha": "mocha lib/test/**/*_test.js --exit", "clean": "shx rm -rf lib scripts", "build": "copyfiles 'test/fixtures/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "compile_test": "node ../deployer/lib/src/cli.js compile --contracts SimpleStorage --contracts-dir test/fixtures/contracts --artifacts-dir test/fixtures/artifacts", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", "docs:stage": "yarn build && node ./scripts/stage_docs.js", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", @@ -53,6 +54,7 @@ "solidity-parser-antlr": "^0.2.8" }, "devDependencies": { + "@0xproject/deployer": "^0.3.5", "@0xproject/monorepo-scripts": "^0.1.17", "@0xproject/tslint-config": "^0.4.15", "@types/istanbul": "^0.4.29", diff --git a/packages/sol-cov/src/collect_contract_data.ts b/packages/sol-cov/src/collect_contract_data.ts index e4a13695a..da56e8d0d 100644 --- a/packages/sol-cov/src/collect_contract_data.ts +++ b/packages/sol-cov/src/collect_contract_data.ts @@ -6,27 +6,17 @@ import * as path from 'path'; import { ContractData } from './types'; export const collectContractsData = (artifactsPath: string, sourcesPath: string, networkId: number) => { - const sourcesGlob = `${sourcesPath}/**/*.sol`; - const sourceFileNames = glob.sync(sourcesGlob, { absolute: true }); - const contractsDataIfExists: Array = _.map(sourceFileNames, sourceFileName => { - const baseName = path.basename(sourceFileName, '.sol'); - const artifactFileName = path.join(artifactsPath, `${baseName}.json`); - if (!fs.existsSync(artifactFileName)) { - // If the contract isn't directly compiled, but is imported as the part of the other contract - we don't - // have an artifact for it and therefore can't do anything useful with it - return {}; - } + const artifactsGlob = `${artifactsPath}/**/*.json`; + const artifactFileNames = glob.sync(artifactsGlob, { absolute: true }); + const contractsDataIfExists: Array = _.map(artifactFileNames, artifactFileName => { const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString()); const sources = artifact.networks[networkId].sources; - const sourceCodes = _.map(sources, (source: string) => { - const includedSourceCode = fs.readFileSync(source).toString(); - return includedSourceCode; - }); + const contractName = artifact.contract_name; + const sourceCodes = _.map(sources, (source: string) => fs.readFileSync(source).toString()); if (_.isUndefined(artifact.networks[networkId])) { - throw new Error(`No ${baseName} artifacts found for networkId ${networkId}`); + throw new Error(`No ${contractName} artifacts found for networkId ${networkId}`); } const contractData = { - baseName, sourceCodes, sources, sourceMap: artifact.networks[networkId].source_map, diff --git a/packages/sol-cov/src/types.ts b/packages/sol-cov/src/types.ts index d6491100b..01359d858 100644 --- a/packages/sol-cov/src/types.ts +++ b/packages/sol-cov/src/types.ts @@ -79,7 +79,6 @@ export interface ContractData { runtimeBytecode: string; sourceMapRuntime: string; sourceCodes: string[]; - baseName: string; sources: string[]; } diff --git a/packages/sol-cov/test/collect_contracts_data_test.ts b/packages/sol-cov/test/collect_contracts_data_test.ts index e793085e3..943a4a878 100644 --- a/packages/sol-cov/test/collect_contracts_data_test.ts +++ b/packages/sol-cov/test/collect_contracts_data_test.ts @@ -16,7 +16,6 @@ describe('Collect contracts data', () => { const contractsData = collectContractsData(artifactsPath, sourcesPath, networkId); _.forEach(contractsData, contractData => { expect(contractData).to.have.keys([ - 'baseName', 'sourceCodes', 'sources', 'sourceMap', diff --git a/packages/sol-cov/test/collect_coverage_entries_test.ts b/packages/sol-cov/test/collect_coverage_entries_test.ts index c7bc45bbf..c7b9d44b1 100644 --- a/packages/sol-cov/test/collect_coverage_entries_test.ts +++ b/packages/sol-cov/test/collect_coverage_entries_test.ts @@ -39,13 +39,13 @@ describe('Collect coverage entries', () => { const coverageEntries = collectCoverageEntries(simpleStorageContract); const fnIds = _.keys(coverageEntries.fnMap); expect(coverageEntries.fnMap[fnIds[0]].name).to.be.equal('set'); - expect(coverageEntries.fnMap[fnIds[0]].line).to.be.equal(3); + expect(coverageEntries.fnMap[fnIds[0]].line).to.be.equal(5); const setFunction = `function set(uint x) { storedData = x; }`; expect(getRange(simpleStorageContract, coverageEntries.fnMap[fnIds[0]].loc)).to.be.equal(setFunction); expect(coverageEntries.fnMap[fnIds[1]].name).to.be.equal('get'); - expect(coverageEntries.fnMap[fnIds[1]].line).to.be.equal(6); + expect(coverageEntries.fnMap[fnIds[1]].line).to.be.equal(8); const getFunction = `function get() constant returns (uint retVal) { return storedData; }`; diff --git a/packages/sol-cov/test/fixtures/artifacts/SimpleStorage.json b/packages/sol-cov/test/fixtures/artifacts/SimpleStorage.json deleted file mode 100644 index 416170ef2..000000000 --- a/packages/sol-cov/test/fixtures/artifacts/SimpleStorage.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "contract_name": "SimpleStorage", - "networks": { - "50": { - "solc_version": "0.4.21", - "keccak256": "0x18dc5b5a0e813c17e49936d2f2f7c07c51f050c09ba5e7206f17c855f23f4b6a", - "source_tree_hash": "0x18dc5b5a0e813c17e49936d2f2f7c07c51f050c09ba5e7206f17c855f23f4b6a", - "optimizer_enabled": 0, - "abi": [ - { - "constant": true, - "inputs": [], - "name": "storedData", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "x", - "type": "uint256" - } - ], - "name": "set", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "get", - "outputs": [ - { - "name": "retVal", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } - ], - "bytecode": - "0x6060604052341561000f57600080fd5b6101098061001e6000396000f3006060604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605857806360fe47b114607e5780636d4ce63c14609e575b600080fd5b3415606257600080fd5b606860c4565b6040518082815260200191505060405180910390f35b3415608857600080fd5b609c600480803590602001909190505060ca565b005b341560a857600080fd5b60ae60d4565b6040518082815260200191505060405180910390f35b60005481565b8060008190555050565b600080549050905600a165627a7a723058207f743855fd0c71699620424a21a257cd197ed05032d6768eb9b874e4898f44c60029", - "runtime_bytecode": - "0x6060604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605857806360fe47b114607e5780636d4ce63c14609e575b600080fd5b3415606257600080fd5b606860c4565b6040518082815260200191505060405180910390f35b3415608857600080fd5b609c600480803590602001909190505060ca565b005b341560a857600080fd5b60ae60d4565b6040518082815260200191505060405180910390f35b60005481565b8060008190555050565b600080549050905600a165627a7a723058207f743855fd0c71699620424a21a257cd197ed05032d6768eb9b874e4898f44c60029", - "updated_at": 1521118350895, - "source_map": "26:196:0:-;;;;;;;;;;;;;;;;;", - "source_map_runtime": - "26:196:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;55:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;83:52;;;;;;;;;;;;;;;;;;;;;;;;;;140:80;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;55:22;;;;:::o;83:52::-;127:1;114:10;:14;;;;83:52;:::o;140:80::-;173:11;203:10;;196:17;;140:80;:::o", - "sources": ["SimpleStorage.sol"] - } - } -} diff --git a/packages/sol-cov/test/fixtures/artifacts/Simplest.json b/packages/sol-cov/test/fixtures/artifacts/Simplest.json deleted file mode 100644 index 8de60e481..000000000 --- a/packages/sol-cov/test/fixtures/artifacts/Simplest.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "contract_name": "Simplest", - "networks": { - "50": { - "solc_version": "0.4.21", - "keccak256": "0x8e7d62e19c7c7b8bf9a4a43749e111605950cc877574fb9640a1a07d1c3749f9", - "source_tree_hash": "0x8e7d62e19c7c7b8bf9a4a43749e111605950cc877574fb9640a1a07d1c3749f9", - "optimizer_enabled": 0, - "abi": [], - "bytecode": - "0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a7230582097cfe05b4d18d6ffb3a8d8fab0570cf09640d3131b9677ddb9be4e9fbcb65f010029", - "runtime_bytecode": - "0x6060604052600080fd00a165627a7a7230582097cfe05b4d18d6ffb3a8d8fab0570cf09640d3131b9677ddb9be4e9fbcb65f010029", - "updated_at": 1521118525393, - "source_map": "26:21:0:-;;;;;;;;;;;;;;;;;", - "source_map_runtime": "26:21:0:-;;;;;", - "sources": ["Simplest.sol"] - } - } -} diff --git a/packages/sol-cov/test/fixtures/contracts/SimpleStorage.sol b/packages/sol-cov/test/fixtures/contracts/SimpleStorage.sol index 178a52318..e4b4ac246 100644 --- a/packages/sol-cov/test/fixtures/contracts/SimpleStorage.sol +++ b/packages/sol-cov/test/fixtures/contracts/SimpleStorage.sol @@ -1,3 +1,5 @@ +pragma solidity ^0.4.21; + contract SimpleStorage { uint public storedData; function set(uint x) { -- cgit v1.2.3