Skip to content

Commit

Permalink
test: Fix MSVC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 5, 2019
1 parent 746e40c commit 6ebaf52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
23 changes: 22 additions & 1 deletion test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -344,6 +345,26 @@ TEST(cpp, vm_move)
EXPECT_EQ(destroy_counter, 5);
}

TEST(cpp, vm_execute_without_host)
{
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;

auto res = vm.execute(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.
Expand Down

0 comments on commit 6ebaf52

Please sign in to comment.