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

Commit 6bc7700

Browse files
authored
Merge pull request #5445 from trufflesuite/and-tests
Internal improvement: Move compile-solidity tests to a new separate package
2 parents 89667fe + 57d00cf commit 6bc7700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+595
-440
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependency-graph": "lerna-dependency-graph -f pdf -o dependency-graph.pdf",
1313
"solc-bump": "node ./scripts/solc-bump.js",
1414
"update": "lernaupdate",
15-
"depcheck": "lerna exec --stream --no-bail dependency-check --ignore @truffle/contract-tests --ignore @truffle/dashboard-message-bus-e2e-test -- --missing .",
15+
"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 .",
1616
"check-truffle-namespace-dependency-versions": "node ./scripts/check-truffle-namespace-dependency-versions.js"
1717
},
1818
"devDependencies": {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `@truffle/compile-solidity-tests`
2+
3+
:information_source: This package houses the tests for
4+
[@truffle/compile-solidity](https://www.npmjs.com/package/@truffle/compile-solidity-tests). This
5+
package is not published and lives only in this monorepo.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@truffle/compile-solidity-tests",
3+
"description": "Compiler helper and artifact manager for Solidity files",
4+
"license": "MIT",
5+
"author": "Tyler Feickert <[email protected]>",
6+
"homepage": "https://github.com/trufflesuite/truffle/tree/master/packages/compile-solidity-tests#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/trufflesuite/truffle.git",
10+
"directory": "packages/compile-solidity-tests"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/trufflesuite/truffle/issues"
14+
},
15+
"private": true,
16+
"version": "0.1.0",
17+
"main": "dist/index.js",
18+
"scripts": {
19+
"build": "ttsc",
20+
"prepare": "yarn build",
21+
"test": "./scripts/test.sh"
22+
},
23+
"devDependencies": {
24+
"@truffle/artifactor": "^4.0.168",
25+
"@truffle/compile-solidity": "^6.0.42",
26+
"@truffle/config": "^1.3.37",
27+
"@truffle/resolver": "^9.0.15",
28+
"@types/node": "12.12.21",
29+
"@types/sinon": "^9.0.10",
30+
"babel-core": "^6.26.0",
31+
"babel-polyfill": "^6.26.0",
32+
"babel-preset-env": "^1.6.1",
33+
"chai": "^4.2.0",
34+
"debug": "^4.3.1",
35+
"fs-extra": "^9.1.0",
36+
"mocha": "9.2.2",
37+
"sinon": "^9.0.2",
38+
"tmp": "^0.2.1",
39+
"ts-node": "10.7.0",
40+
"typescript": "^4.7.4"
41+
},
42+
"keywords": [
43+
"compile",
44+
"ethereum",
45+
"solidity",
46+
"truffle"
47+
],
48+
"babel": {
49+
"presets": [
50+
"env"
51+
]
52+
}
53+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
yarn prepare
6+
7+
if [ "$CI" = true ]; then
8+
mocha -r ts-node/register "./test/**/*.ts" --timeout 70000 $@
9+
else
10+
rm -rf ./node_modules/.cache/truffle
11+
mocha -r ts-node/register "./test/**/*.ts" --invert --grep native --timeout 70000 $@
12+
fi
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
const path = require("path");
2-
const assert = require("assert");
3-
const { Resolver } = require("@truffle/resolver");
4-
const { Compile } = require("@truffle/compile-solidity");
5-
const Config = require("@truffle/config");
1+
import * as path from "path";
2+
import { describe, it, beforeEach } from "mocha";
3+
import { assert } from "chai";
4+
import { Resolver } from "@truffle/resolver";
5+
import { Compile } from "@truffle/compile-solidity";
6+
import Config from "@truffle/config";
7+
let options;
68

79
describe("JSparser", () => {
8-
const options = {
9-
compilers: {
10-
solc: {
11-
parser: "solcjs",
12-
settings: {
13-
optimizer: {
14-
enabled: false,
15-
runs: 200
16-
}
10+
beforeEach(function () {
11+
options = {
12+
compilers: {
13+
solc: {
14+
parser: "solcjs",
15+
settings: {
16+
optimizer: {
17+
enabled: false,
18+
runs: 200
19+
}
20+
},
21+
version: undefined,
22+
docker: undefined
1723
}
18-
}
19-
},
20-
quiet: true,
21-
contracts_build_directory: path.join(__dirname, "./build"),
22-
working_directory: __dirname
23-
};
24+
},
25+
quiet: true,
26+
contracts_directory: undefined,
27+
contracts_build_directory: path.join(__dirname, "./build"),
28+
working_directory: __dirname
29+
};
30+
});
2431

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

30-
const paths = [];
38+
const paths: string[] = [];
3139
paths.push(path.join(__dirname, "./sources/v0.4.x/ComplexOrdered.sol"));
3240
paths.push(path.join(__dirname, "./sources/v0.4.x/InheritB.sol"));
3341

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

4856
// This contract imports / inherits
4957
assert(contractWasCompiled, "Should have compiled");
50-
}).timeout(20000);
58+
});
5159

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

56-
const paths = [];
65+
const paths: string[] = [];
5766
paths.push(path.join(__dirname, "./sources/v0.5.x/ComplexOrdered.sol"));
5867
paths.push(path.join(__dirname, "./sources/v0.5.x/InheritB.sol"));
5968

@@ -70,5 +79,5 @@ describe("JSparser", () => {
7079
} catch (error) {
7180
assert(error.message.match(/(Unsupported parser)/));
7281
}
73-
}).timeout(3000);
82+
});
7483
});

packages/compile-solidity/test/compileWithPragmaAnalysis.js renamed to packages/compile-solidity-tests/test/compileWithPragmaAnalysis.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
const assert = require("assert");
2-
const Config = require("@truffle/config");
3-
const { CompilerSupplier } = require("../dist/index");
4-
const { Resolver } = require("@truffle/resolver");
5-
const sinon = require("sinon");
6-
const {
1+
import { describe, it, before, after } from "mocha";
2+
import { assert } from "chai";
3+
import Config from "@truffle/config";
4+
import {
5+
CompilerSupplier,
76
compileWithPragmaAnalysis
8-
} = require("../dist/compileWithPragmaAnalysis");
9-
const path = require("path");
10-
let paths = [];
7+
} from "@truffle/compile-solidity";
8+
import { Resolver } from "@truffle/resolver";
9+
import * as sinon from "sinon";
10+
import * as path from "path";
11+
let paths: string[] = [];
1112

1213
const sourceDirectory = path.resolve(
1314
__dirname,
@@ -69,9 +70,12 @@ config.resolver = new Resolver(config);
6970

7071
describe("compileWithPragmaAnalysis", function () {
7172
before(function () {
72-
sinon.stub(CompilerSupplier.prototype, "list").returns(releases);
73+
sinon
74+
.stub(CompilerSupplier.prototype, "list")
75+
.returns(Promise.resolve(releases));
7376
});
7477
after(function () {
78+
// @ts-ignore
7579
CompilerSupplier.prototype.list.restore();
7680
});
7781

@@ -130,7 +134,7 @@ describe("compileWithPragmaAnalysis", function () {
130134
paths: [path.join(sourceDirectory, "withImports", "C.sol")]
131135
});
132136
assert.equal(compilations.length, 1);
133-
assert(compilations[0].compiler.version.startsWith("0.6.12"));
137+
assert(compilations[0].compiler.version!.startsWith("0.6.12"));
134138
});
135139

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

0 commit comments

Comments
 (0)