Remove duplicated code in test/Metadata

This commit is contained in:
Alex Beregszaszi 2019-02-05 22:53:25 +00:00
parent 26de5684a2
commit 43ccc75293
2 changed files with 2 additions and 13 deletions

View File

@ -44,19 +44,7 @@ bytes bytecodeSansMetadata(bytes const& _bytecode)
string bytecodeSansMetadata(string const& _bytecode) string bytecodeSansMetadata(string const& _bytecode)
{ {
/// The metadata hash takes up 43 bytes (or 86 characters in hex) return toHex(bytecodeSansMetadata(fromHex(_bytecode, WhenError::Throw)));
/// /a165627a7a72305820([0-9a-f]{64})0029$/
if (_bytecode.size() < 88)
return _bytecode;
if (_bytecode.substr(_bytecode.size() - 4, 4) != "0029")
return _bytecode;
if (_bytecode.substr(_bytecode.size() - 86, 18) != "a165627a7a72305820")
return _bytecode;
return _bytecode.substr(0, _bytecode.size() - 86);
} }
bool isValidMetadata(string const& _metadata) bool isValidMetadata(string const& _metadata)

View File

@ -31,6 +31,7 @@ namespace test
bytes bytecodeSansMetadata(bytes const& _bytecode); bytes bytecodeSansMetadata(bytes const& _bytecode);
/// Returns the bytecode with the metadata hash stripped out. /// Returns the bytecode with the metadata hash stripped out.
/// Throws exception on invalid hex string.
std::string bytecodeSansMetadata(std::string const& _bytecode); std::string bytecodeSansMetadata(std::string const& _bytecode);
/// Expects a serialised metadata JSON and returns true if the /// Expects a serialised metadata JSON and returns true if the