From c4012eee3398aac753ca6d27332a57a77074393b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 29 Nov 2019 15:08:53 +0100 Subject: [PATCH] Update EVMHost to EVMC 7.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paweł Bylica --- test/EVMHost.cpp | 4 ++-- test/EVMHost.h | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 779e9e000..32ba0cc4a 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -229,7 +229,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept return result; } -evmc_tx_context EVMHost::get_tx_context() noexcept +evmc_tx_context EVMHost::get_tx_context() const noexcept { evmc_tx_context ctx = {}; ctx.block_timestamp = m_state.timestamp; @@ -245,7 +245,7 @@ evmc_tx_context EVMHost::get_tx_context() noexcept return ctx; } -evmc::bytes32 EVMHost::get_block_hash(int64_t _number) noexcept +evmc::bytes32 EVMHost::get_block_hash(int64_t _number) const noexcept { return convertToEVMC(u256("0x3737373737373737373737373737373737373737373737373737373737373737") + _number); } diff --git a/test/EVMHost.h b/test/EVMHost.h index 4cbb045f0..0cfedacec 100644 --- a/test/EVMHost.h +++ b/test/EVMHost.h @@ -68,6 +68,12 @@ public: std::vector logs; }; + Account const* account(evmc::address const& _address) const + { + auto it = m_state.accounts.find(_address); + return it == m_state.accounts.end() ? nullptr : &it->second; + } + Account* account(evmc::address const& _address) { auto it = m_state.accounts.find(_address); @@ -82,15 +88,19 @@ public: m_state.logs.clear(); } - bool account_exists(evmc::address const& _addr) noexcept final + bool account_exists(evmc::address const& _addr) const noexcept final { return account(_addr) != nullptr; } - evmc::bytes32 get_storage(evmc::address const& _addr, evmc::bytes32 const& _key) noexcept final + evmc::bytes32 get_storage(evmc::address const& _addr, evmc::bytes32 const& _key) const noexcept final { - if (Account* acc = account(_addr)) - return acc->storage[_key]; + if (auto* acc = account(_addr)) + { + auto it = acc->storage.find(_key); + if (it != acc->storage.end()) + return it->second; + } return {}; } @@ -100,21 +110,21 @@ public: evmc::bytes32 const& _value ) noexcept; - evmc::uint256be get_balance(evmc::address const& _addr) noexcept final + evmc::uint256be get_balance(evmc::address const& _addr) const noexcept final { if (Account const* acc = account(_addr)) return acc->balance; return {}; } - size_t get_code_size(evmc::address const& _addr) noexcept final + size_t get_code_size(evmc::address const& _addr) const noexcept final { if (Account const* acc = account(_addr)) return acc->code.size(); return 0; } - evmc::bytes32 get_code_hash(evmc::address const& _addr) noexcept final + evmc::bytes32 get_code_hash(evmc::address const& _addr) const noexcept final { if (Account const* acc = account(_addr)) return acc->codeHash; @@ -126,7 +136,7 @@ public: size_t _codeOffset, uint8_t* _bufferData, size_t _bufferSize - ) noexcept final + ) const noexcept final { size_t i = 0; if (Account const* acc = account(_addr)) @@ -139,9 +149,9 @@ public: evmc::result call(evmc_message const& _message) noexcept; - evmc_tx_context get_tx_context() noexcept; + evmc_tx_context get_tx_context() const noexcept; - evmc::bytes32 get_block_hash(int64_t number) noexcept; + evmc::bytes32 get_block_hash(int64_t number) const noexcept; void emit_log( evmc::address const& _addr,