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

Commit

Permalink
Merge pull request #5445 from trufflesuite/and-tests
Browse files Browse the repository at this point in the history
Internal improvement: Move compile-solidity tests to a new separate package
  • Loading branch information
eggplantzzz authored Sep 13, 2022
2 parents 89667fe + 57d00cf commit 6bc7700
Show file tree
Hide file tree
Showing 74 changed files with 595 additions and 440 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependency-graph": "lerna-dependency-graph -f pdf -o dependency-graph.pdf",
"solc-bump": "node ./scripts/solc-bump.js",
"update": "lernaupdate",
"depcheck": "lerna exec --stream --no-bail dependency-check --ignore @truffle/contract-tests --ignore @truffle/dashboard-message-bus-e2e-test -- --missing .",
"depcheck": "lerna exec --stream --no-bail dependency-check --ignore @truffle/compile-solidity-tests --ignore @truffle/contract-tests --ignore @truffle/dashboard-message-bus-e2e-test -- --missing .",
"check-truffle-namespace-dependency-versions": "node ./scripts/check-truffle-namespace-dependency-versions.js"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/compile-solidity-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
5 changes: 5 additions & 0 deletions packages/compile-solidity-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `@truffle/compile-solidity-tests`

:information_source: This package houses the tests for
[@truffle/compile-solidity](https://www.npmjs.com/package/@truffle/compile-solidity-tests). This
package is not published and lives only in this monorepo.
53 changes: 53 additions & 0 deletions packages/compile-solidity-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@truffle/compile-solidity-tests",
"description": "Compiler helper and artifact manager for Solidity files",
"license": "MIT",
"author": "Tyler Feickert <[email protected]>",
"homepage": "https://github.com/trufflesuite/truffle/tree/master/packages/compile-solidity-tests#readme",
"repository": {
"type": "git",
"url": "https://github.com/trufflesuite/truffle.git",
"directory": "packages/compile-solidity-tests"
},
"bugs": {
"url": "https://github.com/trufflesuite/truffle/issues"
},
"private": true,
"version": "0.1.0",
"main": "dist/index.js",
"scripts": {
"build": "ttsc",
"prepare": "yarn build",
"test": "./scripts/test.sh"
},
"devDependencies": {
"@truffle/artifactor": "^4.0.168",
"@truffle/compile-solidity": "^6.0.42",
"@truffle/config": "^1.3.37",
"@truffle/resolver": "^9.0.15",
"@types/node": "12.12.21",
"@types/sinon": "^9.0.10",
"babel-core": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"chai": "^4.2.0",
"debug": "^4.3.1",
"fs-extra": "^9.1.0",
"mocha": "9.2.2",
"sinon": "^9.0.2",
"tmp": "^0.2.1",
"ts-node": "10.7.0",
"typescript": "^4.7.4"
},
"keywords": [
"compile",
"ethereum",
"solidity",
"truffle"
],
"babel": {
"presets": [
"env"
]
}
}
12 changes: 12 additions & 0 deletions packages/compile-solidity-tests/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -o errexit

yarn prepare

if [ "$CI" = true ]; then
mocha -r ts-node/register "./test/**/*.ts" --timeout 70000 $@
else
rm -rf ./node_modules/.cache/truffle
mocha -r ts-node/register "./test/**/*.ts" --invert --grep native --timeout 70000 $@
fi
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
const path = require("path");
const assert = require("assert");
const { Resolver } = require("@truffle/resolver");
const { Compile } = require("@truffle/compile-solidity");
const Config = require("@truffle/config");
import * as path from "path";
import { describe, it, beforeEach } from "mocha";
import { assert } from "chai";
import { Resolver } from "@truffle/resolver";
import { Compile } from "@truffle/compile-solidity";
import Config from "@truffle/config";
let options;

describe("JSparser", () => {
const options = {
compilers: {
solc: {
parser: "solcjs",
settings: {
optimizer: {
enabled: false,
runs: 200
}
beforeEach(function () {
options = {
compilers: {
solc: {
parser: "solcjs",
settings: {
optimizer: {
enabled: false,
runs: 200
}
},
version: undefined,
docker: undefined
}
}
},
quiet: true,
contracts_build_directory: path.join(__dirname, "./build"),
working_directory: __dirname
};
},
quiet: true,
contracts_directory: undefined,
contracts_build_directory: path.join(__dirname, "./build"),
working_directory: __dirname
};
});

it("resolves imports when using solcjs parser instead of docker [ @native ]", async () => {
it("resolves imports when using solcjs parser instead of docker [ @native ]", async function () {
this.timeout(20000);
options.compilers.solc.version = "0.4.22";
options.compilers.solc.docker = true;
options.contracts_directory = path.join(__dirname, "./sources/v0.4.x");

const paths = [];
const paths: string[] = [];
paths.push(path.join(__dirname, "./sources/v0.4.x/ComplexOrdered.sol"));
paths.push(path.join(__dirname, "./sources/v0.4.x/InheritB.sol"));

Expand All @@ -47,13 +55,14 @@ describe("JSparser", () => {

// This contract imports / inherits
assert(contractWasCompiled, "Should have compiled");
}).timeout(20000);
});

it("properly throws when passed an invalid parser value", async () => {
it("properly throws when passed an invalid parser value", async function () {
this.timeout(3000);
options.compilers.solc.parser = "badParser";
options.contracts_directory = path.join(__dirname, "./sources/v0.5.x");

const paths = [];
const paths: string[] = [];
paths.push(path.join(__dirname, "./sources/v0.5.x/ComplexOrdered.sol"));
paths.push(path.join(__dirname, "./sources/v0.5.x/InheritB.sol"));

Expand All @@ -70,5 +79,5 @@ describe("JSparser", () => {
} catch (error) {
assert(error.message.match(/(Unsupported parser)/));
}
}).timeout(3000);
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const assert = require("assert");
const Config = require("@truffle/config");
const { CompilerSupplier } = require("../dist/index");
const { Resolver } = require("@truffle/resolver");
const sinon = require("sinon");
const {
import { describe, it, before, after } from "mocha";
import { assert } from "chai";
import Config from "@truffle/config";
import {
CompilerSupplier,
compileWithPragmaAnalysis
} = require("../dist/compileWithPragmaAnalysis");
const path = require("path");
let paths = [];
} from "@truffle/compile-solidity";
import { Resolver } from "@truffle/resolver";
import * as sinon from "sinon";
import * as path from "path";
let paths: string[] = [];

const sourceDirectory = path.resolve(
__dirname,
Expand Down Expand Up @@ -69,9 +70,12 @@ config.resolver = new Resolver(config);

describe("compileWithPragmaAnalysis", function () {
before(function () {
sinon.stub(CompilerSupplier.prototype, "list").returns(releases);
sinon
.stub(CompilerSupplier.prototype, "list")
.returns(Promise.resolve(releases));
});
after(function () {
// @ts-ignore
CompilerSupplier.prototype.list.restore();
});

Expand Down Expand Up @@ -130,7 +134,7 @@ describe("compileWithPragmaAnalysis", function () {
paths: [path.join(sourceDirectory, "withImports", "C.sol")]
});
assert.equal(compilations.length, 1);
assert(compilations[0].compiler.version.startsWith("0.6.12"));
assert(compilations[0].compiler.version!.startsWith("0.6.12"));
});

it("throws an error if it cannot find one that satisfies", async function () {
Expand Down
Loading

0 comments on commit 6bc7700

Please sign in to comment.