Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into support-global-npm
Browse files Browse the repository at this point in the history
  • Loading branch information
CruzMolina committed Apr 18, 2019
2 parents 330a6ce + d3bb42b commit 9d820a9
Show file tree
Hide file tree
Showing 55 changed files with 2,213 additions and 513 deletions.
4 changes: 2 additions & 2 deletions packages/truffle-artifactor/package.json
@@ -1,6 +1,6 @@
{
"name": "truffle-artifactor",
"version": "4.0.10",
"version": "4.0.11",
"description": "A contract packager for Ethereum and Javascript",
"author": "Tim Coulter",
"main": "./index.js",
Expand All @@ -25,7 +25,7 @@
"debug": "^4.1.0",
"fs-extra": "6.0.1",
"lodash": "4.17.11",
"truffle-contract": "^4.0.11",
"truffle-contract": "^4.0.12",
"truffle-contract-schema": "^3.0.6",
"truffle-expect": "^0.0.7"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/truffle-box/package.json
@@ -1,6 +1,6 @@
{
"name": "truffle-box",
"version": "1.0.20",
"version": "1.0.21",
"description": "Truffle project boilerplate utility",
"main": "box.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"eslint": "^4.0.0",
"mocha": "5.2.0",
"sinon": "^6.3.4",
"truffle-config": "^1.1.7"
"truffle-config": "^1.1.8"
},
"dependencies": {
"fs-extra": "6.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/truffle-compile-vyper/package.json
@@ -1,18 +1,18 @@
{
"name": "truffle-compile-vyper",
"version": "1.0.10",
"version": "1.0.11",
"description": "Vyper compiler support",
"main": "index.js",
"dependencies": {
"async": "2.6.1",
"colors": "^1.1.2",
"eslint": "^5.5.0",
"minimatch": "^3.0.4",
"truffle-compile": "^4.0.10"
"truffle-compile": "^4.0.11"
},
"devDependencies": {
"mocha": "^5.2.0",
"truffle-config": "^1.1.7"
"truffle-config": "^1.1.8"
},
"scripts": {
"test": "mocha"
Expand Down
Expand Up @@ -12,24 +12,17 @@ class Docker extends LoadingStrategy {
const command =
"docker run -i ethereum/solc:" + this.config.version + " --standard-json";

const versionRange = new VersionRange();
const commit = versionRange.getCommitFromVersion(versionString);

return versionRange
.getSolcByCommit(commit)
.then(solcjs => {
return {
compile: options => String(execSync(command, { input: options })),
version: () => versionString,
importsParser: solcjs
};
})
.catch(error => {
if (error.message === "No matching version found") {
throw this.errors("noVersion", versionString);
}
throw new Error(error);
});
try {
return {
compile: options => String(execSync(command, { input: options })),
version: () => versionString
};
} catch (error) {
if (error.message === "No matching version found") {
throw this.errors("noVersion", versionString);
}
throw new Error(error);
}
}

getDockerTags() {
Expand Down
Expand Up @@ -7,23 +7,17 @@ class Native extends LoadingStrategy {
const versionString = this.validateAndGetSolcVersion();
const command = "solc --standard-json";

const versionRange = new VersionRange();
const commit = versionRange.getCommitFromVersion(versionString);
return versionRange
.getSolcByCommit(commit)
.then(solcjs => {
return {
compile: options => String(execSync(command, { input: options })),
version: () => versionString,
importsParser: solcjs
};
})
.catch(error => {
if (error.message === "No matching version found") {
throw this.errors("noVersion", versionString);
}
throw new Error(error);
});
try {
return {
compile: options => String(execSync(command, { input: options })),
version: () => versionString
};
} catch (error) {
if (error.message === "No matching version found") {
throw this.errors("noVersion", versionString);
}
throw new Error(error);
}
}

validateAndGetSolcVersion() {
Expand Down
6 changes: 3 additions & 3 deletions packages/truffle-compile/package.json
@@ -1,6 +1,6 @@
{
"name": "truffle-compile",
"version": "4.0.10",
"version": "4.0.11",
"description": "Compiler helper and artifact manager",
"main": "index.js",
"dependencies": {
Expand All @@ -14,7 +14,7 @@
"require-from-string": "^2.0.2",
"semver": "^5.6.0",
"solc": "0.5.0",
"truffle-config": "^1.1.7",
"truffle-config": "^1.1.8",
"truffle-contract-sources": "^0.1.3",
"truffle-error": "^0.0.4",
"truffle-expect": "^0.0.7"
Expand All @@ -26,7 +26,7 @@
"mocha": "5.2.0",
"sinon": "^7.2.2",
"tmp": "0.0.33",
"truffle-resolver": "^5.0.10"
"truffle-resolver": "^5.0.11"
},
"babel": {
"presets": [
Expand Down
55 changes: 22 additions & 33 deletions packages/truffle-compile/parser.js
@@ -1,13 +1,13 @@
const debug = require("debug")("compile:parser"); // eslint-disable-line no-unused-vars
var CompileError = require("./compileerror");
const CompileError = require("./compileerror");

// Warning issued by a pre-release compiler version, ignored by this component.
var preReleaseCompilerWarning =
const preReleaseCompilerWarning =
"This is a pre-release compiler version, please do not use it in production.";

module.exports = {
// This needs to be fast! It is fast (as of this writing). Keep it fast!
parseImports: function(body, solc) {
parseImports(body, solc) {
// WARNING: Kind of a hack (an expedient one).

// So we don't have to maintain a separate parser, we'll get all the imports
Expand All @@ -17,18 +17,15 @@ module.exports = {
// statement right on the end; just to ensure it will error and we can parse
// the imports speedily without doing extra work.

// If we're using docker/native, we'll still want to use solcjs to do this part.
if (solc.importsParser) solc = solc.importsParser;

// Helper to detect import errors with an easy regex.
var importErrorKey = "TRUFFLE_IMPORT";
const importErrorKey = "not found: File";

// Inject failing import.
var failingImportFileName = "__Truffle__NotFound.sol";
const failingImportFileName = "__Truffle__NotFound.sol";

body = body + "\n\nimport '" + failingImportFileName + "';\n";
body = `${body}\n\nimport '${failingImportFileName}';\n`;

var solcStandardInput = {
const solcStandardInput = {
language: "Solidity",
sources: {
"ParsedContract.sol": {
Expand All @@ -44,27 +41,21 @@ module.exports = {
}
};

var output = solc.compile(JSON.stringify(solcStandardInput), function() {
// The existence of this function ensures we get a parsable error message.
// Without this, we'll get an error message we *can* detect, but the key will make it easier.
// Note: This is not a normal callback. See docs here: https://github.com/ethereum/solc-js#from-version-021
return { error: importErrorKey };
});

// By compiling only with ParsedContract.sol as the source, solc.compile returns file import errors for each import path.
let output = solc.compile(JSON.stringify(solcStandardInput));
output = JSON.parse(output);

// Filter out the "pre-release compiler" warning, if present.
var errors = output.errors.filter(function(solidity_error) {
return solidity_error.message.indexOf(preReleaseCompilerWarning) < 0;
});
const errors = output.errors.filter(
({ message }) => !message.includes(preReleaseCompilerWarning)
);

var nonImportErrors = errors.filter(function(solidity_error) {
// If the import error key is not found, we must not have an import error.
// This means we have a *different* parsing error which we should show to the user.
// Note: solc can return multiple parsing errors at once.
// We ignore the "pre-release compiler" warning message.
return solidity_error.formattedMessage.indexOf(importErrorKey) < 0;
});
// If the import error key is not found, we must not have an import error.
// This means we have a *different* parsing error which we should show to the user.
// Note: solc can return multiple parsing errors at once.
const nonImportErrors = errors.filter(
({ formattedMessage }) => !formattedMessage.includes(importErrorKey)
);

// Should we try to throw more than one? (aside; we didn't before)
if (nonImportErrors.length > 0) {
Expand All @@ -73,12 +64,10 @@ module.exports = {

// Now, all errors must be import errors.
// Filter out our forced import, then get the import paths of the rest.
var imports = errors
.filter(function(solidity_error) {
return solidity_error.message.indexOf(failingImportFileName) < 0;
})
.map(function(solidity_error) {
var matches = solidity_error.formattedMessage.match(
const imports = errors
.filter(({ message }) => !message.includes(failingImportFileName))
.map(({ formattedMessage }) => {
const matches = formattedMessage.match(
/import[^'"]+("|')([^'"]+)("|')/
);

Expand Down
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity >0.4.15;

import "./Dependency.sol";
import "./path/to/AnotherDep.sol";
Expand Down
@@ -1,5 +1,5 @@
paragma solidity ^0.4.0;
paragma solidity >0.4.0;

contract Error {
}

}
78 changes: 58 additions & 20 deletions packages/truffle-compile/test/test_parser.js
@@ -1,15 +1,15 @@
var fs = require("fs");
var path = require("path");
var Parser = require("../parser");
var CompilerSupplier = require("../compilerSupplier");
var assert = require("assert");

describe("Parser", function() {
var source = null;
var erroneousSource = null;
var solc;

before("get code", async function() {
const fs = require("fs");
const path = require("path");
const Parser = require("../parser");
const CompilerSupplier = require("../compilerSupplier");
const assert = require("assert");

describe("Parser", () => {
let source = null;
let erroneousSource = null;
let solc;

before("get code", async () => {
source = fs.readFileSync(
path.join(__dirname, "./sources/badSources/MyContract.sol"),
"utf-8"
Expand All @@ -18,18 +18,17 @@ describe("Parser", function() {
path.join(__dirname, "./sources/badSources/ShouldError.sol"),
"utf-8"
);

const supplier = new CompilerSupplier();
solc = await supplier.load();
});

it("should return correct imports", function() {
var imports = Parser.parseImports(source, solc);
it("should return correct imports with solcjs", () => {
const imports = Parser.parseImports(source, solc);

// Note that this test is important because certain parts of the solidity
// output cuts off path prefixes like "./" and "../../../". If we get the
// imports list incorrectly, we'll have collisions.
var expected = [
const expected = [
"./Dependency.sol",
"./path/to/AnotherDep.sol",
"../../../path/to/AnotherDep.sol",
Expand All @@ -39,8 +38,48 @@ describe("Parser", function() {
assert.deepEqual(imports, expected);
});

it("should throw an error when parsing imports if there's an actual parse error", function() {
var error = null;
it("should return correct imports with native solc", () => {
const config = { version: "native" };
const nativeSupplier = new CompilerSupplier(config);
nativeSupplier.load().then(nativeSolc => {
const imports = Parser.parseImports(source, nativeSolc);

// Note that this test is important because certain parts of the solidity
// output cuts off path prefixes like "./" and "../../../". If we get the
// imports list incorrectly, we'll have collisions.
const expected = [
"./Dependency.sol",
"./path/to/AnotherDep.sol",
"../../../path/to/AnotherDep.sol",
"ethpmpackage/Contract.sol"
];

assert.deepEqual(imports, expected);
});
});

it("should return correct imports with docker solc", () => {
const config = { docker: true, version: "0.4.25" };
const dockerSupplier = new CompilerSupplier(config);
dockerSupplier.load().then(dockerSolc => {
const imports = Parser.parseImports(source, dockerSolc);

// Note that this test is important because certain parts of the solidity
// output cuts off path prefixes like "./" and "../../../". If we get the
// imports list incorrectly, we'll have collisions.
const expected = [
"./Dependency.sol",
"./path/to/AnotherDep.sol",
"../../../path/to/AnotherDep.sol",
"ethpmpackage/Contract.sol"
];

assert.deepEqual(imports, expected);
});
});

it("should throw an error when parsing imports if there's an actual parse error", () => {
let error = null;
try {
Parser.parseImports(erroneousSource, solc);
} catch (e) {
Expand All @@ -52,8 +91,7 @@ describe("Parser", function() {
}

assert(
error.message.indexOf("Expected pragma, import directive or contract") >=
0
error.message.includes("Expected pragma, import directive or contract")
);
});
});

0 comments on commit 9d820a9

Please sign in to comment.