mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move bytecodeSansMetadata(bytes) helper to test/Metadata
This commit is contained in:
parent
be22032141
commit
26de5684a2
@ -31,6 +31,17 @@ namespace dev
|
|||||||
namespace test
|
namespace test
|
||||||
{
|
{
|
||||||
|
|
||||||
|
bytes bytecodeSansMetadata(bytes const& _bytecode)
|
||||||
|
{
|
||||||
|
unsigned size = _bytecode.size();
|
||||||
|
if (size < 5)
|
||||||
|
return bytes{};
|
||||||
|
size_t metadataSize = (_bytecode[size - 2] << 8) + _bytecode[size - 1];
|
||||||
|
if (metadataSize != 0x29 || size < (metadataSize + 2))
|
||||||
|
return bytes{};
|
||||||
|
return bytes(_bytecode.begin(), _bytecode.end() - metadataSize - 2);
|
||||||
|
}
|
||||||
|
|
||||||
string bytecodeSansMetadata(string const& _bytecode)
|
string bytecodeSansMetadata(string const& _bytecode)
|
||||||
{
|
{
|
||||||
/// The metadata hash takes up 43 bytes (or 86 characters in hex)
|
/// The metadata hash takes up 43 bytes (or 86 characters in hex)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
* Metadata processing helpers.
|
* Metadata processing helpers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <libdevcore/CommonData.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
@ -26,6 +27,9 @@ namespace dev
|
|||||||
namespace test
|
namespace test
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// Returns the bytecode with the metadata hash stripped out.
|
||||||
|
bytes bytecodeSansMetadata(bytes const& _bytecode);
|
||||||
|
|
||||||
/// Returns the bytecode with the metadata hash stripped out.
|
/// Returns the bytecode with the metadata hash stripped out.
|
||||||
std::string bytecodeSansMetadata(std::string const& _bytecode);
|
std::string bytecodeSansMetadata(std::string const& _bytecode);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* Tests for the Solidity optimizer.
|
* Tests for the Solidity optimizer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <test/Metadata.h>
|
||||||
#include <test/libsolidity/SolidityExecutionFramework.h>
|
#include <test/libsolidity/SolidityExecutionFramework.h>
|
||||||
|
|
||||||
#include <libevmasm/Instruction.h>
|
#include <libevmasm/Instruction.h>
|
||||||
@ -105,11 +106,8 @@ public:
|
|||||||
/// into account.
|
/// into account.
|
||||||
size_t numInstructions(bytes const& _bytecode, boost::optional<Instruction> _which = boost::optional<Instruction>{})
|
size_t numInstructions(bytes const& _bytecode, boost::optional<Instruction> _which = boost::optional<Instruction>{})
|
||||||
{
|
{
|
||||||
BOOST_REQUIRE(_bytecode.size() > 5);
|
bytes realCode = bytecodeSansMetadata(_bytecode);
|
||||||
size_t metadataSize = (_bytecode[_bytecode.size() - 2] << 8) + _bytecode[_bytecode.size() - 1];
|
BOOST_REQUIRE_MESSAGE(!realCode.empty(), "Invalid or missing metadata in bytecode.");
|
||||||
BOOST_REQUIRE_MESSAGE(metadataSize == 0x29, "Invalid metadata size");
|
|
||||||
BOOST_REQUIRE(_bytecode.size() >= metadataSize + 2);
|
|
||||||
bytes realCode = bytes(_bytecode.begin(), _bytecode.end() - metadataSize - 2);
|
|
||||||
size_t instructions = 0;
|
size_t instructions = 0;
|
||||||
solidity::eachInstruction(realCode, [&](Instruction _instr, u256 const&) {
|
solidity::eachInstruction(realCode, [&](Instruction _instr, u256 const&) {
|
||||||
if (!_which || *_which == _instr)
|
if (!_which || *_which == _instr)
|
||||||
|
Loading…
Reference in New Issue
Block a user