Skip to content

Commit

Permalink
EVMHost: Remove unneeded methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast authored and axic committed Dec 2, 2019
1 parent 0bd80ed commit cdcfea7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 84 deletions.
17 changes: 0 additions & 17 deletions test/EVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
69 changes: 4 additions & 65 deletions test/EVMHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,16 @@ 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.
static evmc::VM& getVM(std::string const& _path = {});

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()
{
Expand All @@ -67,59 +58,7 @@ class EVMHost: public evmc::MockedHost

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;
Expand Down
5 changes: 3 additions & 2 deletions test/ExecutionFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cdcfea7

Please sign in to comment.