Merge pull request #7818 from ethereum/evmc_vm

test: Use evmc::VM directly
This commit is contained in:
chriseth 2019-11-27 19:11:12 +01:00 committed by GitHub
commit 80978293ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 15 deletions

View File

@ -35,22 +35,19 @@ using namespace dev;
using namespace dev::test;
evmc::VM* EVMHost::getVM(string const& _path)
evmc::VM& EVMHost::getVM(string const& _path)
{
static unique_ptr<evmc::VM> theVM;
static evmc::VM theVM;
if (!theVM && !_path.empty())
{
evmc_loader_error_code errorCode = {};
evmc_vm* vm = evmc_load_and_configure(_path.c_str(), &errorCode);
auto vm = evmc::VM{evmc_load_and_configure(_path.c_str(), &errorCode)};
if (vm && errorCode == EVMC_LOADER_SUCCESS)
{
if (evmc_vm_has_capability(vm, EVMC_CAPABILITY_EVM1))
theVM = make_unique<evmc::VM>(vm);
if (vm.get_capabilities() & EVMC_CAPABILITY_EVM1)
theVM = std::move(vm);
else
{
evmc_destroy(vm);
cerr << "VM loaded does not support EVM1" << endl;
}
}
else
{
@ -60,10 +57,10 @@ evmc::VM* EVMHost::getVM(string const& _path)
cerr << endl;
}
}
return theVM.get();
return theVM;
}
EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm):
EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
m_vm(_vm),
m_evmVersion(_evmVersion)
{
@ -192,7 +189,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
evmc::address currentAddress = m_currentAddress;
m_currentAddress = message.destination;
evmc::result result = m_vm->execute(*this, m_evmRevision, message, code.data(), code.size());
evmc::result result = m_vm.execute(*this, m_evmRevision, message, code.data(), code.size());
m_currentAddress = currentAddress;
if (message.kind == EVMC_CREATE)

View File

@ -40,9 +40,9 @@ public:
/// 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 = {});
static evmc::VM& getVM(std::string const& _path = {});
explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm = getVM());
explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm = getVM());
struct Account
{
@ -179,7 +179,7 @@ private:
/// @note The return value is only valid as long as @a _data is alive!
static evmc::result resultWithGas(evmc_message const& _message, bytes const& _data) noexcept;
evmc::VM* m_vm = nullptr;
evmc::VM& m_vm;
// EVM version requested by the testing tool
langutil::EVMVersion m_evmVersion;
// EVM version requested from EVMC (matches the above)

View File

@ -142,7 +142,7 @@ DEFINE_PROTO_FUZZER(Contract const& _input)
// We target the default EVM which is the latest
langutil::EVMVersion version = {};
EVMHost hostContext(version, &evmone);
EVMHost hostContext(version, evmone);
// Deploy contract and signal failure if deploy failed
evmc::result createResult = deployContract(hostContext, byteCode);