diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-04-10 03:54:50 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-04-12 18:52:21 +0800 |
commit | 783314c037a85effbc377fdc01cd40235ad388ed (patch) | |
tree | a9b531af9b5a6cfdc34674baf9c874c303a11072 /packages | |
parent | 15cf64318ccc852fa2e779ea4e3685a406bab851 (diff) | |
download | dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar.gz dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar.bz2 dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar.lz dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar.xz dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.tar.zst dexon-0x-contracts-783314c037a85effbc377fdc01cd40235ad388ed.zip |
Improve on readability
Diffstat (limited to 'packages')
-rw-r--r-- | packages/deployer/src/compiler.ts | 24 | ||||
-rw-r--r-- | packages/deployer/test/compiler_utils_test.ts | 8 | ||||
-rw-r--r-- | packages/sol-cov/src/collect_contract_data.ts | 7 |
3 files changed, 16 insertions, 23 deletions
diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index ad35a7794..af0e83dbc 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -112,15 +112,16 @@ export class Compiler { await createDirIfDoesNotExistAsync(this._artifactsDir); await createDirIfDoesNotExistAsync(SOLC_BIN_DIR); this._contractSources = await Compiler._getContractSourcesAsync(this._contractsDir); - for (const contractName of _.keys(this._contractSources)) { + const contractNames = _.keys(this._contractSources); + for (const contractName of contractNames) { const contractSource = this._contractSources[contractName]; this._setContractSpecificSourceData(contractSource.source, contractName); } - const contractNames = this._specifiedContracts.has(ALL_CONTRACTS_IDENTIFIER) + const contractNamesToCompile = this._specifiedContracts.has(ALL_CONTRACTS_IDENTIFIER) ? _.keys(this._contractSources) : Array.from(this._specifiedContracts.values()); - for (const contractName of contractNames) { - await this._compileContractAsync(contractName); + for (const contractNameToCompile of contractNamesToCompile) { + await this._compileContractAsync(contractNameToCompile); } } /** @@ -172,8 +173,9 @@ export class Compiler { const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename)); logUtils.log(`Compiling ${contractName} with Solidity v${solcVersion}...`); - const source = this._contractSources[contractName].source; - const absoluteFilePath = this._contractSources[contractName].absoluteFilePath; + const contractSource = this._contractSources[contractName]; + const source = contractSource.source; + const absoluteFilePath = contractSource.absoluteFilePath; const standardInput: solc.StandardInput = { language: 'Solidity', sources: { @@ -206,19 +208,17 @@ export class Compiler { if (!_.isUndefined(compiled.errors)) { const SOLIDITY_WARNING = 'warning'; - const isError = (entry: any) => entry.severity !== SOLIDITY_WARNING; - const isWarning = (entry: any) => entry.severity === SOLIDITY_WARNING; - const errors = _.filter(compiled.errors, isError); - const warnings = _.filter(compiled.errors, isWarning); + const errors = _.filter(compiled.errors, entry => entry.severity !== SOLIDITY_WARNING); + const warnings = _.filter(compiled.errors, entry => entry.severity === SOLIDITY_WARNING); if (!_.isEmpty(errors)) { errors.forEach(error => { - const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage); + const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message); logUtils.log(chalk.red(normalizedErrMsg)); }); process.exit(1); } else { warnings.forEach(warning => { - const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage); + const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message); logUtils.log(chalk.yellow(normalizedWarningMsg)); }); } diff --git a/packages/deployer/test/compiler_utils_test.ts b/packages/deployer/test/compiler_utils_test.ts index 246304858..8baa30481 100644 --- a/packages/deployer/test/compiler_utils_test.ts +++ b/packages/deployer/test/compiler_utils_test.ts @@ -50,11 +50,7 @@ describe('Compiler utils', () => { const exchangeSource = await fsWrapper.readFileAsync(`${__dirname}/fixtures/contracts/Exchange.sol`, { encoding: 'utf8', }); - expect(parseDependencies(exchangeSource)).to.be.deep.equal([ - 'TokenTransferProxy.sol', - 'Token.sol', - 'SafeMath.sol', - ]); + expect(parseDependencies(exchangeSource)).to.be.deep.equal(['TokenTransferProxy', 'Token', 'SafeMath']); }); it('correctly parses TokenTransferProxy dependencies', async () => { const exchangeSource = await fsWrapper.readFileAsync( @@ -63,7 +59,7 @@ describe('Compiler utils', () => { encoding: 'utf8', }, ); - expect(parseDependencies(exchangeSource)).to.be.deep.equal(['Token.sol', 'Ownable.sol']); + expect(parseDependencies(exchangeSource)).to.be.deep.equal(['Token', 'Ownable']); }); // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser it.skip('correctly parses commented out dependencies', async () => { diff --git a/packages/sol-cov/src/collect_contract_data.ts b/packages/sol-cov/src/collect_contract_data.ts index a0ce2640f..e4a13695a 100644 --- a/packages/sol-cov/src/collect_contract_data.ts +++ b/packages/sol-cov/src/collect_contract_data.ts @@ -17,11 +17,8 @@ export const collectContractsData = (artifactsPath: string, sourcesPath: string, return {}; } const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString()); - const sources = _.map(artifact.networks[networkId].sources, source => { - const includedFileName = glob.sync(`${sourcesPath}/**/${source}`, { absolute: true })[0]; - return includedFileName; - }); - const sourceCodes = _.map(sources, source => { + const sources = artifact.networks[networkId].sources; + const sourceCodes = _.map(sources, (source: string) => { const includedSourceCode = fs.readFileSync(source).toString(); return includedSourceCode; }); |