Move metadata settings into its own object.

This commit is contained in:
chriseth 2019-04-23 21:53:24 +02:00
parent eac0048176
commit eef3f95724
3 changed files with 20 additions and 10 deletions

View File

@ -84,6 +84,10 @@ explanatory purposes.
yulDetails: {}
}
},
metadata: {
// Reflects the setting used in the input json, defaults to false
useLiteralContent: true
}
// Required for Solidity: File and name of the contract or library this
// metadata is created for.
compilationTarget: {
@ -92,9 +96,7 @@ 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:

View File

@ -1067,7 +1067,8 @@ string CompilerStack::createMetadata(Contract const& _contract) const
meta["settings"]["optimizer"]["details"] = std::move(details);
}
meta["settings"]["useLiteralContent"] = m_metadataLiteralSources;
if (m_metadataLiteralSources)
meta["settings"]["metadata"]["useLiteralContent"] = true;
meta["settings"]["evmVersion"] = m_evmVersion.name();
meta["settings"]["compilationTarget"][_contract.contract->sourceUnitName()] =
_contract.contract->annotation().canonicalName;

View File

@ -186,22 +186,29 @@ BOOST_AUTO_TEST_CASE(metadata_useLiteralContent)
}
)";
auto check = [](char const* _src, bool _check)
auto check = [](char const* _src, bool _literal)
{
CompilerStack compilerStack;
compilerStack.setSources({{"", std::string(_src)}});
compilerStack.setEVMVersion(dev::test::Options::get().evmVersion());
compilerStack.setOptimiserSettings(dev::test::Options::get().optimize);
compilerStack.useMetadataLiteralSources(_check);
compilerStack.useMetadataLiteralSources(_literal);
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));
BOOST_CHECK(metadata.isMember("settings"));
if (_literal)
{
BOOST_CHECK(metadata["settings"].isMember("metadata"));
BOOST_CHECK(metadata["settings"]["metadata"].isMember("useLiteralContent"));
BOOST_CHECK(metadata["settings"]["metadata"]["useLiteralContent"].asBool());
}
else
{
BOOST_CHECK(!metadata["settings"].isMember("metadata"));
}
};
check(sourceCode, true);