Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp: Add VM::has_capability() method #465

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
10 changes: 10 additions & 0 deletions test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
chfast marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down