diff --git a/CHANGELOG.md b/CHANGELOG.md index aee78ebdc..b16b1cbfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,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 2c7597fd6..0b44cd12c 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 396ecfb7b..5f1cd26df 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -314,8 +314,18 @@ TEST(cpp, vm) const auto host = evmc_host_interface{}; auto res = vm.execute(host, nullptr, EVMC_MAX_REVISION, {}, nullptr, 0); 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_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)