|
| 1 | +const debug = require("debug")("compile:test:test_oldversions"); |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
| 4 | +const { Compile } = require("@truffle/compile-solidity"); |
| 5 | +const CompilerSupplier = require("../compilerSupplier"); |
| 6 | +const assert = require("assert"); |
| 7 | +const { findOne } = require("./helpers"); |
| 8 | +const workingDirectory = "/home/fakename/truffleproject"; |
| 9 | +const compileOptions = { |
| 10 | + working_directory: workingDirectory, |
| 11 | + compilers: { |
| 12 | + solc: { |
| 13 | + version: "0.4.11", |
| 14 | + settings: { |
| 15 | + optimizer: { |
| 16 | + enabled: false, |
| 17 | + runs: 200 |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + }, |
| 22 | + quiet: true |
| 23 | +}; |
| 24 | +const supplierOptions = { |
| 25 | + solcConfig: compileOptions.compilers.solc, |
| 26 | + events: { |
| 27 | + emit: () => {} |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +describe("Compile - solidity <0.4.20", function () { |
| 32 | + this.timeout(5000); // solc |
| 33 | + let source = null; |
| 34 | + let solc = null; // gets loaded via supplier |
| 35 | + |
| 36 | + before("get solc", async function () { |
| 37 | + this.timeout(40000); |
| 38 | + |
| 39 | + const supplier = new CompilerSupplier(supplierOptions); |
| 40 | + ({ solc } = await supplier.load()); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("Output repair", function () { |
| 44 | + before("get code", function () { |
| 45 | + source = fs.readFileSync( |
| 46 | + path.join(__dirname, "./sources/v0.4.11/FilenameWith:Colon.sol"), |
| 47 | + "utf-8" |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("produces contract output correctly", async function () { |
| 52 | + const sourcePath = `${workingDirectory}/contracts/FilenameWith:Colon.sol`; |
| 53 | + const sources = { [sourcePath]: source }; |
| 54 | + |
| 55 | + const { compilations } = await Compile.sources({ |
| 56 | + sources, |
| 57 | + options: compileOptions |
| 58 | + }); |
| 59 | + //there should be one compilation |
| 60 | + assert.equal(compilations.length, 1); |
| 61 | + const compilation = compilations[0]; |
| 62 | + //it should have contracts |
| 63 | + assert.ok(compilation.contracts); |
| 64 | + //there should be one |
| 65 | + assert.equal(compilation.contracts.length, 1); |
| 66 | + const contract = compilation.contracts[0]; |
| 67 | + //it should have contract name & source set correctly; |
| 68 | + //it should have various other properties set at all |
| 69 | + assert.equal(contract.contractName, "SimpleContract"); |
| 70 | + assert.equal(contract.sourcePath, sourcePath); |
| 71 | + assert.equal(contract.source, source); |
| 72 | + assert.ok(contract.bytecode); |
| 73 | + assert.ok(contract.abi); |
| 74 | + assert.ok(contract.legacyAST); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments