From 35feb6d47ce143c625187a95f54563fa456aa3f5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 18 Jul 2017 19:28:58 +0100 Subject: Add tests for relevant metadata files --- test/libsolidity/Metadata.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index ce1a7b18..271c1751 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -57,6 +57,73 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), bytecode.end() - metadataCBORSize - 2)); } +BOOST_AUTO_TEST_CASE(metadata_relevant_sources) +{ + CompilerStack compilerStack; + char const* sourceCode = R"( + pragma solidity >=0.0; + contract A { + function g(function(uint) external returns (uint) x) {} + } + )"; + compilerStack.addSource("A", std::string(sourceCode)); + sourceCode = R"( + pragma solidity >=0.0; + contract B { + function g(function(uint) external returns (uint) x) {} + } + )"; + compilerStack.addSource("B", std::string(sourceCode)); + ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(dev::test::Options::get().optimize), "Compiling contract failed"); + + std::string const& serialisedMetadata = compilerStack.metadata("A"); + BOOST_CHECK(dev::test::isValidMetadata(serialisedMetadata)); + Json::Value metadata; + BOOST_REQUIRE(Json::Reader().parse(serialisedMetadata, metadata, false)); + + BOOST_CHECK_EQUAL(metadata["sources"].size(), 1); + BOOST_CHECK(metadata["sources"].isMember("A")); +} + +BOOST_AUTO_TEST_CASE(metadata_relevant_sources_imports) +{ + CompilerStack compilerStack; + char const* sourceCode = R"( + pragma solidity >=0.0; + contract A { + function g(function(uint) external returns (uint) x) {} + } + )"; + compilerStack.addSource("A", std::string(sourceCode)); + sourceCode = R"( + pragma solidity >=0.0; + import "./A"; + contract B is A { + function g(function(uint) external returns (uint) x) {} + } + )"; + compilerStack.addSource("B", std::string(sourceCode)); + sourceCode = R"( + pragma solidity >=0.0; + import "./B"; + contract C is B { + function g(function(uint) external returns (uint) x) {} + } + )"; + compilerStack.addSource("C", std::string(sourceCode)); + ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(dev::test::Options::get().optimize), "Compiling contract failed"); + + std::string const& serialisedMetadata = compilerStack.metadata("C"); + BOOST_CHECK(dev::test::isValidMetadata(serialisedMetadata)); + Json::Value metadata; + BOOST_REQUIRE(Json::Reader().parse(serialisedMetadata, metadata, false)); + + BOOST_CHECK_EQUAL(metadata["sources"].size(), 3); + BOOST_CHECK(metadata["sources"].isMember("A")); + BOOST_CHECK(metadata["sources"].isMember("B")); + BOOST_CHECK(metadata["sources"].isMember("C")); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit