diff --git a/test/Metadata.cpp b/test/Metadata.cpp index bdbf427e9e66..974a1df69ef9 100644 --- a/test/Metadata.cpp +++ b/test/Metadata.cpp @@ -61,6 +61,16 @@ string bytecodeSansMetadata(string const& _bytecode) return toHex(bytecodeSansMetadata(fromHex(_bytecode, WhenError::Throw))); } +string byteCodeSansAnyMetadata(string const& _bytecode) +{ + std::string bin = bytecodeSansMetadata(_bytecode); + while (onlyMetadata(fromHex(bin, WhenError::Throw)).size() > 0) + { + bin = bytecodeSansMetadata(bin); + } + return bin; +} + DEV_SIMPLE_EXCEPTION(CBORException); class TinyCBORParser diff --git a/test/Metadata.h b/test/Metadata.h index 4c7a10b31205..d8ebbf40ae58 100644 --- a/test/Metadata.h +++ b/test/Metadata.h @@ -41,6 +41,10 @@ bytes bytecodeSansMetadata(bytes const& _bytecode); /// Throws exception on invalid hex string. std::string bytecodeSansMetadata(std::string const& _bytecode); +/// Returns the bytecode with all metadata hashes (imported contracts too) stripped out. +/// Throws exception on invalid hex string. +std::string bytecodeSansAnyMetadata(std::string const& _bytecode); + /// Parse CBOR metadata into a map. Expects the input CBOR to be a /// fixed length map, with each key being a string. The values /// are parsed as follows: diff --git a/test/libsolidity/ASTImportTest.cpp b/test/libsolidity/ASTImportTest.cpp index d6c4937f2429..c33ba8604d1c 100644 --- a/test/libsolidity/ASTImportTest.cpp +++ b/test/libsolidity/ASTImportTest.cpp @@ -77,18 +77,15 @@ ASTImportTest::ASTImportTest(string const& _filename) } // save entire Json from input as string in m_expectations - // TODO but modify the metadata to not includes the hash of the solidity-source code // TODO2: byteCodeSansMetadata might need to be modified to remove metadata of imported contracts too if ( (*ast).isMember("contracts") ) { for (auto& srcName: (*ast)["contracts"].getMemberNames()) { - // why is this not importing correctly? HELP namesspace issues? -// string bin = (*ast)["contracts"][srcName]["bin"].asString(); -// string binSansMetadata = dev::test::bytecodeSansMetadata(bin); - // dummy - string binSansMetadata = "0x00"; + string binSansMetadata = dev::test::bytecodeSansAnyMetadata((*ast)["contracts"][srcName]["bin"].asString()); (*ast)["contracts"][srcName]["bin"] = binSansMetadata; +// (*ast)["contracts"][srcName]["bin"] = dev::test::bytecodeSansMetadata(binSansMetadata); + } } m_expectation = dev::jsonPrettyPrint(*ast); @@ -147,8 +144,9 @@ TestCase::TestResult ASTImportTest::run(ostream& _stream, string const& _linePre for (string const& contractName: contracts) { Json::Value& contractData = output["contracts"][contractName] = Json::objectValue; - string binSansMetadata = "0x00";// dev::test::bytecodeSansMetadata(c.object(contractName).toHex()); // TODO see above - contractData["bin"] = binSansMetadata; + string binSansMetadata = dev::test::bytecodeSansAnyMetadata(c.object(contractName).toHex()); + contractData["bin"] = binSansMetadata ; +// contractData["bin"] = dev::test::bytecodeSansMetadata(binSansMetadata); } } output["sources"] = Json::Value(Json::objectValue); diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt index 08596c88504f..7e5e77d85eb4 100644 --- a/test/tools/CMakeLists.txt +++ b/test/tools/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(isoltest ../Options.cpp ../Common.cpp ../TestCase.cpp + ../Metadata.cpp ../libsolidity/util/BytesUtils.cpp ../libsolidity/util/ContractABIUtils.cpp ../libsolidity/util/TestFileParser.cpp