From cdcfea73ab540c75e80eda18121069d475788629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Sat, 30 Nov 2019 00:10:41 +0100 Subject: [PATCH] EVMHost: Remove unneeded methods --- test/EVMHost.cpp | 17 --------- test/EVMHost.h | 69 +++---------------------------------- test/ExecutionFramework.cpp | 5 +-- 3 files changed, 7 insertions(+), 84 deletions(-) diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 1cfe840c2..9ea472eae 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -111,23 +111,6 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm): tx_context.chain_id = convertToEVMC(u256(1)); } -evmc_storage_status EVMHost::set_storage(const evmc::address& _addr, const evmc::bytes32& _key, const evmc::bytes32& _value) noexcept -{ - evmc::bytes32 previousValue = accounts[_addr].storage[_key].value; - accounts[_addr].storage[_key].value = _value; - - // TODO EVMC_STORAGE_MODIFIED_AGAIN should be also used - if (previousValue == _value) - return EVMC_STORAGE_UNCHANGED; - else if (previousValue == evmc::bytes32{}) - return EVMC_STORAGE_ADDED; - else if (_value == evmc::bytes32{}) - return EVMC_STORAGE_DELETED; - else - return EVMC_STORAGE_MODIFIED; - -} - void EVMHost::selfdestruct(const evmc::address& _addr, const evmc::address& _beneficiary) noexcept { // TODO actual selfdestruct is even more complicated. diff --git a/test/EVMHost.h b/test/EVMHost.h index 7aa1e20b5..c3f69960c 100644 --- a/test/EVMHost.h +++ b/test/EVMHost.h @@ -38,6 +38,9 @@ using Address = h160; class EVMHost: public evmc::MockedHost { public: + using MockedHost::get_code_size; + using MockedHost::get_balance; + /// Tries to dynamically load libevmone. @returns nullptr on failure. /// The path has to be provided for the first successful run and will be ignored /// afterwards. @@ -45,18 +48,6 @@ public: explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm = getVM()); - evmc::MockedAccount const* account(evmc::address const& _address) const - { - auto it = accounts.find(_address); - return it == accounts.end() ? nullptr : &it->second; - } - - evmc::MockedAccount* account(evmc::address const& _address) - { - auto it = accounts.find(_address); - return it == accounts.end() ? nullptr : &it->second; - } - void reset() { accounts.clear(); m_currentAddress = {}; } void newBlock() { @@ -67,59 +58,7 @@ public: 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) const noexcept final - { - if (auto* acc = account(_addr)) - { - auto it = acc->storage.find(_key); - if (it != acc->storage.end()) - return it->second.value; - } - return {}; - } - - evmc_storage_status set_storage( - evmc::address const& _addr, - evmc::bytes32 const& _key, - evmc::bytes32 const& _value - ) noexcept final; - - evmc::uint256be get_balance(evmc::address const& _addr) const noexcept final - { - if (auto const* acc = account(_addr)) - return acc->balance; - return {}; - } - - size_t get_code_size(evmc::address const& _addr) const noexcept final - { - if (auto const* acc = account(_addr)) - return acc->code.size(); - return 0; - } - - evmc::bytes32 get_code_hash(evmc::address const& _addr) const noexcept final - { - if (auto const* acc = account(_addr)) - return acc->codehash; - return {}; - } - - size_t copy_code( - evmc::address const& _addr, - size_t _codeOffset, - uint8_t* _bufferData, - size_t _bufferSize - ) const noexcept final - { - size_t i = 0; - if (auto const* acc = account(_addr)) - for (; i < _bufferSize && _codeOffset + i < acc->code.size(); i++) - _bufferData[i] = acc->code[_codeOffset + i]; - return i; + return evmc::MockedHost::account_exists(_addr); } void selfdestruct(evmc::address const& _addr, evmc::address const& _beneficiary) noexcept final; diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index df9c7e9df..4f5c8badd 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -233,9 +233,10 @@ u256 ExecutionFramework::balanceAt(Address const& _addr) bool ExecutionFramework::storageEmpty(Address const& _addr) { - if (auto const* acc = m_evmHost->account(EVMHost::convertToEVMC(_addr))) + const auto it = m_evmHost->accounts.find(EVMHost::convertToEVMC(_addr)); + if (it != m_evmHost->accounts.end()) { - for (auto const& entry: acc->storage) + for (auto const& entry: it->second.storage) if (!(entry.second.value == evmc::bytes32{})) return false; }