mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Store compiler version in CBOR metadata
This commit is contained in:
committed by
Daniel Kirchner
parent
4037da9575
commit
e121c8f3c7
+2
-2
@@ -41,9 +41,9 @@ bytes onlyMetadata(bytes const& _bytecode)
|
||||
size_t metadataSize = (_bytecode[size - 2] << 8) + _bytecode[size - 1];
|
||||
if (size < (metadataSize + 2))
|
||||
return bytes{};
|
||||
// Sanity check: assume the first byte is a fixed-size CBOR array with either 1 or 2 entries
|
||||
// Sanity check: assume the first byte is a fixed-size CBOR array with either 2 or 3 entries
|
||||
unsigned char firstByte = _bytecode[size - metadataSize - 2];
|
||||
if (firstByte != 0xa1 && firstByte != 0xa2)
|
||||
if (firstByte != 0xa2 && firstByte != 0xa3)
|
||||
return bytes{};
|
||||
return bytes(_bytecode.end() - metadataSize - 2, _bytecode.end() - 2);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <test/Metadata.h>
|
||||
#include <test/Options.h>
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
#include <libdevcore/SwarmHash.h>
|
||||
#include <libdevcore/JSON.h>
|
||||
|
||||
@@ -69,7 +70,12 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
||||
bytes hash = dev::swarmHash(metadata).asBytes();
|
||||
BOOST_REQUIRE(hash.size() == 32);
|
||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
||||
BOOST_CHECK(cborMetadata.size() == 1);
|
||||
BOOST_CHECK(cborMetadata.size() == 2);
|
||||
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||
if (VersionIsRelease)
|
||||
BOOST_CHECK(cborMetadata.at("solc") == toHex(VersionCompactBytes));
|
||||
else
|
||||
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
||||
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
||||
}
|
||||
@@ -95,7 +101,12 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
||||
bytes hash = dev::swarmHash(metadata).asBytes();
|
||||
BOOST_REQUIRE(hash.size() == 32);
|
||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
||||
BOOST_CHECK(cborMetadata.size() == 2);
|
||||
BOOST_CHECK(cborMetadata.size() == 3);
|
||||
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||
if (VersionIsRelease)
|
||||
BOOST_CHECK(cborMetadata.at("solc") == toHex(VersionCompactBytes));
|
||||
else
|
||||
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
||||
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
||||
BOOST_CHECK(cborMetadata.count("experimental") == 1);
|
||||
|
||||
Reference in New Issue
Block a user