Update test/EVMHost.cpp

Co-authored-by: Daniel Kirchner <daniel@ekpyron.org>
This commit is contained in:
Bhargava Shastry 2021-03-10 13:49:19 +01:00
parent 8023fdb537
commit a30b071a5d
2 changed files with 24 additions and 34 deletions

View File

@ -257,12 +257,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
code = evmc::bytes(message.input_data, message.input_data + message.input_size); code = evmc::bytes(message.input_data, message.input_data + message.input_size);
} }
else if (message.kind == EVMC_DELEGATECALL) else if (message.kind == EVMC_DELEGATECALL || message.kind == EVMC_CALLCODE)
{
code = accounts[message.destination].code;
message.destination = m_currentAddress;
}
else if (message.kind == EVMC_CALLCODE)
{ {
code = accounts[message.destination].code; code = accounts[message.destination].code;
message.destination = m_currentAddress; message.destination = m_currentAddress;
@ -774,13 +769,6 @@ evmc::result EVMHost::resultWithGas(
return result; return result;
} }
void EVMHost::printStorageAt(evmc::address const& _addr, ostringstream& _os)
{
for (auto const& [slot, value]: get_address_storage(_addr))
if (get_storage(_addr, slot))
_os << convertFromEVMC(slot) << ": " << convertFromEVMC(value.value) << endl;
}
StorageMap const& EVMHost::get_address_storage(evmc::address const& _addr) StorageMap const& EVMHost::get_address_storage(evmc::address const& _addr)
{ {
assertThrow(account_exists(_addr), Exception, "Account does not exist."); assertThrow(account_exists(_addr), Exception, "Account does not exist.");
@ -790,7 +778,7 @@ StorageMap const& EVMHost::get_address_storage(evmc::address const& _addr)
string EVMHostPrinter::state() string EVMHostPrinter::state()
{ {
// Print state and execution trace. // Print state and execution trace.
if (host.account_exists(account)) if (m_host.account_exists(m_account))
{ {
storage(); storage();
balance(); balance();
@ -799,34 +787,34 @@ string EVMHostPrinter::state()
selfdestructRecords(); selfdestructRecords();
callRecords(); callRecords();
return stateStream.str(); return m_stateStream.str();
} }
void EVMHostPrinter::storage() void EVMHostPrinter::storage()
{ {
for (auto const& [slot, value]: host.get_address_storage(account)) for (auto const& [slot, value]: m_host.get_address_storage(m_account))
if (host.get_storage(account, slot)) if (m_host.get_storage(m_account, slot))
stateStream << host.convertFromEVMC(slot) m_stateStream << m_host.convertFromEVMC(slot)
<< ": " << ": "
<< host.convertFromEVMC(value.value) << m_host.convertFromEVMC(value.value)
<< endl; << endl;
} }
void EVMHostPrinter::balance() void EVMHostPrinter::balance()
{ {
stateStream << "BALANCE " m_stateStream << "BALANCE "
<< host.convertFromEVMC(host.get_balance(account)) << m_host.convertFromEVMC(m_host.get_balance(m_account))
<< endl; << endl;
} }
void EVMHostPrinter::selfdestructRecords() void EVMHostPrinter::selfdestructRecords()
{ {
for (auto const& record: host.recorded_selfdestructs) for (auto const& record: m_host.recorded_selfdestructs)
stateStream << "SELFDESTRUCT" m_stateStream << "SELFDESTRUCT"
<< " BENEFICIARY " << " BENEFICIARY "
<< host.convertFromEVMC(record.beneficiary) << m_host.convertFromEVMC(record.beneficiary)
<< " BALANCE " << " BALANCE "
<< host.convertFromEVMC(record.balance) << m_host.convertFromEVMC(record.balance)
<< endl; << endl;
} }
@ -851,9 +839,9 @@ void EVMHostPrinter::callRecords()
} }
}; };
for (auto const& record: host.recorded_calls) for (auto const& record: m_host.recorded_calls)
stateStream << callKind(record.kind) m_stateStream << callKind(record.kind)
<< " VALUE " << " VALUE "
<< host.convertFromEVMC(record.value) << m_host.convertFromEVMC(record.value)
<< endl; << endl;
} }

View File

@ -113,15 +113,17 @@ private:
evmc_revision m_evmRevision; evmc_revision m_evmRevision;
}; };
struct EVMHostPrinter class EVMHostPrinter
{ {
public:
/// Constructs a host printer object for state at @param _address. /// Constructs a host printer object for state at @param _address.
explicit EVMHostPrinter(EVMHost& _host, evmc::address _address): explicit EVMHostPrinter(EVMHost& _host, evmc::address _address):
host(_host), m_host(_host),
account(_address) m_account(_address)
{} {}
/// @returns state at account maintained by host. /// @returns state at account maintained by host.
std::string state(); std::string state();
private:
/// Outputs storage at account to stateStream. /// Outputs storage at account to stateStream.
void storage(); void storage();
/// Outputs call records for account to stateStream. /// Outputs call records for account to stateStream.
@ -131,9 +133,9 @@ struct EVMHostPrinter
/// Outputs self-destruct record for account to stateStream. /// Outputs self-destruct record for account to stateStream.
void selfdestructRecords(); void selfdestructRecords();
std::ostringstream stateStream; std::ostringstream m_stateStream;
EVMHost& host; EVMHost& m_host;
evmc::address account; evmc::address m_account;
}; };
} }