mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Run metadata tests for every metadata format.
This commit is contained in:
parent
b598948211
commit
6e62cbf156
@ -37,13 +37,18 @@ namespace solidity::frontend::test
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
map<string, string> requireParsedCBORMetadata(bytes const& _bytecode)
|
map<string, string> requireParsedCBORMetadata(bytes const& _bytecode, CompilerStack::MetadataFormat _metadataFormat)
|
||||||
{
|
{
|
||||||
bytes cborMetadata = solidity::test::onlyMetadata(_bytecode);
|
bytes cborMetadata = solidity::test::onlyMetadata(_bytecode);
|
||||||
|
if (_metadataFormat != CompilerStack::MetadataFormat::NoMetadata)
|
||||||
|
{
|
||||||
BOOST_REQUIRE(!cborMetadata.empty());
|
BOOST_REQUIRE(!cborMetadata.empty());
|
||||||
std::optional<map<string, string>> tmp = solidity::test::parseCBORMetadata(cborMetadata);
|
std::optional<map<string, string>> tmp = solidity::test::parseCBORMetadata(cborMetadata);
|
||||||
BOOST_REQUIRE(tmp);
|
BOOST_REQUIRE(tmp);
|
||||||
return *tmp;
|
return *tmp;
|
||||||
|
}
|
||||||
|
BOOST_REQUIRE(cborMetadata.empty());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<string> compileAndCheckLicenseMetadata(string const& _contractName, char const* _sourceCode)
|
optional<string> compileAndCheckLicenseMetadata(string const& _contractName, char const* _sourceCode)
|
||||||
@ -83,7 +88,11 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
function g(function(uint) external returns (uint) x) public {}
|
function g(function(uint) external returns (uint) x) public {}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
for (auto release: std::set<bool>{true, VersionIsRelease})
|
for (auto metadataFormat: std::set<CompilerStack::MetadataFormat>{
|
||||||
|
CompilerStack::MetadataFormat::NoMetadata,
|
||||||
|
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
||||||
|
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
||||||
|
})
|
||||||
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
||||||
CompilerStack::MetadataHash::IPFS,
|
CompilerStack::MetadataHash::IPFS,
|
||||||
CompilerStack::MetadataHash::Bzzr1,
|
CompilerStack::MetadataHash::Bzzr1,
|
||||||
@ -91,7 +100,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
})
|
})
|
||||||
{
|
{
|
||||||
CompilerStack compilerStack;
|
CompilerStack compilerStack;
|
||||||
compilerStack.overwriteReleaseFlag(release);
|
compilerStack.setMetadataFormat(metadataFormat);
|
||||||
compilerStack.setSources({{"", std::string(sourceCode)}});
|
compilerStack.setSources({{"", std::string(sourceCode)}});
|
||||||
compilerStack.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
compilerStack.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||||
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
@ -101,9 +110,9 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
std::string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
|
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
||||||
if (metadataHash == CompilerStack::MetadataHash::None)
|
if (metadataHash == CompilerStack::MetadataHash::None)
|
||||||
BOOST_CHECK(cborMetadata.size() == 1);
|
BOOST_CHECK(cborMetadata.size() == (metadataFormat == CompilerStack::MetadataFormat::NoMetadata ? 0 : 1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytes hash;
|
bytes hash;
|
||||||
@ -121,17 +130,25 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
hashMethod = "bzzr1";
|
hashMethod = "bzzr1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metadataFormat != CompilerStack::MetadataFormat::NoMetadata)
|
||||||
|
{
|
||||||
BOOST_CHECK(cborMetadata.size() == 2);
|
BOOST_CHECK(cborMetadata.size() == 2);
|
||||||
BOOST_CHECK(cborMetadata.count(hashMethod) == 1);
|
BOOST_CHECK(cborMetadata.count(hashMethod) == 1);
|
||||||
BOOST_CHECK(cborMetadata.at(hashMethod) == util::toHex(hash));
|
BOOST_CHECK(cborMetadata.at(hashMethod) == util::toHex(hash));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadataFormat == CompilerStack::MetadataFormat::NoMetadata)
|
||||||
|
BOOST_CHECK(cborMetadata.count("solc") == 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||||
if (release)
|
if (metadataFormat == CompilerStack::MetadataFormat::WithReleaseVersionTag)
|
||||||
BOOST_CHECK(cborMetadata.at("solc") == util::toHex(VersionCompactBytes));
|
BOOST_CHECK(cborMetadata.at("solc") == util::toHex(VersionCompactBytes));
|
||||||
else
|
else
|
||||||
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
||||||
@ -144,7 +161,11 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
function g(function(uint) external returns (uint) x) public {}
|
function g(function(uint) external returns (uint) x) public {}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
for (auto release: set<bool>{true, VersionIsRelease})
|
for (auto metadataFormat: std::set<CompilerStack::MetadataFormat>{
|
||||||
|
CompilerStack::MetadataFormat::NoMetadata,
|
||||||
|
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
||||||
|
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
||||||
|
})
|
||||||
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
||||||
CompilerStack::MetadataHash::IPFS,
|
CompilerStack::MetadataHash::IPFS,
|
||||||
CompilerStack::MetadataHash::Bzzr1,
|
CompilerStack::MetadataHash::Bzzr1,
|
||||||
@ -152,7 +173,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
})
|
})
|
||||||
{
|
{
|
||||||
CompilerStack compilerStack;
|
CompilerStack compilerStack;
|
||||||
compilerStack.overwriteReleaseFlag(release);
|
compilerStack.setMetadataFormat(metadataFormat);
|
||||||
compilerStack.setSources({{"", std::string(sourceCode)}});
|
compilerStack.setSources({{"", std::string(sourceCode)}});
|
||||||
compilerStack.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
compilerStack.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||||
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
@ -162,9 +183,9 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
std::string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
|
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
||||||
if (metadataHash == CompilerStack::MetadataHash::None)
|
if (metadataHash == CompilerStack::MetadataHash::None)
|
||||||
BOOST_CHECK(cborMetadata.size() == 2);
|
BOOST_CHECK(cborMetadata.size() == (metadataFormat == CompilerStack::MetadataFormat::NoMetadata ? 0 : 2));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytes hash;
|
bytes hash;
|
||||||
@ -182,19 +203,27 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
hashMethod = "bzzr1";
|
hashMethod = "bzzr1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metadataFormat != CompilerStack::MetadataFormat::NoMetadata)
|
||||||
|
{
|
||||||
BOOST_CHECK(cborMetadata.size() == 3);
|
BOOST_CHECK(cborMetadata.size() == 3);
|
||||||
BOOST_CHECK(cborMetadata.count(hashMethod) == 1);
|
BOOST_CHECK(cborMetadata.count(hashMethod) == 1);
|
||||||
BOOST_CHECK(cborMetadata.at(hashMethod) == util::toHex(hash));
|
BOOST_CHECK(cborMetadata.at(hashMethod) == util::toHex(hash));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadataFormat == CompilerStack::MetadataFormat::NoMetadata)
|
||||||
|
BOOST_CHECK(cborMetadata.count("solc") == 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||||
if (release)
|
if (metadataFormat == CompilerStack::MetadataFormat::WithReleaseVersionTag)
|
||||||
BOOST_CHECK(cborMetadata.at("solc") == util::toHex(VersionCompactBytes));
|
BOOST_CHECK(cborMetadata.at("solc") == util::toHex(VersionCompactBytes));
|
||||||
else
|
else
|
||||||
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||||
BOOST_CHECK(cborMetadata.count("experimental") == 1);
|
BOOST_CHECK(cborMetadata.count("experimental") == 1);
|
||||||
BOOST_CHECK(cborMetadata.at("experimental") == "true");
|
BOOST_CHECK(cborMetadata.at("experimental") == "true");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
|
BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
|
||||||
|
Loading…
Reference in New Issue
Block a user