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

Fix: official repo to list Solidity's releases #5008

Merged
merged 7 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export class VersionRange {
constructor(options: StrategyOptions) {
const defaultConfig = {
compilerRoots: [
// NOTE this relay address exists so that we have a backup option in
// case more official distribution mechanisms fail.
//
// currently this URL just redirects (302 Found); we may alter this to
// host for real in the future.
"https://relay.trufflesuite.com/solc/bin/",
// this order of url root preference was recommended by Cameel from the
// Solidity team here -- https://github.com/trufflesuite/truffle/pull/5008
"https://relay.trufflesuite.com/solc/emscripten-wasm32/",
"https://binaries.soliditylang.org/emscripten-wasm32/",
"https://relay.trufflesuite.com/solc/emscripten-asmjs/",
"https://binaries.soliditylang.org/emscripten-asmjs/",
"https://solc-bin.ethereum.org/bin/",
"https://ethereum.github.io/solc-bin/bin/"
]
Expand Down
29 changes: 20 additions & 9 deletions packages/compile-solidity/test/test_supplier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debug = require("debug")("compile:test:test_supplier");
const fse = require("fs-extra");
const path = require("path");
const assert = require("assert");
const { assert } = require("chai");
const { Resolver } = require("@truffle/resolver");
const { Compile } = require("@truffle/compile-solidity");
const Config = require("@truffle/config");
Expand Down Expand Up @@ -150,13 +150,11 @@ describe("CompilerSupplier", function () {
Config.getTruffleDataDirectory(),
"compilers/node_modules"
);
const expectedCache = path.resolve(
compilerCacheDirectory,
"soljson-v0.4.21+commit.dfe3193c.js"
);

// Delete if it's already there.
if (await fse.exists(expectedCache)) await fse.unlink(expectedCache);
if (fse.existsSync(compilerCacheDirectory)) {
fse.removeSync(compilerCacheDirectory);
}

options.compilers = {
solc: { version: "0.4.21" }
Expand All @@ -170,10 +168,23 @@ describe("CompilerSupplier", function () {
options: cachedOptions
});

assert(await fse.exists(expectedCache), "Should have cached compiler");
const cachedCompilerFilenames = fse.readdirSync(compilerCacheDirectory);
const compilerFilename = cachedCompilerFilenames.find(filename => {
return filename.includes("v0.4.21+commit.dfe3193c");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is truly nitpicking and you don't need to change this, but filename => { return foo; } could instead just be filename => foo.

});

assert.isDefined(
compilerFilename,
"The compiler should have been cached but wasn't"
);

const cachedCompilerPath = path.join(
compilerCacheDirectory,
compilerFilename
);

// Get cached solc access time
initialAccessTime = (await fse.stat(expectedCache)).atime.getTime();
initialAccessTime = (await fse.stat(cachedCompilerPath)).atime.getTime();

// Wait a second and recompile, verifying that the cached solc
// got accessed / ran ok.
Expand All @@ -184,7 +195,7 @@ describe("CompilerSupplier", function () {
options: cachedOptions
});

finalAccessTime = (await fse.stat(expectedCache)).atime.getTime();
finalAccessTime = (await fse.stat(cachedCompilerPath)).atime.getTime();
const NewPragma = findOne("NewPragma", compilations[0].contracts);

assert(NewPragma.contractName === "NewPragma", "Should have compiled");
Expand Down
48 changes: 22 additions & 26 deletions packages/truffle/test/scenarios/commands/obtain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,52 @@ const path = require("path");
const assert = require("assert");
const sandbox = require("../sandbox");

let logger, config, project, expectedPath;
let logger, config, project, compilersCacheDirectory;

describe("truffle obtain", function () {
project = path.join(__dirname, "../../sources/obtain");

beforeEach(async function () {
expectedPath = path.join(
compilersCacheDirectory = path.join(
Config.getTruffleDataDirectory(),
"compilers",
"node_modules",
"soljson-v0.7.2+commit.51b20bc0.js"
"node_modules"
);
this.timeout(10000);
config = await sandbox.create(project);
logger = new MemoryLogger();
config.logger = logger;

// ensure the compiler is not cached beforehand
if (fse.existsSync(compilersCacheDirectory)) {
fse.removeSync(compilersCacheDirectory);
}
});

afterEach(() => {
if (fse.existsSync(compilersCacheDirectory)) {
fse.removeSync(compilersCacheDirectory);
}
});

it("fetches the solc version specified", async function () {
this.timeout(70000);
// ensure the compiler does not yet exist
try {
fse.unlinkSync(expectedPath);
} catch (error) {
// unlink throws when file doesn't exist
if (error.code !== "ENOENT") {
throw error;
}
}
await CommandRunner.run("obtain --solc=0.7.2", config);
assert(fse.statSync(expectedPath), "The compiler was not obtained!");
fse.unlinkSync(expectedPath);
const cachedCompilersFilenames = fse.readdirSync(compilersCacheDirectory);

assert(
cachedCompilersFilenames.some(filename => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note here as earlier about filename => { return foo; }.

return filename.includes("v0.7.2+commit.51b20bc0");
}),
"The compiler was not obtained!"
);
});

it("respects the `quiet` option", async function () {
this.timeout(80000);
// ensure the compiler does not yet exist
try {
fse.unlinkSync(expectedPath);
} catch (error) {
// unlink throws when file doesn't exist
if (error.code !== "ENOENT") {
throw error;
}
}
await CommandRunner.run("obtain --solc=0.7.2 --quiet", config);
// logger.contents() returns false as long as nothing is written to the
// stream that is used for logging in MemoryLogger

// in Node12, Ganache prints a warning and it cannot be suppressed
// I guess we have to allow it until we stop supporting Node12
const ganacheNode12WarningRegex =
Expand All @@ -68,6 +65,5 @@ describe("truffle obtain", function () {
!loggedStuff,
"The command logged to the console when it shouldn't have."
);
fse.unlinkSync(expectedPath);
});
});