aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-27 17:07:15 +0800
committerGitHub <noreply@github.com>2017-07-27 17:07:15 +0800
commit1298a8df14bd3dd6495aa38413208fa77781d4fd (patch)
tree90fe3173fc7716789b47474cfb4053e4b90dd752 /test/libsolidity
parent16ca1eea78d476de3fd52ebdd9dcfb6fa5610aa6 (diff)
parent35feb6d47ce143c625187a95f54563fa456aa3f5 (diff)
downloaddexon-solidity-1298a8df14bd3dd6495aa38413208fa77781d4fd.tar.gz
dexon-solidity-1298a8df14bd3dd6495aa38413208fa77781d4fd.tar.zst
dexon-solidity-1298a8df14bd3dd6495aa38413208fa77781d4fd.zip
Merge pull request #2566 from ethereum/metadata-only-relevant
Metadata: only include relevant files in the source list
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/Metadata.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp
index e4820ad2..30de7908 100644
--- a/test/libsolidity/Metadata.cpp
+++ b/test/libsolidity/Metadata.cpp
@@ -58,6 +58,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()
}