mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Provide different options for reason strings.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <test/Options.h>
|
||||
|
||||
#include <libsolidity/interface/OptimiserSettings.h>
|
||||
#include <libsolidity/interface/DebugSettings.h>
|
||||
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
@@ -269,6 +270,7 @@ protected:
|
||||
bytes const& logData(size_t _logIdx) const;
|
||||
|
||||
langutil::EVMVersion m_evmVersion;
|
||||
solidity::RevertStrings m_revertStrings = solidity::RevertStrings::Default;
|
||||
solidity::OptimiserSettings m_optimiserSettings = solidity::OptimiserSettings::minimal();
|
||||
bool m_showMessages = false;
|
||||
std::shared_ptr<EVMHost> m_evmHost;
|
||||
|
||||
@@ -87,6 +87,7 @@ eth::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
||||
{
|
||||
Compiler compiler(
|
||||
dev::test::Options::get().evmVersion(),
|
||||
RevertStrings::Default,
|
||||
dev::test::Options::get().optimize ? OptimiserSettings::standard() : OptimiserSettings::minimal()
|
||||
);
|
||||
compiler.compileContract(*contract, map<ContractDefinition const*, shared_ptr<Compiler const>>{}, bytes());
|
||||
|
||||
@@ -284,6 +284,26 @@ BOOST_AUTO_TEST_CASE(metadata_useLiteralContent)
|
||||
check(sourceCode, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(metadata_revert_strings)
|
||||
{
|
||||
CompilerStack compilerStack;
|
||||
char const* sourceCodeA = R"(
|
||||
pragma solidity >=0.0;
|
||||
contract A {
|
||||
}
|
||||
)";
|
||||
compilerStack.setSources({{"A", std::string(sourceCodeA)}});
|
||||
compilerStack.setRevertStringBehaviour(RevertStrings::Strip);
|
||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||
|
||||
std::string const& serialisedMetadata = compilerStack.metadata("A");
|
||||
BOOST_CHECK(dev::test::isValidMetadata(serialisedMetadata));
|
||||
Json::Value metadata;
|
||||
BOOST_REQUIRE(jsonParseStrict(serialisedMetadata, metadata));
|
||||
|
||||
BOOST_CHECK_EQUAL(metadata["settings"]["debug"]["revertStrings"], "strip");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
@@ -14800,6 +14800,55 @@ BOOST_AUTO_TEST_CASE(try_catch_library_call)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(strip_reason_strings)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f(bool _x) public pure returns (uint) {
|
||||
require(_x, "some reason");
|
||||
return 7;
|
||||
}
|
||||
function g(bool _x) public pure returns (uint) {
|
||||
string memory x = "some indirect reason";
|
||||
require(_x, x);
|
||||
return 8;
|
||||
}
|
||||
function f1(bool _x) public pure returns (uint) {
|
||||
if (!_x) revert( /* */ "some reason" /* */ );
|
||||
return 9;
|
||||
}
|
||||
function g1(bool _x) public pure returns (uint) {
|
||||
string memory x = "some indirect reason";
|
||||
if (!_x) revert(x);
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
)";
|
||||
m_revertStrings = RevertStrings::Default;
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
|
||||
if (
|
||||
m_optimiserSettings == OptimiserSettings::minimal() ||
|
||||
m_optimiserSettings == OptimiserSettings::none()
|
||||
)
|
||||
// check that the reason string IS part of the binary.
|
||||
BOOST_CHECK(toHex(m_output).find("736f6d6520726561736f6e") != std::string::npos);
|
||||
|
||||
m_revertStrings = RevertStrings::Strip;
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
// check that the reason string is NOT part of the binary.
|
||||
BOOST_CHECK(toHex(m_output).find("736f6d6520726561736f6e") == std::string::npos);
|
||||
|
||||
ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(7));
|
||||
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("g(bool)", true), encodeArgs(8));
|
||||
ABI_CHECK(callContractFunction("g(bool)", false), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("f1(bool)", true), encodeArgs(9));
|
||||
ABI_CHECK(callContractFunction("f1(bool)", false), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("g1(bool)", true), encodeArgs(10));
|
||||
ABI_CHECK(callContractFunction("g1(bool)", false), encodeArgs());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ bytes SolidityExecutionFramework::compileContract(
|
||||
m_compiler.reset();
|
||||
m_compiler.setSources({{"", sourceCode}});
|
||||
m_compiler.setLibraries(_libraryAddresses);
|
||||
m_compiler.setRevertStringBehaviour(m_revertStrings);
|
||||
m_compiler.setEVMVersion(m_evmVersion);
|
||||
m_compiler.setOptimiserSettings(m_optimiserSettings);
|
||||
m_compiler.enableIRGeneration(m_compileViaYul);
|
||||
|
||||
@@ -152,7 +152,11 @@ bytes compileFirstExpression(
|
||||
parametersSize--
|
||||
);
|
||||
|
||||
ExpressionCompiler(context, dev::test::Options::get().optimize).compile(*extractor.expression());
|
||||
ExpressionCompiler(
|
||||
context,
|
||||
RevertStrings::Default,
|
||||
dev::test::Options::get().optimize
|
||||
).compile(*extractor.expression());
|
||||
|
||||
for (vector<string> const& function: _functions)
|
||||
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(
|
||||
|
||||
Reference in New Issue
Block a user