diff --git a/CHANGELOG.md b/CHANGELOG.md index c4df0b324..5a462f9da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ removed. the Host context and interface parameters. This is useful for Precompiles VMs that do not interact with the Host. [#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 diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 7acfd1ae5..ebe9677ec 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -570,6 +570,12 @@ class VM /// @copydoc evmc_vm::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(capability)) != 0; + } + /// @copydoc evmc::vm::get_capabilities evmc_capabilities_flagset get_capabilities() const noexcept { diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index 0ed28cc8b..4b4e3c504 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -313,6 +313,8 @@ TEST(cpp, vm) EXPECT_EQ(res.status_code, EVMC_FAILURE); EXPECT_TRUE(vm.get_capabilities() & EVMC_CAPABILITY_EVM1); + EXPECT_TRUE(vm.has_capability(EVMC_CAPABILITY_EVM1)); + EXPECT_FALSE(vm.has_capability(EVMC_CAPABILITY_EWASM)); } TEST(cpp, vm_set_option)