2021-06-07 17:04:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
/// Unit tests for solc/CommandLineParser.h
|
|
|
|
|
|
|
|
#include <solc/CommandLineParser.h>
|
2021-10-11 11:48:03 +00:00
|
|
|
#include <solc/Exceptions.h>
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-13 13:53:16 +00:00
|
|
|
#include <test/solc/Common.h>
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
#include <test/Common.h>
|
|
|
|
#include <test/libsolidity/util/SoltestErrors.h>
|
|
|
|
|
|
|
|
#include <libsolutil/CommonData.h>
|
|
|
|
#include <liblangutil/EVMVersion.h>
|
2021-05-19 15:35:19 +00:00
|
|
|
#include <libsmtutil/SolverInterface.h>
|
2021-06-07 17:04:02 +00:00
|
|
|
#include <libsolidity/interface/Version.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
using namespace solidity::langutil;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::yul;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parseCommandLine(vector<string> const& _commandLine)
|
2021-06-07 17:04:02 +00:00
|
|
|
{
|
2021-06-13 13:53:16 +00:00
|
|
|
vector<char const*> argv = test::makeArgv(_commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 12:20:56 +00:00
|
|
|
CommandLineParser cliParser;
|
2021-10-11 11:48:03 +00:00
|
|
|
cliParser.parse(static_cast<int>(_commandLine.size()), argv.data());
|
|
|
|
return cliParser.options();
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace solidity::frontend::test
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(CommandLineParserTest)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(no_options)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {"solc", "contract.sol"};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.paths = {"contract.sol"};
|
|
|
|
expectedOptions.modelChecker.initialize = true;
|
2021-07-15 15:39:01 +00:00
|
|
|
expectedOptions.modelChecker.settings = {};
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
BOOST_TEST(parsedOptions == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 11:03:51 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(help_license_version)
|
2021-06-16 20:50:32 +00:00
|
|
|
{
|
2021-10-11 11:03:51 +00:00
|
|
|
map<string, InputMode> expectedModePerOption = {
|
|
|
|
{"--help", InputMode::Help},
|
|
|
|
{"--license", InputMode::License},
|
|
|
|
{"--version", InputMode::Version},
|
|
|
|
};
|
2021-06-16 20:50:32 +00:00
|
|
|
|
2021-10-11 11:03:51 +00:00
|
|
|
for (auto const& [option, expectedMode]: expectedModePerOption)
|
|
|
|
{
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parsedOptions = parseCommandLine({"solc", option});
|
2021-10-11 11:03:51 +00:00
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.mode = expectedMode;
|
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
BOOST_TEST(parsedOptions == expectedOptions);
|
2021-10-11 11:03:51 +00:00
|
|
|
}
|
2021-06-16 20:50:32 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(cli_mode_options)
|
|
|
|
{
|
|
|
|
for (InputMode inputMode: {InputMode::Compiler, InputMode::CompilerWithASTImport})
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"contract.sol", // Both modes do not care about file names, just about
|
|
|
|
"/tmp/projects/token.sol", // their content. They also both support stdin.
|
|
|
|
"/home/user/lib/dex.sol",
|
|
|
|
"file",
|
|
|
|
"input.json",
|
|
|
|
"-",
|
|
|
|
"/tmp=/usr/lib/",
|
|
|
|
"a:b=c/d",
|
|
|
|
":contract.sol=",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
|
|
|
"--ignore-missing",
|
|
|
|
"--output-dir=/tmp/out",
|
|
|
|
"--overwrite",
|
|
|
|
"--evm-version=spuriousDragon",
|
2022-03-09 15:02:31 +00:00
|
|
|
"--via-ir",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--experimental-via-ir",
|
|
|
|
"--revert-strings=strip",
|
2021-09-13 12:17:05 +00:00
|
|
|
"--debug-info=location",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--pretty-json",
|
2021-07-07 11:18:24 +00:00
|
|
|
"--json-indent=7",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color",
|
|
|
|
"--error-codes",
|
|
|
|
"--libraries="
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
|
|
|
"--ast-compact-json", "--asm", "--asm-json", "--opcodes", "--bin", "--bin-runtime", "--abi",
|
2023-05-02 13:34:12 +00:00
|
|
|
"--ir", "--ir-ast-json", "--ir-optimized", "--ir-optimized-ast-json", "--hashes", "--userdoc", "--devdoc", "--metadata", "--storage-layout",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--gas",
|
|
|
|
"--combined-json="
|
|
|
|
"abi,metadata,bin,bin-runtime,opcodes,asm,storage-layout,generated-sources,generated-sources-runtime,"
|
|
|
|
"srcmap,srcmap-runtime,function-debug,function-debug-runtime,hashes,devdoc,userdoc,ast",
|
|
|
|
"--metadata-hash=swarm",
|
|
|
|
"--metadata-literal",
|
|
|
|
"--optimize",
|
2023-05-24 12:22:18 +00:00
|
|
|
"--optimize-yul",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--optimize-runs=1000",
|
|
|
|
"--yul-optimizations=agf",
|
2023-02-23 18:22:46 +00:00
|
|
|
"--model-checker-bmc-loop-iterations=2",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-contracts=contract1.yul:A,contract2.yul:B",
|
2021-07-15 15:39:01 +00:00
|
|
|
"--model-checker-div-mod-no-slacks",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-engine=bmc",
|
2021-10-12 09:12:18 +00:00
|
|
|
"--model-checker-ext-calls=trusted",
|
2021-10-06 09:52:44 +00:00
|
|
|
"--model-checker-invariants=contract,reentrancy",
|
2023-02-09 16:07:13 +00:00
|
|
|
"--model-checker-show-proved-safe",
|
2021-08-11 08:54:03 +00:00
|
|
|
"--model-checker-show-unproved",
|
2023-03-06 13:19:58 +00:00
|
|
|
"--model-checker-show-unsupported",
|
2021-05-19 15:35:19 +00:00
|
|
|
"--model-checker-solvers=z3,smtlib2",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-targets=underflow,divByZero",
|
2023-02-23 18:22:46 +00:00
|
|
|
"--model-checker-timeout=5"
|
2021-06-07 17:04:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (inputMode == InputMode::CompilerWithASTImport)
|
|
|
|
commandLine += vector<string>{
|
|
|
|
"--import-ast",
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.mode = inputMode;
|
|
|
|
expectedOptions.input.paths = {"contract.sol", "/tmp/projects/token.sol", "/home/user/lib/dex.sol", "file", "input.json"};
|
|
|
|
expectedOptions.input.remappings = {
|
|
|
|
{"", "/tmp", "/usr/lib/"},
|
|
|
|
{"a", "b", "c/d"},
|
|
|
|
{"", "contract.sol", ""},
|
|
|
|
};
|
2021-07-07 11:18:24 +00:00
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.addStdin = true;
|
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
|
|
|
|
2021-07-23 18:27:50 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts", "c", "/usr/lib"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
|
|
|
expectedOptions.output.dir = "/tmp/out";
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
2022-03-09 15:02:31 +00:00
|
|
|
expectedOptions.output.viaIR = true;
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-09-13 12:17:05 +00:00
|
|
|
expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location");
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat{JsonFormat::Pretty, 7};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.linker.libraries = {
|
|
|
|
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
|
|
|
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
|
|
|
};
|
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
|
|
|
expectedOptions.compiler.outputs = {
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
2023-05-02 13:34:12 +00:00
|
|
|
true, true, true, true, true,
|
|
|
|
true,
|
2021-06-07 17:04:02 +00:00
|
|
|
};
|
|
|
|
expectedOptions.compiler.estimateGas = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests = {
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true,
|
|
|
|
};
|
|
|
|
expectedOptions.metadata.hash = CompilerStack::MetadataHash::Bzzr1;
|
|
|
|
expectedOptions.metadata.literalSources = true;
|
2023-05-24 12:22:18 +00:00
|
|
|
expectedOptions.optimizer.optimizeEvmasm = true;
|
|
|
|
expectedOptions.optimizer.optimizeYul = true;
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
|
|
|
expectedOptions.optimizer.yulSteps = "agf";
|
|
|
|
|
|
|
|
expectedOptions.modelChecker.initialize = true;
|
|
|
|
expectedOptions.modelChecker.settings = {
|
2023-02-23 18:22:46 +00:00
|
|
|
2,
|
2021-06-07 17:04:02 +00:00
|
|
|
{{{"contract1.yul", {"A"}}, {"contract2.yul", {"B"}}}},
|
2021-07-15 15:39:01 +00:00
|
|
|
true,
|
2021-06-07 17:04:02 +00:00
|
|
|
{true, false},
|
2021-10-12 09:12:18 +00:00
|
|
|
{ModelCheckerExtCalls::Mode::TRUSTED},
|
2021-10-06 09:52:44 +00:00
|
|
|
{{InvariantType::Contract, InvariantType::Reentrancy}},
|
2023-04-26 10:50:36 +00:00
|
|
|
false, // --model-checker-print-query
|
2021-07-02 13:05:24 +00:00
|
|
|
true,
|
2023-02-09 16:07:13 +00:00
|
|
|
true,
|
2023-03-06 13:19:58 +00:00
|
|
|
true,
|
2022-05-15 15:45:43 +00:00
|
|
|
{false, false, true, true},
|
2021-06-07 17:04:02 +00:00
|
|
|
{{VerificationTargetType::Underflow, VerificationTargetType::DivByZero}},
|
|
|
|
5,
|
|
|
|
};
|
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
BOOST_TEST(parsedOptions == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 22:22:56 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(no_cbor_metadata)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {"solc", "--no-cbor-metadata", "contract.sol"};
|
|
|
|
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
|
|
|
bool assert = parsedOptions.metadata.format == CompilerStack::MetadataFormat::NoMetadata;
|
|
|
|
|
|
|
|
BOOST_TEST(assert);
|
|
|
|
}
|
|
|
|
|
2022-03-09 15:02:31 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(via_ir_options)
|
|
|
|
{
|
|
|
|
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);
|
|
|
|
for (string viaIrOption: {"--via-ir", "--experimental-via-ir"})
|
|
|
|
BOOST_TEST(parseCommandLine({"solc", viaIrOption, "contract.sol"}).output.viaIR);
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
|
|
|
{
|
2022-03-28 04:27:11 +00:00
|
|
|
static vector<tuple<vector<string>, YulStack::Machine, YulStack::Language>> const allowedCombinations = {
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly},
|
|
|
|
{{"--machine=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul},
|
|
|
|
{{"--machine=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
|
|
|
|
{{"--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly},
|
|
|
|
{{"--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul},
|
|
|
|
{{"--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
|
2021-06-07 17:04:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const& [assemblyOptions, expectedMachine, expectedLanguage]: allowedCombinations)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"contract.yul",
|
|
|
|
"/tmp/projects/token.yul",
|
|
|
|
"/home/user/lib/dex.yul",
|
|
|
|
"file",
|
|
|
|
"input.json",
|
|
|
|
"-",
|
|
|
|
"/tmp=/usr/lib/",
|
|
|
|
"a:b=c/d",
|
|
|
|
":contract.yul=",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
|
|
|
"--ignore-missing",
|
|
|
|
"--overwrite",
|
|
|
|
"--evm-version=spuriousDragon",
|
|
|
|
"--revert-strings=strip", // Accepted but has no effect in assembly mode
|
2021-09-13 12:17:05 +00:00
|
|
|
"--debug-info=location",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--pretty-json",
|
2021-07-07 11:18:24 +00:00
|
|
|
"--json-indent=1",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color",
|
|
|
|
"--error-codes",
|
|
|
|
"--libraries="
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
2021-09-30 18:38:28 +00:00
|
|
|
"--asm",
|
|
|
|
"--bin",
|
|
|
|
"--ir-optimized",
|
2023-05-02 13:34:12 +00:00
|
|
|
"--ast-compact-json",
|
2021-06-07 17:04:02 +00:00
|
|
|
};
|
|
|
|
commandLine += assemblyOptions;
|
2023-02-22 15:32:29 +00:00
|
|
|
if (expectedLanguage == YulStack::Language::StrictAssembly)
|
2021-06-07 17:04:02 +00:00
|
|
|
commandLine += vector<string>{
|
|
|
|
"--optimize",
|
2021-07-28 15:53:19 +00:00
|
|
|
"--optimize-runs=1000",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--yul-optimizations=agf",
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.mode = InputMode::Assembler;
|
|
|
|
|
|
|
|
expectedOptions.input.paths = {"contract.yul", "/tmp/projects/token.yul", "/home/user/lib/dex.yul", "file", "input.json"};
|
|
|
|
expectedOptions.input.remappings = {
|
|
|
|
{"", "/tmp", "/usr/lib/"},
|
|
|
|
{"a", "b", "c/d"},
|
|
|
|
{"", "contract.yul", ""},
|
|
|
|
};
|
|
|
|
expectedOptions.input.addStdin = true;
|
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
2021-07-23 18:27:50 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts", "c", "/usr/lib"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-09-13 12:17:05 +00:00
|
|
|
expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location");
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.assembly.targetMachine = expectedMachine;
|
|
|
|
expectedOptions.assembly.inputLanguage = expectedLanguage;
|
|
|
|
expectedOptions.linker.libraries = {
|
|
|
|
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
|
|
|
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
|
|
|
};
|
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
2021-09-30 18:38:28 +00:00
|
|
|
expectedOptions.compiler.outputs.asm_ = true;
|
|
|
|
expectedOptions.compiler.outputs.binary = true;
|
|
|
|
expectedOptions.compiler.outputs.irOptimized = true;
|
2023-05-02 13:34:12 +00:00
|
|
|
expectedOptions.compiler.outputs.astCompactJson = true;
|
2023-02-22 15:32:29 +00:00
|
|
|
if (expectedLanguage == YulStack::Language::StrictAssembly)
|
2021-06-07 17:04:02 +00:00
|
|
|
{
|
2023-05-24 12:22:18 +00:00
|
|
|
expectedOptions.optimizer.optimizeEvmasm = true;
|
|
|
|
expectedOptions.optimizer.optimizeYul = true;
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.optimizer.yulSteps = "agf";
|
2021-07-28 15:53:19 +00:00
|
|
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
BOOST_TEST(parsedOptions == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"input.json",
|
|
|
|
"--standard-json",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
2021-06-13 13:53:16 +00:00
|
|
|
"--ignore-missing",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--output-dir=/tmp/out", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--overwrite", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
|
|
|
|
"--revert-strings=strip", // Accepted but has no effect in Standard JSON mode
|
2021-07-07 11:18:24 +00:00
|
|
|
"--pretty-json",
|
|
|
|
"--json-indent=1",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--error-codes", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--libraries=" // Ignored in Standard JSON mode
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
|
|
|
"--gas", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--combined-json=abi,bin", // Accepted but has no effect in Standard JSON mode
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
2021-07-07 11:18:24 +00:00
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.mode = InputMode::StandardJson;
|
2021-06-13 13:53:16 +00:00
|
|
|
expectedOptions.input.paths = {"input.json"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts"};
|
2021-06-13 13:53:16 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.output.dir = "/tmp/out";
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
|
|
|
expectedOptions.compiler.estimateGas = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests = CombinedJsonRequests{};
|
|
|
|
expectedOptions.compiler.combinedJsonRequests->abi = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests->binary = true;
|
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-10-11 11:48:03 +00:00
|
|
|
BOOST_TEST(parsedOptions == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 16:57:09 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
|
2021-08-27 16:10:41 +00:00
|
|
|
{
|
2021-08-31 16:57:09 +00:00
|
|
|
map<string, vector<string>> invalidOptionInputModeCombinations = {
|
|
|
|
// TODO: This should eventually contain all options.
|
2022-03-09 15:02:31 +00:00
|
|
|
{"--experimental-via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
2021-11-01 13:47:30 +00:00
|
|
|
{"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--metadata-literal", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--metadata-hash=swarm", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
2023-02-09 16:07:13 +00:00
|
|
|
{"--model-checker-show-proved-safe", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
2021-11-01 13:47:30 +00:00
|
|
|
{"--model-checker-show-unproved", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
2023-03-06 13:19:58 +00:00
|
|
|
{"--model-checker-show-unsupported", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
2021-11-01 13:47:30 +00:00
|
|
|
{"--model-checker-div-mod-no-slacks", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-engine=bmc", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-invariants=contract,reentrancy", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-solvers=z3,smtlib2", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-timeout=5", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-contracts=contract1.yul:A,contract2.yul:B", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
|
|
|
{"--model-checker-targets=underflow,divByZero", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}
|
2021-08-27 16:10:41 +00:00
|
|
|
};
|
|
|
|
|
2021-08-31 16:57:09 +00:00
|
|
|
for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations)
|
|
|
|
for (string const& inputMode: inputModes)
|
|
|
|
{
|
2021-10-11 11:03:51 +00:00
|
|
|
stringstream serr;
|
2021-11-01 13:47:30 +00:00
|
|
|
size_t separatorPosition = optionName.find("=");
|
|
|
|
string optionNameWithoutValue = optionName.substr(0, separatorPosition);
|
|
|
|
soltestAssert(!optionNameWithoutValue.empty());
|
|
|
|
|
2021-08-31 16:57:09 +00:00
|
|
|
vector<string> commandLine = {"solc", optionName, "file", inputMode};
|
|
|
|
|
2021-11-01 13:47:30 +00:00
|
|
|
string expectedMessage = "The following options are not supported in the current input mode: " + optionNameWithoutValue;
|
2021-10-11 11:48:03 +00:00
|
|
|
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; };
|
|
|
|
|
|
|
|
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);
|
2021-08-31 16:57:09 +00:00
|
|
|
}
|
2021-08-27 16:10:41 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:22:18 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(optimizer_flags)
|
|
|
|
{
|
2023-05-23 12:59:54 +00:00
|
|
|
OptimiserSettings yulOnly = OptimiserSettings::minimal();
|
|
|
|
yulOnly.runYulOptimiser = true;
|
|
|
|
yulOnly.optimizeStackAllocation = true;
|
|
|
|
|
2023-05-24 12:22:18 +00:00
|
|
|
OptimiserSettings evmasmOnly = OptimiserSettings::standard();
|
|
|
|
evmasmOnly.runYulOptimiser = false;
|
|
|
|
|
|
|
|
map<vector<string>, OptimiserSettings> settingsMap = {
|
|
|
|
{{}, OptimiserSettings::minimal()},
|
|
|
|
{{"--optimize"}, OptimiserSettings::standard()},
|
|
|
|
{{"--no-optimize-yul"}, OptimiserSettings::minimal()},
|
2023-05-23 12:59:54 +00:00
|
|
|
{{"--optimize-yul"}, yulOnly},
|
2023-05-24 12:22:18 +00:00
|
|
|
{{"--optimize", "--no-optimize-yul"}, evmasmOnly},
|
|
|
|
{{"--optimize", "--optimize-yul"}, OptimiserSettings::standard()},
|
|
|
|
};
|
|
|
|
|
|
|
|
map<InputMode, string> inputModeFlagMap = {
|
|
|
|
{InputMode::Compiler, ""},
|
|
|
|
{InputMode::CompilerWithASTImport, "--import-ast"},
|
2023-05-23 12:59:54 +00:00
|
|
|
{InputMode::Assembler, "--strict-assembly"},
|
2023-05-24 12:22:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const& [inputMode, inputModeFlag]: inputModeFlagMap)
|
|
|
|
for (auto const& [optimizerFlags, expectedOptimizerSettings]: settingsMap)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {"solc", inputModeFlag, "file"};
|
|
|
|
commandLine += optimizerFlags;
|
|
|
|
BOOST_CHECK(parseCommandLine(commandLine).optimiserSettings() == expectedOptimizerSettings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 09:58:12 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(default_optimiser_sequence)
|
|
|
|
{
|
2022-09-12 08:57:02 +00:00
|
|
|
CommandLineOptions const& commandLineOptions = parseCommandLine({"solc", "contract.sol", "--optimize"});
|
2022-08-23 09:58:12 +00:00
|
|
|
BOOST_CHECK_EQUAL(commandLineOptions.optimiserSettings().yulOptimiserSteps, OptimiserSettings::DefaultYulOptimiserSteps);
|
|
|
|
BOOST_CHECK_EQUAL(commandLineOptions.optimiserSettings().yulOptimiserCleanupSteps, OptimiserSettings::DefaultYulOptimiserCleanupSteps);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(valid_optimiser_sequences)
|
|
|
|
{
|
|
|
|
vector<string> validSequenceInputs {
|
2022-09-13 10:07:30 +00:00
|
|
|
":", // Empty optimization sequence and empty cleanup sequence
|
|
|
|
":fDn", // Empty optimization sequence and specified cleanup sequence
|
|
|
|
"dhfoDgvulfnTUtnIf:", // Specified optimization sequence and empty cleanup sequence
|
|
|
|
"dhfoDgvulfnTUtnIf:fDn", // Specified optimization sequence and cleanup sequence
|
|
|
|
"dhfo[Dgvulfn]TUtnIf:f[D]n", // Specified and nested optimization and cleanup sequence
|
|
|
|
"dhfoDgvulfnTUtnIf", // Specified optimizer sequence only
|
|
|
|
"iDu", // Short optimizer sequence
|
|
|
|
"a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a]" // Nested brackets
|
2022-08-23 09:58:12 +00:00
|
|
|
};
|
|
|
|
|
2022-09-13 10:07:30 +00:00
|
|
|
vector<tuple<string, string>> const expectedParsedSequences {
|
2022-09-12 08:57:02 +00:00
|
|
|
{"", ""},
|
|
|
|
{"", "fDn"},
|
|
|
|
{"dhfoDgvulfnTUtnIf", ""},
|
|
|
|
{"dhfoDgvulfnTUtnIf", "fDn"},
|
2022-09-13 10:07:30 +00:00
|
|
|
{"dhfo[Dgvulfn]TUtnIf", "f[D]n"},
|
|
|
|
{"dhfoDgvulfnTUtnIf", OptimiserSettings::DefaultYulOptimiserCleanupSteps},
|
|
|
|
{"iDu", OptimiserSettings::DefaultYulOptimiserCleanupSteps},
|
|
|
|
{"a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a]", OptimiserSettings::DefaultYulOptimiserCleanupSteps}
|
2022-08-23 09:58:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(validSequenceInputs.size(), expectedParsedSequences.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < validSequenceInputs.size(); ++i)
|
|
|
|
{
|
2022-09-12 08:57:02 +00:00
|
|
|
CommandLineOptions const& commandLineOptions = parseCommandLine({"solc", "contract.sol", "--optimize", "--yul-optimizations=" + validSequenceInputs[i]});
|
2022-08-23 09:58:12 +00:00
|
|
|
auto const& [expectedYulOptimiserSteps, expectedYulCleanupSteps] = expectedParsedSequences[i];
|
|
|
|
BOOST_CHECK_EQUAL(commandLineOptions.optimiserSettings().yulOptimiserSteps, expectedYulOptimiserSteps);
|
|
|
|
BOOST_CHECK_EQUAL(commandLineOptions.optimiserSettings().yulOptimiserCleanupSteps, expectedYulCleanupSteps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 10:07:30 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(invalid_optimiser_sequences)
|
2022-08-23 09:58:12 +00:00
|
|
|
{
|
2022-09-13 10:07:30 +00:00
|
|
|
vector<string> const invalidSequenceInputs {
|
|
|
|
"abcdefg{hijklmno}pqr[st]uvwxyz", // Invalid abbreviation
|
|
|
|
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
|
|
|
|
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
|
|
|
|
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
|
|
|
|
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
|
|
|
|
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a]"
|
|
|
|
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
|
|
|
|
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
|
|
|
|
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
|
|
|
|
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
|
|
|
|
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", // Brackets nested too deep
|
|
|
|
"a]a][", // Unbalanced closing bracket
|
|
|
|
"a[a][", // Unbalanced opening bracket
|
|
|
|
"dhfoDgvulfnTUt[nIf:fd]N", // Nested cleanup sequence delimiter
|
|
|
|
"dhfoDgvulfnTU:tnIf:fdN" // Too many cleanup sequence delimiters
|
|
|
|
};
|
2022-08-23 09:58:12 +00:00
|
|
|
|
2022-09-13 10:07:30 +00:00
|
|
|
vector<string> const expectedErrorMessages {
|
|
|
|
"'b' is not a valid step abbreviation",
|
|
|
|
"Brackets nested too deep",
|
|
|
|
"Unbalanced brackets",
|
|
|
|
"Unbalanced brackets",
|
|
|
|
"Cleanup sequence delimiter cannot be placed inside the brackets",
|
|
|
|
"Too many cleanup sequence delimiters"
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(invalidSequenceInputs.size(), expectedErrorMessages.size());
|
|
|
|
|
|
|
|
string const baseExpectedErrorMessage = "Invalid optimizer step sequence in --yul-optimizations: ";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < invalidSequenceInputs.size(); ++i)
|
|
|
|
{
|
|
|
|
vector<string> const commandLineOptions = {"solc", "contract.sol", "--optimize", "--yul-optimizations=" + invalidSequenceInputs[i]};
|
|
|
|
string const expectedErrorMessage = baseExpectedErrorMessage + expectedErrorMessages[i];
|
|
|
|
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedErrorMessage; };
|
|
|
|
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLineOptions), CommandLineValidationError, hasCorrectMessage);
|
|
|
|
}
|
2022-08-23 09:58:12 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|
|
|
|
} // namespace solidity::frontend::test
|