From 67c15a208d72749b9d9a2b73dc5871e5d1f24b73 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 5 Mar 2019 01:10:46 +0100 Subject: [PATCH] Use CBOR parser in metadata tests --- test/libsolidity/Metadata.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index 3402959da..d1e0cd678 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -25,6 +25,8 @@ #include #include +using namespace std; + namespace dev { namespace solidity @@ -32,6 +34,18 @@ namespace solidity namespace test { +namespace +{ +map requireParsedCBORMetadata(bytes const& _bytecode) +{ + bytes cborMetadata = dev::test::onlyMetadata(_bytecode); + BOOST_REQUIRE(!cborMetadata.empty()); + boost::optional> tmp = dev::test::parseCBORMetadata(cborMetadata); + BOOST_REQUIRE(tmp); + return *tmp; +} +} + BOOST_AUTO_TEST_SUITE(Metadata) BOOST_AUTO_TEST_CASE(metadata_stamp) @@ -54,10 +68,10 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) BOOST_CHECK(dev::test::isValidMetadata(metadata)); bytes hash = dev::swarmHash(metadata).asBytes(); BOOST_REQUIRE(hash.size() == 32); - bytes cborMetadata = dev::test::onlyMetadata(bytecode); - BOOST_REQUIRE(!cborMetadata.empty()); - bytes expectation = bytes{0xa1, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} + hash; - BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), cborMetadata.begin())); + auto const cborMetadata = requireParsedCBORMetadata(bytecode); + BOOST_CHECK(cborMetadata.size() == 1); + BOOST_CHECK(cborMetadata.count("bzzr0") == 1); + BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash)); } BOOST_AUTO_TEST_CASE(metadata_stamp_experimental) @@ -80,13 +94,12 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental) BOOST_CHECK(dev::test::isValidMetadata(metadata)); bytes hash = dev::swarmHash(metadata).asBytes(); BOOST_REQUIRE(hash.size() == 32); - bytes cborMetadata = dev::test::onlyMetadata(bytecode); - BOOST_REQUIRE(!cborMetadata.empty()); - bytes expectation = - bytes{0xa2, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} + - hash + - bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5}; - BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), cborMetadata.begin())); + auto const cborMetadata = requireParsedCBORMetadata(bytecode); + BOOST_CHECK(cborMetadata.size() == 2); + BOOST_CHECK(cborMetadata.count("bzzr0") == 1); + BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash)); + BOOST_CHECK(cborMetadata.count("experimental") == 1); + BOOST_CHECK(cborMetadata.at("experimental") == "true"); } BOOST_AUTO_TEST_CASE(metadata_relevant_sources)