Skip to content

Commit

Permalink
bytecodeComparison
Browse files Browse the repository at this point in the history
  • Loading branch information
djudjuu committed Jul 31, 2019
1 parent 01780c4 commit e216427
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions test/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions test/libsolidity/ASTImportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e216427

Please sign in to comment.