mirror of
https://github.com/status-im/evmc.git
synced 2025-02-23 16:38:06 +00:00
test: Add C++ API test executing Precompiles VM
This commit is contained in:
parent
3f6ea7ac7d
commit
310dc8e438
@ -17,7 +17,16 @@ add_executable(
|
||||
test_loader.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(evmc-unittests PRIVATE loader-mocked evmc::example-vm-static evmc-example-host instructions GTest::gtest_main)
|
||||
target_link_libraries(
|
||||
evmc-unittests
|
||||
PRIVATE
|
||||
loader-mocked
|
||||
evmc::example-vm-static
|
||||
evmc::example-precompiles-vm
|
||||
evmc-example-host
|
||||
instructions
|
||||
GTest::gtest_main
|
||||
)
|
||||
set_target_properties(evmc-unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
|
||||
|
||||
gtest_add_tests(TARGET evmc-unittests TEST_PREFIX ${PROJECT_NAME}/unittests/)
|
||||
|
@ -7,17 +7,18 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../../examples/example_host.h"
|
||||
#include "../../examples/example_precompiles_vm/example_precompiles_vm.h"
|
||||
#include "../../examples/example_vm/example_vm.h"
|
||||
|
||||
#include <evmc/evmc.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
TEST(cpp, address)
|
||||
{
|
||||
evmc::address a;
|
||||
@ -344,6 +345,27 @@ TEST(cpp, vm_move)
|
||||
EXPECT_EQ(destroy_counter, 5);
|
||||
}
|
||||
|
||||
TEST(cpp, vm_execute_precompiles)
|
||||
{
|
||||
auto vm = evmc::VM{evmc_create_example_precompiles_vm()};
|
||||
EXPECT_EQ(vm.get_capabilities(), evmc_capabilities_flagset{EVMC_CAPABILITY_PRECOMPILES});
|
||||
|
||||
constexpr std::array<uint8_t, 3> input{{1, 2, 3}};
|
||||
|
||||
evmc_message msg{};
|
||||
msg.destination.bytes[19] = 4; // Call Identify precompile at address 0x4.
|
||||
msg.input_data = input.data();
|
||||
msg.input_size = input.size();
|
||||
msg.gas = 18;
|
||||
|
||||
constexpr evmc_host_interface null_interface{};
|
||||
auto res = vm.execute(null_interface, nullptr, EVMC_MAX_REVISION, msg, nullptr, 0);
|
||||
EXPECT_EQ(res.status_code, EVMC_SUCCESS);
|
||||
EXPECT_EQ(res.gas_left, 0);
|
||||
ASSERT_EQ(res.output_size, input.size());
|
||||
EXPECT_TRUE(std::equal(input.begin(), input.end(), res.output_data));
|
||||
}
|
||||
|
||||
TEST(cpp, host)
|
||||
{
|
||||
// Use example host to execute all methods from the C++ host wrapper.
|
||||
|
Loading…
x
Reference in New Issue
Block a user