This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4363 from trufflesuite/archaeology
Bug fix: Repair compiler output from Solidity <0.4.20
- Loading branch information
Showing
3 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/compile-solidity/test/sources/v0.4.11/FilenameWith:Colon.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//SPDX-License-Identifier: MIT | ||
//I've put a colon in the filename to be extra-sure | ||
//that this is indeed testing what it's supposed to | ||
//(that colons in file paths don't screw things up; | ||
//"project:/" should suffice to trigger the issue but | ||
//I want to be extra sure | ||
pragma solidity >=0.4.9 <0.4.20; | ||
|
||
contract SimpleContract { | ||
uint x; | ||
|
||
function SimpleContract() public { | ||
x = 7; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const debug = require("debug")("compile:test:test_oldversions"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { Compile } = require("@truffle/compile-solidity"); | ||
const CompilerSupplier = require("../compilerSupplier"); | ||
const assert = require("assert"); | ||
const { findOne } = require("./helpers"); | ||
const workingDirectory = "/home/fakename/truffleproject"; | ||
const compileOptions = { | ||
working_directory: workingDirectory, | ||
compilers: { | ||
solc: { | ||
version: "0.4.11", | ||
settings: { | ||
optimizer: { | ||
enabled: false, | ||
runs: 200 | ||
} | ||
} | ||
} | ||
}, | ||
quiet: true | ||
}; | ||
const supplierOptions = { | ||
solcConfig: compileOptions.compilers.solc, | ||
events: { | ||
emit: () => {} | ||
} | ||
}; | ||
|
||
describe("Compile - solidity <0.4.20", function () { | ||
this.timeout(5000); // solc | ||
let source = null; | ||
let solc = null; // gets loaded via supplier | ||
|
||
before("get solc", async function () { | ||
this.timeout(40000); | ||
|
||
const supplier = new CompilerSupplier(supplierOptions); | ||
({ solc } = await supplier.load()); | ||
}); | ||
|
||
describe("Output repair", function () { | ||
before("get code", function () { | ||
source = fs.readFileSync( | ||
path.join(__dirname, "./sources/v0.4.11/FilenameWith:Colon.sol"), | ||
"utf-8" | ||
); | ||
}); | ||
|
||
it("produces contract output correctly", async function () { | ||
const sourcePath = `${workingDirectory}/contracts/FilenameWith:Colon.sol`; | ||
const sources = { [sourcePath]: source }; | ||
|
||
const { compilations } = await Compile.sources({ | ||
sources, | ||
options: compileOptions | ||
}); | ||
//there should be one compilation | ||
assert.equal(compilations.length, 1); | ||
const compilation = compilations[0]; | ||
//it should have contracts | ||
assert.ok(compilation.contracts); | ||
//there should be one | ||
assert.equal(compilation.contracts.length, 1); | ||
const contract = compilation.contracts[0]; | ||
//it should have contract name & source set correctly; | ||
//it should have various other properties set at all | ||
assert.equal(contract.contractName, "SimpleContract"); | ||
assert.equal(contract.sourcePath, sourcePath); | ||
assert.equal(contract.source, source); | ||
assert.ok(contract.bytecode); | ||
assert.ok(contract.abi); | ||
assert.ok(contract.legacyAST); | ||
}); | ||
}); | ||
}); |