mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
test: Use evmc::VM directly
The evmc::VM works as a RAII wrapper similarly to unique_ptr, so there is no point in using additional unique_ptr.
This commit is contained in:
parent
87943bf444
commit
38a20190f4
@ -35,22 +35,19 @@ using namespace dev;
|
|||||||
using namespace dev::test;
|
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())
|
if (!theVM && !_path.empty())
|
||||||
{
|
{
|
||||||
evmc_loader_error_code errorCode = {};
|
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 (vm && errorCode == EVMC_LOADER_SUCCESS)
|
||||||
{
|
{
|
||||||
if (evmc_vm_has_capability(vm, EVMC_CAPABILITY_EVM1))
|
if (vm.get_capabilities() & EVMC_CAPABILITY_EVM1)
|
||||||
theVM = make_unique<evmc::VM>(vm);
|
theVM = std::move(vm);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
evmc_destroy(vm);
|
|
||||||
cerr << "VM loaded does not support EVM1" << endl;
|
cerr << "VM loaded does not support EVM1" << endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -60,10 +57,10 @@ evmc::VM* EVMHost::getVM(string const& _path)
|
|||||||
cerr << endl;
|
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_vm(_vm),
|
||||||
m_evmVersion(_evmVersion)
|
m_evmVersion(_evmVersion)
|
||||||
{
|
{
|
||||||
@ -192,7 +189,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
|
|||||||
|
|
||||||
evmc::address currentAddress = m_currentAddress;
|
evmc::address currentAddress = m_currentAddress;
|
||||||
m_currentAddress = message.destination;
|
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;
|
m_currentAddress = currentAddress;
|
||||||
|
|
||||||
if (message.kind == EVMC_CREATE)
|
if (message.kind == EVMC_CREATE)
|
||||||
|
@ -40,9 +40,9 @@ public:
|
|||||||
/// Tries to dynamically load libevmone. @returns nullptr on failure.
|
/// Tries to dynamically load libevmone. @returns nullptr on failure.
|
||||||
/// The path has to be provided for the first successful run and will be ignored
|
/// The path has to be provided for the first successful run and will be ignored
|
||||||
/// afterwards.
|
/// 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
|
struct Account
|
||||||
{
|
{
|
||||||
@ -179,7 +179,7 @@ private:
|
|||||||
/// @note The return value is only valid as long as @a _data is alive!
|
/// @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;
|
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
|
// EVM version requested by the testing tool
|
||||||
langutil::EVMVersion m_evmVersion;
|
langutil::EVMVersion m_evmVersion;
|
||||||
// EVM version requested from EVMC (matches the above)
|
// EVM version requested from EVMC (matches the above)
|
||||||
|
@ -142,7 +142,7 @@ DEFINE_PROTO_FUZZER(Contract const& _input)
|
|||||||
|
|
||||||
// We target the default EVM which is the latest
|
// We target the default EVM which is the latest
|
||||||
langutil::EVMVersion version = {};
|
langutil::EVMVersion version = {};
|
||||||
EVMHost hostContext(version, &evmone);
|
EVMHost hostContext(version, evmone);
|
||||||
|
|
||||||
// Deploy contract and signal failure if deploy failed
|
// Deploy contract and signal failure if deploy failed
|
||||||
evmc::result createResult = deployContract(hostContext, byteCode);
|
evmc::result createResult = deployContract(hostContext, byteCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user