Skip to content

Commit

Permalink
cpp: Add VM::has_capability() method
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 27, 2019
1 parent ca74d19 commit 1c5b65d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<evmc_capabilities_flagset>(capability)) != 0;
}

/// @copydoc evmc::vm::get_capabilities
evmc_capabilities_flagset get_capabilities() const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1c5b65d

Please sign in to comment.