From c20285dd3655a9685b52205229e675c797cd4418 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 12:30:54 +0100 Subject: [PATCH 1/9] Fix the undefined opts bug --- packages/sol-compiler/CHANGELOG.json | 4 ++++ packages/sol-compiler/src/compiler.ts | 4 ++-- packages/sol-compiler/test/compiler_test.ts | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index dd65f3aed2..a0d2250aaf 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Fix a bug when smart recompilation wasn't working because of remappings", "pr": 1575 + }, + { + "note": "Fix a bug when opts could not be undefined", + "pr": "TODO" } ] }, diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index c5dea1155f..686ba4f829 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -96,12 +96,12 @@ export class Compiler { * @return An instance of the Compiler class. */ constructor(opts?: CompilerOptions) { - assert.doesConformToSchema('opts', opts, compilerOptionsSchema); + const passedOpts = opts || {}; + assert.doesConformToSchema('opts', passedOpts, compilerOptionsSchema); // TODO: Look for config file in parent directories if not found in current directory const config: CompilerOptions = fs.existsSync(CONFIG_FILE) ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString()) : {}; - const passedOpts = opts || {}; assert.doesConformToSchema('compiler.json', config, compilerOptionsSchema); this._contractsDir = path.resolve(passedOpts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR); this._solcVersionIfExists = passedOpts.solcVersion || config.solcVersion; diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts index 464aa8bb67..5cc7e41ce4 100644 --- a/packages/sol-compiler/test/compiler_test.ts +++ b/packages/sol-compiler/test/compiler_test.ts @@ -23,6 +23,9 @@ describe('#Compiler', function(): void { contractsDir, contracts: constants.contracts, }; + it('should create a Compiler with empty opts', async () => { + const _compiler = new Compiler(); + }); it('should create an Exchange artifact with the correct unlinked binary', async () => { compilerOpts.contracts = ['Exchange']; From 64d6dae672e71f6c81b472a58cb9c443607262c9 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 12:58:46 +0100 Subject: [PATCH 2/9] Remove the bin_paths and fetch the solidity release list from github repo --- packages/sol-compiler/CHANGELOG.json | 4 ++ packages/sol-compiler/src/compiler.ts | 7 +-- packages/sol-compiler/src/solc/bin_paths.ts | 52 --------------------- packages/sol-compiler/src/utils/compiler.ts | 21 +++++++-- packages/sol-compiler/src/utils/types.ts | 4 ++ 5 files changed, 29 insertions(+), 59 deletions(-) delete mode 100644 packages/sol-compiler/src/solc/bin_paths.ts diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index a0d2250aaf..977699ad6e 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -9,6 +9,10 @@ { "note": "Fix a bug when opts could not be undefined", "pr": "TODO" + }, + { + "note": "Remove `bin_paths` and fetch the list of soliidty compilers from github", + "pr": "TODO" } ] }, diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 686ba4f829..45608eb556 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -21,7 +21,6 @@ import * as semver from 'semver'; import solc = require('solc'); import { compilerOptionsSchema } from './schemas/compiler_options_schema'; -import { binPaths } from './solc/bin_paths'; import { addHexPrefixToContractBytecode, compileDockerAsync, @@ -29,6 +28,7 @@ import { createDirIfDoesNotExistAsync, getContractArtifactIfExistsAsync, getDependencyNameToPackagePath, + getSolcJSReleasesAsync, getSourcesWithDependencies, getSourceTreeHash, makeContractPathsRelative, @@ -211,6 +211,7 @@ export class Compiler { // map contract paths to data about them for later verification and persistence const contractPathToData: ContractPathToData = {}; + const solcJSReleases = await getSolcJSReleasesAsync(); const resolvedContractSources = []; for (const contractName of contractNames) { const spyResolver = new SpyResolver(this._resolver); @@ -226,7 +227,7 @@ export class Compiler { } contractPathToData[contractSource.path] = contractData; const solcVersion = _.isUndefined(this._solcVersionIfExists) - ? semver.maxSatisfying(_.keys(binPaths), parseSolidityVersionRange(contractSource.source)) + ? semver.maxSatisfying(_.keys(solcJSReleases), parseSolidityVersionRange(contractSource.source)) : this._solcVersionIfExists; const isFirstContractWithThisVersion = _.isUndefined(versionToInputs[solcVersion]); if (isFirstContractWithThisVersion) { @@ -272,7 +273,7 @@ export class Compiler { fullSolcVersion = versionCommandOutputParts[versionCommandOutputParts.length - 1].trim(); compilerOutput = await compileDockerAsync(solcVersion, input.standardInput); } else { - fullSolcVersion = binPaths[solcVersion]; + fullSolcVersion = solcJSReleases[solcVersion]; compilerOutput = await compileSolcJSAsync(solcVersion, input.standardInput); } if (!_.isUndefined(compilerOutput.errors)) { diff --git a/packages/sol-compiler/src/solc/bin_paths.ts b/packages/sol-compiler/src/solc/bin_paths.ts deleted file mode 100644 index b653c09263..0000000000 --- a/packages/sol-compiler/src/solc/bin_paths.ts +++ /dev/null @@ -1,52 +0,0 @@ -export interface BinaryPaths { - [key: string]: string; -} - -export const binPaths: BinaryPaths = { - '0.5.2': 'soljson-v0.5.2+commit.1df8f40c.js', - '0.5.1': 'soljson-v0.5.1+commit.c8a2cb62.js', - '0.5.0': 'soljson-v0.5.0+commit.1d4f565a.js', - '0.4.25': 'soljson-v0.4.25+commit.59dbf8f1.js', - '0.4.24': 'soljson-v0.4.24+commit.e67f0147.js', - '0.4.23': 'soljson-v0.4.23+commit.124ca40d.js', - '0.4.22': 'soljson-v0.4.22+commit.4cb486ee.js', - '0.4.21': 'soljson-v0.4.21+commit.dfe3193c.js', - '0.4.20': 'soljson-v0.4.20+commit.3155dd80.js', - '0.4.19': 'soljson-v0.4.19+commit.c4cbbb05.js', - '0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js', - '0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js', - '0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js', - '0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js', - '0.4.14': 'soljson-v0.4.14+commit.c2215d46.js', - '0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js', - '0.4.12': 'soljson-v0.4.12+commit.194ff033.js', - '0.4.11': 'soljson-v0.4.11+commit.68ef5810.js', - '0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js', - '0.4.9': 'soljson-v0.4.9+commit.364da425.js', - '0.4.8': 'soljson-v0.4.8+commit.60cc1668.js', - '0.4.7': 'soljson-v0.4.7+commit.822622cf.js', - '0.4.6': 'soljson-v0.4.6+commit.2dabbdf0.js', - '0.4.5': 'soljson-v0.4.5+commit.b318366e.js', - '0.4.4': 'soljson-v0.4.4+commit.4633f3de.js', - '0.4.3': 'soljson-v0.4.3+commit.2353da71.js', - '0.4.2': 'soljson-v0.4.2+commit.af6afb04.js', - '0.4.1': 'soljson-v0.4.1+commit.4fc6fc2c.js', - '0.4.0': 'soljson-v0.4.0+commit.acd334c9.js', - '0.3.6': 'soljson-v0.3.6+commit.3fc68da.js', - '0.3.5': 'soljson-v0.3.5+commit.5f97274.js', - '0.3.4': 'soljson-v0.3.4+commit.7dab890.js', - '0.3.3': 'soljson-v0.3.3+commit.4dc1cb1.js', - '0.3.2': 'soljson-v0.3.2+commit.81ae2a7.js', - '0.3.1': 'soljson-v0.3.1+commit.c492d9b.js', - '0.3.0': 'soljson-v0.3.0+commit.11d6736.js', - '0.2.2': 'soljson-v0.2.2+commit.ef92f56.js', - '0.2.1': 'soljson-v0.2.1+commit.91a6b35.js', - '0.2.0': 'soljson-v0.2.0+commit.4dc2445.js', - '0.1.7': 'soljson-v0.1.7+commit.b4e666c.js', - '0.1.6': 'soljson-v0.1.6+commit.d41f8b7.js', - '0.1.5': 'soljson-v0.1.5+commit.23865e3.js', - '0.1.4': 'soljson-v0.1.4+commit.5f6c3cd.js', - '0.1.3': 'soljson-v0.1.3+commit.28f561.js', - '0.1.2': 'soljson-v0.1.2+commit.d0d36e3.js', - '0.1.1': 'soljson-v0.1.1+commit.6ff4cd6.js', -}; diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts index dffd07b1da..34aa1a3b8c 100644 --- a/packages/sol-compiler/src/utils/compiler.ts +++ b/packages/sol-compiler/src/utils/compiler.ts @@ -9,11 +9,9 @@ import * as path from 'path'; import * as requireFromString from 'require-from-string'; import * as solc from 'solc'; -import { binPaths } from '../solc/bin_paths'; - import { constants } from './constants'; import { fsWrapper } from './fs_wrapper'; -import { CompilationError } from './types'; +import { BinaryPaths, CompilationError } from './types'; /** * Gets contract data on network or returns if an artifact does not exist. @@ -119,6 +117,20 @@ export function parseDependencies(contractSource: ContractSource): string[] { return dependencies; } +let solcJSReleasesCache: BinaryPaths | undefined; + +/** + * Fetches the list of available solidity compilers + */ +export async function getSolcJSReleasesAsync(): Promise { + if (_.isUndefined(solcJSReleasesCache)) { + const versionList = await fetch('https://ethereum.github.io/solc-bin/bin/list.json'); + const versionListJSON = await versionList.json(); + solcJSReleasesCache = versionListJSON.releases; + } + return solcJSReleasesCache as BinaryPaths; +} + /** * Compiles the contracts and prints errors/warnings * @param solcVersion Version of a solc compiler @@ -319,7 +331,8 @@ function recursivelyGatherDependencySources( * @param solcVersion The compiler version. e.g. 0.5.0 */ export async function getSolcJSAsync(solcVersion: string): Promise { - const fullSolcVersion = binPaths[solcVersion]; + const solcJSReleases = await getSolcJSReleasesAsync(); + const fullSolcVersion = solcJSReleases[solcVersion]; if (_.isUndefined(fullSolcVersion)) { throw new Error(`${solcVersion} is not a known compiler version`); } diff --git a/packages/sol-compiler/src/utils/types.ts b/packages/sol-compiler/src/utils/types.ts index 64328899d6..f756c51bb5 100644 --- a/packages/sol-compiler/src/utils/types.ts +++ b/packages/sol-compiler/src/utils/types.ts @@ -13,6 +13,10 @@ export interface ContractSourceData { [contractName: string]: ContractSpecificSourceData; } +export interface BinaryPaths { + [key: string]: string; +} + export interface ContractSpecificSourceData { solcVersionRange: string; sourceHash: Buffer; From d567c58d3b2b8d858977c310b2978e65a587b968 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 13:10:08 +0100 Subject: [PATCH 3/9] Fix a bug when ast and legacyAST were not present in the artifacts even if requested --- packages/sol-compiler/CHANGELOG.json | 4 ++++ packages/sol-compiler/src/utils/compiler.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 977699ad6e..78db31b0f6 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -13,6 +13,10 @@ { "note": "Remove `bin_paths` and fetch the list of soliidty compilers from github", "pr": "TODO" + }, + { + "note": "Fix a bug when ast and legacyAST were not present in the artifacts even if requested", + "pr": "TODO" } ] }, diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts index 34aa1a3b8c..28049e453d 100644 --- a/packages/sol-compiler/src/utils/compiler.ts +++ b/packages/sol-compiler/src/utils/compiler.ts @@ -251,7 +251,7 @@ export function getSourcesWithDependencies( contractPath: string, fullSources: { [sourceName: string]: { id: number } }, ): { sourceCodes: { [sourceName: string]: string }; sources: { [sourceName: string]: { id: number } } } { - const sources = { [contractPath]: { id: fullSources[contractPath].id } }; + const sources = { [contractPath]: fullSources[contractPath] }; const sourceCodes = { [contractPath]: resolver.resolve(contractPath).source }; recursivelyGatherDependencySources( resolver, From 2b7699c26afb96cf043c25973b45926ff32b00d5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 13:20:03 +0100 Subject: [PATCH 4/9] Omit remapping in compiler settings equality checks --- packages/sol-compiler/src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 45608eb556..afa4cc5bb8 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -327,7 +327,7 @@ export class Compiler { const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; const didCompilerSettingsChange = !_.isEqual( _.omit(currentArtifact.compiler.settings, 'remappings'), - this._compilerSettings, + _.omit(this._compilerSettings, 'remappings'), ); const didSourceChange = currentArtifact.sourceTreeHashHex !== contractData.sourceTreeHashHex; return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; From 2e60d5341efbd985b284dbb4c31210025259bf15 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 13:24:57 +0100 Subject: [PATCH 5/9] Add PR numbers --- packages/sol-compiler/CHANGELOG.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 78db31b0f6..7a6174605d 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -8,15 +8,15 @@ }, { "note": "Fix a bug when opts could not be undefined", - "pr": "TODO" + "pr": 1596 }, { "note": "Remove `bin_paths` and fetch the list of soliidty compilers from github", - "pr": "TODO" + "pr": 1596 }, { "note": "Fix a bug when ast and legacyAST were not present in the artifacts even if requested", - "pr": "TODO" + "pr": 1596 } ] }, From 53fe08a348fdf940eb1818327e36ed5637547eb1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 13:30:00 +0100 Subject: [PATCH 6/9] Update CHANGELOG --- packages/sol-compiler/CHANGELOG.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 7a6174605d..434c62211d 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -7,15 +7,15 @@ "pr": 1575 }, { - "note": "Fix a bug when opts could not be undefined", + "note": "Fix a bug when `opts` could not be `undefined`", "pr": 1596 }, { - "note": "Remove `bin_paths` and fetch the list of soliidty compilers from github", + "note": "Remove `bin_paths` and fetch the list of Solidity compilers from Github", "pr": 1596 }, { - "note": "Fix a bug when ast and legacyAST were not present in the artifacts even if requested", + "note": "Fix a bug when `ast` and `legacyAST` were not present in the artifacts even if requested", "pr": 1596 } ] From b54bafe1c57b100a205630e88c8ead5e5358cc6a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 13:35:50 +0100 Subject: [PATCH 7/9] Fix linter --- packages/sol-compiler/test/compiler_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts index 5cc7e41ce4..cae6bce053 100644 --- a/packages/sol-compiler/test/compiler_test.ts +++ b/packages/sol-compiler/test/compiler_test.ts @@ -24,7 +24,7 @@ describe('#Compiler', function(): void { contracts: constants.contracts, }; it('should create a Compiler with empty opts', async () => { - const _compiler = new Compiler(); + const _compiler = new Compiler(); // tslint:disable-line no-unused-variable }); it('should create an Exchange artifact with the correct unlinked binary', async () => { compilerOpts.contracts = ['Exchange']; From 7f2a011c3e64d0010940658ab75eb8da1e99c160 Mon Sep 17 00:00:00 2001 From: Fabio B Date: Thu, 7 Feb 2019 14:17:23 +0100 Subject: [PATCH 8/9] Update packages/sol-compiler/CHANGELOG.json Co-Authored-By: LogvinovLeon --- packages/sol-compiler/CHANGELOG.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 434c62211d..26878c085d 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -7,7 +7,7 @@ "pr": 1575 }, { - "note": "Fix a bug when `opts` could not be `undefined`", + "note": "Fix a bug that made `opts` required instead of optional", "pr": 1596 }, { From 2ff0f545f5535cf6d61b883583643750acae2fbc Mon Sep 17 00:00:00 2001 From: Fabio B Date: Thu, 7 Feb 2019 14:17:41 +0100 Subject: [PATCH 9/9] Update packages/sol-compiler/CHANGELOG.json Co-Authored-By: LogvinovLeon --- packages/sol-compiler/CHANGELOG.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 26878c085d..cded2c3ad2 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -15,7 +15,7 @@ "pr": 1596 }, { - "note": "Fix a bug when `ast` and `legacyAST` were not present in the artifacts even if requested", + "note": "Fix a bug causing `ast` and `legacyAST` to not be added to the artifacts even when requested", "pr": 1596 } ]