From b24dd42e478bd7d8b5f57362b2f06bcc2a785d4d Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 16 Apr 2019 18:10:50 +0200 Subject: [PATCH] Re-produce the original 'useLiteralContent' setting --- Changelog.md | 1 + docs/metadata.rst | 4 +++- libsolidity/interface/CompilerStack.cpp | 1 + test/libsolidity/Metadata.cpp | 31 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index da77ea53c..cfcb8c034 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ Language Features: Compiler Features: * ABI Decoder: Raise a runtime error on dirty inputs when using the experimental decoder. + * Standartd JSON Interface: Metadata settings now re-produce the original 'useLiteralContent' setting from the compilation input. * SMTChecker: Support arithmetic compound assignment operators. * SMTChecker: Support unary increment and decrement for array and mapping access. * SMTChecker: Show unsupported warning for inline assembly blocks. diff --git a/docs/metadata.rst b/docs/metadata.rst index 0d8054524..770a482de 100644 --- a/docs/metadata.rst +++ b/docs/metadata.rst @@ -92,7 +92,9 @@ explanatory purposes. // Required for Solidity: Addresses for libraries used libraries: { "MyLib": "0x123123..." - } + }, + // Reflects the setting used in the input json, defaults to false + "useLiteralContent": false }, // Required: Generated information about the contract. output: diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 3dfcc9267..84f744760 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1045,6 +1045,7 @@ string CompilerStack::createMetadata(Contract const& _contract) const meta["settings"]["optimizer"]["details"] = std::move(details); } + meta["settings"]["useLiteralContent"] = m_metadataLiteralSources; meta["settings"]["evmVersion"] = m_evmVersion.name(); meta["settings"]["compilationTarget"][_contract.contract->sourceUnitName()] = _contract.contract->annotation().canonicalName; diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index e5b3ef280..f93788b07 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -177,6 +177,37 @@ BOOST_AUTO_TEST_CASE(metadata_relevant_sources_imports) BOOST_CHECK(metadata["sources"].isMember("C")); } +BOOST_AUTO_TEST_CASE(metadata_useLiteralContent) +{ + // Check that the metadata contains "useLiteralContent" + char const* sourceCode = R"( + pragma solidity >=0.0; + contract test { + } + )"; + + auto check = [](char const* _src, bool _check) + { + CompilerStack compilerStack; + compilerStack.setSources({{"", std::string(_src)}}); + compilerStack.setEVMVersion(dev::test::Options::get().evmVersion()); + compilerStack.setOptimiserSettings(dev::test::Options::get().optimize); + compilerStack.useMetadataLiteralSources(_check); + BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed"); + string metadata_str = compilerStack.metadata("test"); + Json::Value metadata; + jsonParse(metadata_str, metadata); + BOOST_CHECK(metadata.isMember("settings")); + BOOST_CHECK(metadata["settings"].isMember("useLiteralContent")); + BOOST_CHECK(_check == metadata["settings"]["useLiteralContent"].asBool()); + BOOST_CHECK(dev::test::isValidMetadata(metadata_str)); + + }; + + check(sourceCode, true); + check(sourceCode, false); +} + BOOST_AUTO_TEST_SUITE_END() }