aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/Metadata.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-19 02:28:58 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-19 21:57:12 +0800
commit35feb6d47ce143c625187a95f54563fa456aa3f5 (patch)
treea4776bdbe0d90d94026da283fb039ae4e160e84c /test/libsolidity/Metadata.cpp
parentf3e591eedd19b181e71682c8dd5d032b52cdced8 (diff)
downloaddexon-solidity-35feb6d47ce143c625187a95f54563fa456aa3f5.tar.gz
dexon-solidity-35feb6d47ce143c625187a95f54563fa456aa3f5.tar.zst
dexon-solidity-35feb6d47ce143c625187a95f54563fa456aa3f5.zip
Add tests for relevant metadata files
Diffstat (limited to 'test/libsolidity/Metadata.cpp')
-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 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()
}