mirror of https://github.com/status-im/evmc.git
cpp: Add VM::has_capability() method
This commit is contained in:
parent
95c01b648b
commit
236aa76c8d
|
@ -41,6 +41,8 @@ removed.
|
||||||
the Host context and interface parameters. This is useful for Precompiles VMs
|
the Host context and interface parameters. This is useful for Precompiles VMs
|
||||||
that do not interact with the Host.
|
that do not interact with the Host.
|
||||||
[#302](https://github.com/ethereum/evmc/pull/302)
|
[#302](https://github.com/ethereum/evmc/pull/302)
|
||||||
|
- In C++ API, the `VM::has_capability()` method has been added.
|
||||||
|
[#465](https://github.com/ethereum/evmc/pull/465)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -570,6 +570,12 @@ public:
|
||||||
/// @copydoc evmc_vm::version
|
/// @copydoc evmc_vm::version
|
||||||
char const* version() const noexcept { return m_instance->version; }
|
char const* version() const noexcept { return m_instance->version; }
|
||||||
|
|
||||||
|
/// Checks if the VM has the given capability.
|
||||||
|
bool has_capability(evmc_capabilities capability) const noexcept
|
||||||
|
{
|
||||||
|
return (get_capabilities() & static_cast<evmc_capabilities_flagset>(capability)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// @copydoc evmc::vm::get_capabilities
|
/// @copydoc evmc::vm::get_capabilities
|
||||||
evmc_capabilities_flagset get_capabilities() const noexcept
|
evmc_capabilities_flagset get_capabilities() const noexcept
|
||||||
{
|
{
|
||||||
|
|
|
@ -314,8 +314,18 @@ TEST(cpp, vm)
|
||||||
const auto host = evmc_host_interface{};
|
const auto host = evmc_host_interface{};
|
||||||
auto res = vm.execute(host, nullptr, EVMC_MAX_REVISION, {}, nullptr, 0);
|
auto res = vm.execute(host, nullptr, EVMC_MAX_REVISION, {}, nullptr, 0);
|
||||||
EXPECT_EQ(res.status_code, EVMC_FAILURE);
|
EXPECT_EQ(res.status_code, EVMC_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(cpp, vm_capabilities)
|
||||||
|
{
|
||||||
|
const auto vm = evmc::VM{evmc_create_example_vm()};
|
||||||
|
|
||||||
EXPECT_TRUE(vm.get_capabilities() & EVMC_CAPABILITY_EVM1);
|
EXPECT_TRUE(vm.get_capabilities() & EVMC_CAPABILITY_EVM1);
|
||||||
|
EXPECT_TRUE(vm.get_capabilities() & EVMC_CAPABILITY_EWASM);
|
||||||
|
EXPECT_FALSE(vm.get_capabilities() & EVMC_CAPABILITY_PRECOMPILES);
|
||||||
|
EXPECT_TRUE(vm.has_capability(EVMC_CAPABILITY_EVM1));
|
||||||
|
EXPECT_TRUE(vm.has_capability(EVMC_CAPABILITY_EWASM));
|
||||||
|
EXPECT_FALSE(vm.has_capability(EVMC_CAPABILITY_PRECOMPILES));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(cpp, vm_set_option)
|
TEST(cpp, vm_set_option)
|
||||||
|
|
Loading…
Reference in New Issue