diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-24 16:50:22 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-24 19:24:00 +0800 |
commit | 804e99c6339c3fc3cb42737d492b035f38384dab (patch) | |
tree | 2bc00e80fc451dd6d0ea02c9010d098be74fd01e | |
parent | cf639f48f2e7be43ac47fda6d7dec765ed0893e4 (diff) | |
download | dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar.gz dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar.bz2 dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar.lz dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar.xz dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.tar.zst dexon-solidity-804e99c6339c3fc3cb42737d492b035f38384dab.zip |
Split out metadata test into its own file
-rw-r--r-- | test/libsolidity/Metadata.cpp | 60 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 20 |
2 files changed, 60 insertions, 20 deletions
diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp new file mode 100644 index 00000000..7f089a1d --- /dev/null +++ b/test/libsolidity/Metadata.cpp @@ -0,0 +1,60 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see <http://www.gnu.org/licenses/>. + */ +/** + * @date 2017 + * Unit tests for the metadata output. + */ + +#include "../TestHelper.h" +#include <libsolidity/interface/CompilerStack.h> +#include <libdevcore/SwarmHash.h> + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(Metadata) + +BOOST_AUTO_TEST_CASE(metadata_stamp) +{ + // Check that the metadata stamp is at the end of the runtime bytecode. + char const* sourceCode = R"( + pragma solidity >=0.0; + contract test { + function g(function(uint) external returns (uint) x) {} + } + )"; + CompilerStack compilerStack; + BOOST_REQUIRE(compilerStack.compile(std::string(sourceCode))); + bytes const& bytecode = compilerStack.runtimeObject("test").bytecode; + bytes hash = dev::swarmHash(compilerStack.onChainMetadata("test")).asBytes(); + BOOST_REQUIRE(hash.size() == 32); + BOOST_REQUIRE(bytecode.size() >= 2); + size_t metadataCBORSize = (size_t(bytecode.end()[-2]) << 8) + size_t(bytecode.end()[-1]); + BOOST_REQUIRE(metadataCBORSize < bytecode.size() - 2); + bytes expectation = bytes{0xa1, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} + hash; + BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), bytecode.end() - metadataCBORSize - 2)); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 1ebccc13..f87390e1 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -752,26 +752,6 @@ BOOST_AUTO_TEST_CASE(function_type) checkInterface(sourceCode, interface); } -BOOST_AUTO_TEST_CASE(metadata_stamp) -{ - // Check that the metadata stamp is at the end of the runtime bytecode. - char const* sourceCode = R"( - pragma solidity >=0.0; - contract test { - function g(function(uint) external returns (uint) x) {} - } - )"; - BOOST_REQUIRE(m_compilerStack.compile(std::string(sourceCode))); - bytes const& bytecode = m_compilerStack.runtimeObject("test").bytecode; - bytes hash = dev::swarmHash(m_compilerStack.onChainMetadata("test")).asBytes(); - BOOST_REQUIRE(hash.size() == 32); - BOOST_REQUIRE(bytecode.size() >= 2); - size_t metadataCBORSize = (size_t(bytecode.end()[-2]) << 8) + size_t(bytecode.end()[-1]); - BOOST_REQUIRE(metadataCBORSize < bytecode.size() - 2); - bytes expectation = bytes{0xa1, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} + hash; - BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), bytecode.end() - metadataCBORSize - 2)); -} - BOOST_AUTO_TEST_SUITE_END() } |