mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 00:11:02 +00:00
lint
This commit is contained in:
@@ -23,4 +23,4 @@
|
||||
"ts-jest": "^29.2.5",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,19 +1,33 @@
|
||||
import * as path from 'path';
|
||||
import * as path from "path";
|
||||
|
||||
const outputDir = 'artifacts';
|
||||
const binExtension = ':C.pvm';
|
||||
const asmExtension = ':C.pvmasm';
|
||||
const llvmExtension = '.ll';
|
||||
const contractSolFilename = 'contract.sol';
|
||||
const contractYulFilename = 'contract.yul';
|
||||
const contractOptimizedLLVMFilename = contractSolFilename + '.C.optimized';
|
||||
const contractUnoptimizedLLVMFilename = contractSolFilename + '.C.unoptimized';
|
||||
const pathToOutputDir = path.join(__dirname, '..', outputDir);
|
||||
const pathToContracts = path.join(__dirname, '..', 'src', 'contracts');
|
||||
const pathToBasicYulContract = path.join(pathToContracts, 'yul', contractYulFilename);
|
||||
const pathToBasicSolContract = path.join(pathToContracts, 'solidity', contractSolFilename);
|
||||
const pathToSolBinOutputFile = path.join(pathToOutputDir, contractSolFilename + binExtension);
|
||||
const pathToSolAsmOutputFile = path.join(pathToOutputDir, contractSolFilename + asmExtension);
|
||||
const outputDir = "artifacts";
|
||||
const binExtension = ":C.pvm";
|
||||
const asmExtension = ":C.pvmasm";
|
||||
const llvmExtension = ".ll";
|
||||
const contractSolFilename = "contract.sol";
|
||||
const contractYulFilename = "contract.yul";
|
||||
const contractOptimizedLLVMFilename = contractSolFilename + ".C.optimized";
|
||||
const contractUnoptimizedLLVMFilename = contractSolFilename + ".C.unoptimized";
|
||||
const pathToOutputDir = path.join(__dirname, "..", outputDir);
|
||||
const pathToContracts = path.join(__dirname, "..", "src", "contracts");
|
||||
const pathToBasicYulContract = path.join(
|
||||
pathToContracts,
|
||||
"yul",
|
||||
contractYulFilename,
|
||||
);
|
||||
const pathToBasicSolContract = path.join(
|
||||
pathToContracts,
|
||||
"solidity",
|
||||
contractSolFilename,
|
||||
);
|
||||
const pathToSolBinOutputFile = path.join(
|
||||
pathToOutputDir,
|
||||
contractSolFilename + binExtension,
|
||||
);
|
||||
const pathToSolAsmOutputFile = path.join(
|
||||
pathToOutputDir,
|
||||
contractSolFilename + asmExtension,
|
||||
);
|
||||
|
||||
export const paths = {
|
||||
outputDir: outputDir,
|
||||
|
||||
@@ -1,44 +1,51 @@
|
||||
import * as shell from 'shelljs';
|
||||
import * as fs from 'fs';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as shell from "shelljs";
|
||||
import * as fs from "fs";
|
||||
import { spawnSync } from "child_process";
|
||||
|
||||
interface CommandResult {
|
||||
output: string;
|
||||
exitCode: number;
|
||||
output: string;
|
||||
exitCode: number;
|
||||
}
|
||||
|
||||
export const executeCommand = (command: string, stdin?: string): CommandResult => {
|
||||
if (stdin) {
|
||||
const process = spawnSync(command, [], {
|
||||
input: stdin,
|
||||
shell: true,
|
||||
encoding: 'utf8',
|
||||
maxBuffer: 30 * 1024 * 1024
|
||||
});
|
||||
export const executeCommand = (
|
||||
command: string,
|
||||
stdin?: string,
|
||||
): CommandResult => {
|
||||
if (stdin) {
|
||||
const process = spawnSync(command, [], {
|
||||
input: stdin,
|
||||
shell: true,
|
||||
encoding: "utf8",
|
||||
maxBuffer: 30 * 1024 * 1024,
|
||||
});
|
||||
|
||||
return {
|
||||
exitCode: process.status || 0,
|
||||
output: (process.stdout || process.stderr || '').toString()
|
||||
};
|
||||
}
|
||||
|
||||
const result = shell.exec(command, { silent: true, async: false });
|
||||
return {
|
||||
exitCode: result.code,
|
||||
output: result.stdout || result.stderr || ''
|
||||
exitCode: process.status || 0,
|
||||
output: (process.stdout || process.stderr || "").toString(),
|
||||
};
|
||||
}
|
||||
|
||||
const result = shell.exec(command, { silent: true, async: false });
|
||||
return {
|
||||
exitCode: result.code,
|
||||
output: result.stdout || result.stderr || "",
|
||||
};
|
||||
};
|
||||
|
||||
export const isFolderExist = (folder: string): boolean => {
|
||||
return shell.test('-d', folder);
|
||||
return shell.test("-d", folder);
|
||||
};
|
||||
|
||||
export const isFileExist = (pathToFileDir: string, fileName: string, fileExtension: string): boolean => {
|
||||
return shell.ls(pathToFileDir).stdout.includes(fileName + fileExtension);
|
||||
export const isFileExist = (
|
||||
pathToFileDir: string,
|
||||
fileName: string,
|
||||
fileExtension: string,
|
||||
): boolean => {
|
||||
return shell.ls(pathToFileDir).stdout.includes(fileName + fileExtension);
|
||||
};
|
||||
|
||||
export const isFileEmpty = (file: string): boolean => {
|
||||
if (fs.existsSync(file)) {
|
||||
return (fs.readFileSync(file).length === 0);
|
||||
}
|
||||
if (fs.existsSync(file)) {
|
||||
return fs.readFileSync(file).length === 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import {executeCommand} from "../src/helper";
|
||||
import { paths } from '../src/entities';
|
||||
|
||||
import { executeCommand } from "../src/helper";
|
||||
import { paths } from "../src/entities";
|
||||
|
||||
//id1746
|
||||
describe("Run with --asm by default", () => {
|
||||
const command = `resolc ${paths.pathToBasicSolContract} --asm`;
|
||||
const result = executeCommand(command);
|
||||
const commandInvalid = 'resolc --asm';
|
||||
const commandInvalid = "resolc --asm";
|
||||
const resultInvalid = executeCommand(commandInvalid);
|
||||
|
||||
it("Valid command exit code = 0", () => {
|
||||
@@ -28,16 +27,18 @@ describe("Run with --asm by default", () => {
|
||||
});
|
||||
|
||||
it("run invalid: resolc --asm", () => {
|
||||
expect(resultInvalid.output).toMatch(/(No input sources specified|Compilation aborted)/i);
|
||||
expect(resultInvalid.output).toMatch(
|
||||
/(No input sources specified|Compilation aborted)/i,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
it("Invalid command exit code = 1", () => {
|
||||
expect(resultInvalid.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("Invalid solc exit code == Invalid resolc exit code", () => {
|
||||
const command = 'solc --asm';
|
||||
const command = "solc --asm";
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(resultInvalid.exitCode);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,191 +1,241 @@
|
||||
import { executeCommand, isFolderExist, isFileExist, isFileEmpty } from "../src/helper";
|
||||
import { paths } from '../src/entities';
|
||||
import * as shell from 'shelljs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {
|
||||
executeCommand,
|
||||
isFolderExist,
|
||||
isFileExist,
|
||||
isFileEmpty,
|
||||
} from "../src/helper";
|
||||
import { paths } from "../src/entities";
|
||||
import * as shell from "shelljs";
|
||||
import * as path from "path";
|
||||
|
||||
//id1762
|
||||
describe("Run resolc without any options", () => {
|
||||
const command = 'resolc';
|
||||
const result = executeCommand(command);
|
||||
const command = "resolc";
|
||||
const result = executeCommand(command);
|
||||
|
||||
it("Info with help is presented", () => {
|
||||
expect(result.output).toMatch(/(Usage: resolc)/i);
|
||||
});
|
||||
it("Info with help is presented", () => {
|
||||
expect(result.output).toMatch(/(Usage: resolc)/i);
|
||||
});
|
||||
|
||||
it("Exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
it("Exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("solc exit code == resolc exit code", () => {
|
||||
const command = 'solc';
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
it("solc exit code == resolc exit code", () => {
|
||||
const command = "solc";
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//#1713
|
||||
describe("Default run a command from the help", () => {
|
||||
const command = `resolc ${paths.pathToBasicSolContract} --overwrite -O3 --bin --output-dir "${paths.pathToOutputDir}"`; // potential issue on resolc with full path on Windows cmd
|
||||
const result = executeCommand(command);
|
||||
|
||||
const command = `resolc ${paths.pathToBasicSolContract} --overwrite -O3 --bin --output-dir "${paths.pathToOutputDir}"`; // potential issue on resolc with full path on Windows cmd
|
||||
const result = executeCommand(command);
|
||||
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
xit("Output file is created", () => { // a bug on windows
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.binExtension)).toBe(true);
|
||||
});
|
||||
it("the output file is not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Warning'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
||||
});
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
xit("Output file is created", () => {
|
||||
// a bug on windows
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractSolFilename,
|
||||
paths.binExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it("the output file is not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Warning'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
||||
});
|
||||
});
|
||||
|
||||
//#1818
|
||||
describe("Default run a command from the help", () => {
|
||||
const command = `resolc ${paths.pathToBasicSolContract} --overwrite -O3 --bin --asm --output-dir "${paths.pathToOutputDir}"`; // potential issue on resolc with full path on Windows cmd
|
||||
const result = executeCommand(command);
|
||||
|
||||
const command = `resolc ${paths.pathToBasicSolContract} --overwrite -O3 --bin --asm --output-dir "${paths.pathToOutputDir}"`; // potential issue on resolc with full path on Windows cmd
|
||||
const result = executeCommand(command);
|
||||
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
xit("Output files are created", () => { // a bug on windows
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.binExtension)).toBe(true);
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.asmExtension)).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Warning'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
||||
});
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
xit("Output files are created", () => {
|
||||
// a bug on windows
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractSolFilename,
|
||||
paths.binExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractSolFilename,
|
||||
paths.asmExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Warning'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Run resolc with source debug information", () => {
|
||||
const commands = [
|
||||
`resolc -g ${paths.pathToBasicSolContract} --overwrite --bin --asm --output-dir "${paths.pathToOutputDir}"`,
|
||||
`resolc --disable-solc-optimizer -g ${paths.pathToBasicSolContract} --overwrite --bin --asm --output-dir "${paths.pathToOutputDir}"`
|
||||
]; // potential issue on resolc with full path on Windows cmd`;
|
||||
const commands = [
|
||||
`resolc -g ${paths.pathToBasicSolContract} --overwrite --bin --asm --output-dir "${paths.pathToOutputDir}"`,
|
||||
`resolc --disable-solc-optimizer -g ${paths.pathToBasicSolContract} --overwrite --bin --asm --output-dir "${paths.pathToOutputDir}"`,
|
||||
]; // potential issue on resolc with full path on Windows cmd`;
|
||||
|
||||
for (var idx in commands) {
|
||||
const command = commands[idx];
|
||||
const result = executeCommand(command);
|
||||
for (var idx in commands) {
|
||||
const command = commands[idx];
|
||||
const result = executeCommand(command);
|
||||
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
it("Output files are created", () => { // a bug on windows
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.binExtension)).toBe(true);
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.asmExtension)).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
||||
});
|
||||
}
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
it("Output files are created", () => {
|
||||
// a bug on windows
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractSolFilename,
|
||||
paths.binExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractSolFilename,
|
||||
paths.asmExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Run resolc with source debug information, check LLVM debug-info", () => {
|
||||
const commands = [
|
||||
`resolc -g ${paths.pathToBasicSolContract} --overwrite --debug-output-dir="${paths.pathToOutputDir}"`,
|
||||
`resolc -g --disable-solc-optimizer ${paths.pathToBasicSolContract} --overwrite --debug-output-dir="${paths.pathToOutputDir}"`
|
||||
]; // potential issue on resolc with full path on Windows cmd`;
|
||||
const commands = [
|
||||
`resolc -g ${paths.pathToBasicSolContract} --overwrite --debug-output-dir="${paths.pathToOutputDir}"`,
|
||||
`resolc -g --disable-solc-optimizer ${paths.pathToBasicSolContract} --overwrite --debug-output-dir="${paths.pathToOutputDir}"`,
|
||||
]; // potential issue on resolc with full path on Windows cmd`;
|
||||
|
||||
for (var idx in commands) {
|
||||
const command = commands[idx];
|
||||
const result = executeCommand(command);
|
||||
for (var idx in commands) {
|
||||
const command = commands[idx];
|
||||
const result = executeCommand(command);
|
||||
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
it("Output files are created", () => { // a bug on windows
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractOptimizedLLVMFilename, paths.llvmExtension)).toBe(true);
|
||||
expect(isFileExist(paths.pathToOutputDir, paths.contractUnoptimizedLLVMFilename, paths.llvmExtension)).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
||||
});
|
||||
}
|
||||
it("Compiler run successful", () => {
|
||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
||||
});
|
||||
it("Exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
it("Output dir is created", () => {
|
||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
||||
});
|
||||
it("Output files are created", () => {
|
||||
// a bug on windows
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractOptimizedLLVMFilename,
|
||||
paths.llvmExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isFileExist(
|
||||
paths.pathToOutputDir,
|
||||
paths.contractUnoptimizedLLVMFilename,
|
||||
paths.llvmExtension,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it("the output files are not empty", () => {
|
||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
||||
});
|
||||
it("No 'Error'/'Fail' in the output", () => {
|
||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe("Standard JSON compilation with path options", () => {
|
||||
const contractsDir = path.join(shell.tempdir(), 'contracts-test');
|
||||
const inputFile = path.join(__dirname, '..', 'src/contracts/compiled/1.json');
|
||||
const contractsDir = path.join(shell.tempdir(), "contracts-test");
|
||||
const inputFile = path.join(__dirname, "..", "src/contracts/compiled/1.json");
|
||||
|
||||
beforeAll(() => {
|
||||
shell.mkdir("-p", contractsDir);
|
||||
|
||||
const input = JSON.parse(shell.cat(inputFile).toString());
|
||||
|
||||
Object.entries(input.sources).forEach(
|
||||
([sourcePath, source]: [string, any]) => {
|
||||
const filePath = path.join(contractsDir, sourcePath);
|
||||
shell.mkdir("-p", path.dirname(filePath));
|
||||
shell.ShellString(source.content).to(filePath);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
shell.rm("-rf", contractsDir);
|
||||
});
|
||||
|
||||
describe("Output with all path options", () => {
|
||||
let result: { exitCode: number; output: string };
|
||||
|
||||
beforeAll(() => {
|
||||
shell.mkdir('-p', contractsDir);
|
||||
const tempInputFile = path.join(contractsDir, "temp-input.json");
|
||||
shell.cp(inputFile, tempInputFile);
|
||||
const inputContent = shell.cat(inputFile).toString();
|
||||
|
||||
const input = JSON.parse(shell.cat(inputFile).toString());
|
||||
const command = `resolc --standard-json --base-path "${contractsDir}" --include-path "${contractsDir}" --allow-paths "${contractsDir}"`;
|
||||
|
||||
Object.entries(input.sources).forEach(([sourcePath, source]: [string, any]) => {
|
||||
const filePath = path.join(contractsDir, sourcePath);
|
||||
shell.mkdir('-p', path.dirname(filePath));
|
||||
shell.ShellString(source.content).to(filePath);
|
||||
});
|
||||
result = executeCommand(command, inputContent);
|
||||
|
||||
shell.rm(tempInputFile);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
shell.rm('-rf', contractsDir);
|
||||
it("Compiler run successful without emiting warnings", () => {
|
||||
const parsedResults = JSON.parse(result.output);
|
||||
expect(
|
||||
parsedResults.errors.filter(
|
||||
(error: { type: string }) => error.type != "Warning",
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
describe("Output with all path options", () => {
|
||||
let result: { exitCode: number; output: string };
|
||||
|
||||
beforeAll(() => {
|
||||
const tempInputFile = path.join(contractsDir, 'temp-input.json');
|
||||
shell.cp(inputFile, tempInputFile);
|
||||
const inputContent = shell.cat(inputFile).toString();
|
||||
|
||||
const command = `resolc --standard-json --base-path "${contractsDir}" --include-path "${contractsDir}" --allow-paths "${contractsDir}"`;
|
||||
|
||||
result = executeCommand(command, inputContent);
|
||||
|
||||
shell.rm(tempInputFile);
|
||||
|
||||
});
|
||||
|
||||
it("Compiler run successful without emiting warnings", () => {
|
||||
const parsedResults = JSON.parse(result.output)
|
||||
expect(parsedResults.errors.filter((error: { type: string; }) => error.type != 'Warning')).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import {executeCommand} from "../src/helper";
|
||||
import { paths } from '../src/entities';
|
||||
|
||||
import { executeCommand } from "../src/helper";
|
||||
import { paths } from "../src/entities";
|
||||
|
||||
//id1743
|
||||
describe("Run with --yul by default", () => {
|
||||
const command = `resolc ${paths.pathToBasicYulContract} --yul`;
|
||||
const result = executeCommand(command);
|
||||
const commandInvalid = 'resolc --yul';
|
||||
const commandInvalid = "resolc --yul";
|
||||
const resultInvalid = executeCommand(commandInvalid);
|
||||
|
||||
it("Valid command exit code = 0", () => {
|
||||
@@ -18,11 +17,11 @@ describe("Run with --yul by default", () => {
|
||||
expect(result.output).toMatch(/(No output requested)/i);
|
||||
});
|
||||
|
||||
|
||||
xit("solc exit code == resolc exit code", () => { // unknown solc issue for datatype of the contract
|
||||
const command = `solc ${paths.pathToBasicSolContract} --yul`;
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
xit("solc exit code == resolc exit code", () => {
|
||||
// unknown solc issue for datatype of the contract
|
||||
const command = `solc ${paths.pathToBasicSolContract} --yul`;
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
|
||||
it("run invalid: resolc --yul", () => {
|
||||
@@ -33,7 +32,7 @@ describe("Run with --yul by default", () => {
|
||||
});
|
||||
|
||||
it("Invalid solc exit code == Invalid resolc exit code", () => {
|
||||
const command = 'solc --yul';
|
||||
const command = "solc --yul";
|
||||
const solcResult = executeCommand(command);
|
||||
expect(solcResult.exitCode).toBe(resultInvalid.exitCode);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "CommonJS",
|
||||
"outDir": "./dist",
|
||||
"outDir": "./dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,153 +1,192 @@
|
||||
import { executeCommand } from "../src/helper";
|
||||
import { paths } from '../src/entities';
|
||||
|
||||
import { paths } from "../src/entities";
|
||||
|
||||
describe("Set of --combined-json tests", () => {
|
||||
const zksolcCommand = 'zksolc';
|
||||
const solcCommand = 'solc';
|
||||
const json_args: string[] = [`abi`, `hashes`, `metadata`, `devdoc`, `userdoc`, `storage-layout`, `ast`, `asm`, `bin`, `bin-runtime`];
|
||||
const zksolcCommand = "zksolc";
|
||||
const solcCommand = "solc";
|
||||
const json_args: string[] = [
|
||||
`abi`,
|
||||
`hashes`,
|
||||
`metadata`,
|
||||
`devdoc`,
|
||||
`userdoc`,
|
||||
`storage-layout`,
|
||||
`ast`,
|
||||
`asm`,
|
||||
`bin`,
|
||||
`bin-runtime`,
|
||||
];
|
||||
|
||||
//id1742:I
|
||||
describe(`Run ${zksolcCommand} with just --combined-json`, () => {
|
||||
const args = [`--combined-json`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
//id1742:I
|
||||
describe(`Run ${zksolcCommand} with just --combined-json`, () => {
|
||||
const args = [`--combined-json`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(requires a value but none was supplied)/i);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
//id1742:II
|
||||
describe(`Run ${zksolcCommand} with Sol contract and --combined-json`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(requires a value but none was supplied)/i);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(
|
||||
/(requires a value but none was supplied)/i,
|
||||
);
|
||||
});
|
||||
|
||||
//id1742:III
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and ARG: ${json_args[i]}`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`, `${json_args[i]}`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
|
||||
it("Valid command exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
//id1742:II
|
||||
describe(`Run ${zksolcCommand} with Sol contract and --combined-json`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(contracts)/i);
|
||||
});
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(
|
||||
/(requires a value but none was supplied)/i,
|
||||
);
|
||||
});
|
||||
|
||||
//id1829:I
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and wrong ARG: --${json_args[i]}`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`, `--${json_args[i]}`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
//id1742:III
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and ARG: ${json_args[i]}`, () => {
|
||||
const args = [
|
||||
`${paths.pathToBasicSolContract}`,
|
||||
`--combined-json`,
|
||||
`${json_args[i]}`,
|
||||
];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(Invalid option|error)/i);
|
||||
});
|
||||
it("Valid command exit code = 0", () => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(contracts)/i);
|
||||
});
|
||||
|
||||
//id1829:II
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and multiple ARG: ${json_args[i]} ${json_args[i]}`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`, `${json_args[i]}`, `${json_args[i]}`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
xit("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
//id1829:I
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and wrong ARG: --${json_args[i]}`, () => {
|
||||
const args = [
|
||||
`${paths.pathToBasicSolContract}`,
|
||||
`--combined-json`,
|
||||
`--${json_args[i]}`,
|
||||
];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(No such file or directory|cannot find the file specified)/i); // Hopefully we should have more precise message here!
|
||||
});
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
xit("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(Invalid option|error)/i);
|
||||
});
|
||||
|
||||
//id1829:III
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, and multiple (--combined-json ${json_args[i]})`, () => {
|
||||
const args = [`${paths.pathToBasicSolContract}`, `--combined-json`, `${json_args[i]}`, `--combined-json`, `${json_args[i]}`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
//id1829:II
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, --combined-json and multiple ARG: ${json_args[i]} ${json_args[i]}`, () => {
|
||||
const args = [
|
||||
`${paths.pathToBasicSolContract}`,
|
||||
`--combined-json`,
|
||||
`${json_args[i]}`,
|
||||
`${json_args[i]}`,
|
||||
];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(cannot be used multiple times)/i);
|
||||
});
|
||||
xit("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(
|
||||
/(No such file or directory|cannot find the file specified)/i,
|
||||
); // Hopefully we should have more precise message here!
|
||||
});
|
||||
|
||||
//id1830
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Yul, and --combined-json ${json_args[i]}`, () => {
|
||||
const args = [`${paths.pathToBasicYulContract}`, `--combined-json`, `${json_args[i]}`];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
xit("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
//id1829:III
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Sol, and multiple (--combined-json ${json_args[i]})`, () => {
|
||||
const args = [
|
||||
`${paths.pathToBasicSolContract}`,
|
||||
`--combined-json`,
|
||||
`${json_args[i]}`,
|
||||
`--combined-json`,
|
||||
`${json_args[i]}`,
|
||||
];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(ParserError: Expected identifier)/i);
|
||||
});
|
||||
asd
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(cannot be used multiple times)/i);
|
||||
});
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//id1830
|
||||
for (let i = 0; i < json_args.length; i++) {
|
||||
describe(`Run ${zksolcCommand} with Yul, and --combined-json ${json_args[i]}`, () => {
|
||||
const args = [
|
||||
`${paths.pathToBasicYulContract}`,
|
||||
`--combined-json`,
|
||||
`${json_args[i]}`,
|
||||
];
|
||||
const result = executeCommand(zksolcCommand, args);
|
||||
|
||||
it("Valid command exit code = 1", () => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("--combined-json error is presented", () => {
|
||||
expect(result.output).toMatch(/(ParserError: Expected identifier)/i);
|
||||
});
|
||||
asd;
|
||||
|
||||
it("solc exit code == zksolc exit code", () => {
|
||||
const solcResult = executeCommand(solcCommand, args);
|
||||
expect(solcResult.exitCode).toBe(result.exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user