cpp: Add VM::has_capability() method

This commit is contained in:
Paweł Bylica 2019-11-27 17:51:06 +01:00
parent 95c01b648b
commit 236aa76c8d
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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
{ {

View File

@ -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)