Skip to content

Commit

Permalink
Merge pull request #606 from ethereum/cleanups
Browse files Browse the repository at this point in the history
Small clean-ups
  • Loading branch information
chfast committed Jun 29, 2021
2 parents 1a5a7f8 + 7180f39 commit 6b05379
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
3 changes: 3 additions & 0 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <ostream>
#include <utility>

static_assert(EVMC_LATEST_STABLE_REVISION <= EVMC_MAX_REVISION,
"latest stable revision ill-defined");

/// EVMC C++ API - wrappers and bindings for C++
/// @ingroup cpp
namespace evmc
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

add_library(evmc INTERFACE)
add_library(evmc::evmc ALIAS evmc)
target_compile_features(evmc INTERFACE c_std_99)
target_include_directories(evmc INTERFACE $<BUILD_INTERFACE:${EVMC_INCLUDE_DIR}>$<INSTALL_INTERFACE:include>)

add_library(evmc_cpp INTERFACE)
Expand Down
34 changes: 17 additions & 17 deletions test/unittests/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ TEST(cpp, std_hash)

using namespace evmc::literals;

static_assert(std::hash<evmc::address>{}({}) == static_cast<size_t>(0xd94d12186c0f2fb7), "");
static_assert(std::hash<evmc::bytes32>{}({}) == static_cast<size_t>(0x4d25767f9dce13f5), "");
static_assert(std::hash<evmc::address>{}({}) == static_cast<size_t>(0xd94d12186c0f2fb7));
static_assert(std::hash<evmc::bytes32>{}({}) == static_cast<size_t>(0x4d25767f9dce13f5));

EXPECT_EQ(std::hash<evmc::address>{}({}), static_cast<size_t>(0xd94d12186c0f2fb7));
EXPECT_EQ(std::hash<evmc::bytes32>{}({}), static_cast<size_t>(0x4d25767f9dce13f5));
Expand Down Expand Up @@ -341,15 +341,15 @@ TEST(cpp, literals)
constexpr auto zero_address = 0_address;
constexpr auto zero_hash = 0_bytes32;

static_assert(address1.bytes[0] == 0xa0, "");
static_assert(address1.bytes[9] == 0xa9, "");
static_assert(address1.bytes[10] == 0xd0, "");
static_assert(address1.bytes[19] == 0xd9, "");
static_assert(hash1.bytes[0] == 0x01, "");
static_assert(hash1.bytes[10] == 0xa1, "");
static_assert(hash1.bytes[31] == 0xd2, "");
static_assert(zero_address == evmc::address{}, "");
static_assert(zero_hash == evmc::bytes32{}, "");
static_assert(address1.bytes[0] == 0xa0);
static_assert(address1.bytes[9] == 0xa9);
static_assert(address1.bytes[10] == 0xd0);
static_assert(address1.bytes[19] == 0xd9);
static_assert(hash1.bytes[0] == 0x01);
static_assert(hash1.bytes[10] == 0xa1);
static_assert(hash1.bytes[31] == 0xd2);
static_assert(zero_address == evmc::address{});
static_assert(zero_hash == evmc::bytes32{});

EXPECT_EQ(0_address, evmc::address{});
EXPECT_EQ(0_bytes32, evmc::bytes32{});
Expand All @@ -371,9 +371,9 @@ TEST(cpp, bytes32_from_uint)
using evmc::bytes32;
using evmc::operator""_bytes32;

static_assert(bytes32{0} == bytes32{}, "");
static_assert(bytes32{3}.bytes[31] == 3, "");
static_assert(bytes32{0xfe00000000000000}.bytes[24] == 0xfe, "");
static_assert(bytes32{0} == bytes32{});
static_assert(bytes32{3}.bytes[31] == 3);
static_assert(bytes32{0xfe00000000000000}.bytes[24] == 0xfe);

EXPECT_EQ(bytes32{0}, bytes32{});
EXPECT_EQ(bytes32{0x01},
Expand All @@ -393,9 +393,9 @@ TEST(cpp, address_from_uint)
using evmc::address;
using evmc::operator""_address;

static_assert(address{0} == address{}, "");
static_assert(address{3}.bytes[19] == 3, "");
static_assert(address{0xfe00000000000000}.bytes[12] == 0xfe, "");
static_assert(address{0} == address{});
static_assert(address{3}.bytes[19] == 3);
static_assert(address{0xfe00000000000000}.bytes[12] == 0xfe);

EXPECT_EQ(address{0}, address{});
EXPECT_EQ(address{0x01}, 0x0000000000000000000000000000000000000001_address);
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class loader : public ::testing::Test
static evmc_vm* create_vm_with_wrong_abi()
{
constexpr auto wrong_abi_version = 1985;
static_assert(wrong_abi_version != EVMC_ABI_VERSION, "");
static_assert(wrong_abi_version != EVMC_ABI_VERSION);
static auto instance =
evmc_vm{wrong_abi_version, "", "", destroy, nullptr, nullptr, nullptr};
++create_count;
Expand Down Expand Up @@ -137,9 +137,9 @@ TEST_F(loader, strcpy_sx)
const char input_that_fits[] = "x";
const char input_too_big[] = "12";
char buf[2] = {0x0f, 0x0f};
static_assert(sizeof(input_empty) <= sizeof(buf), "");
static_assert(sizeof(input_that_fits) <= sizeof(buf), "");
static_assert(sizeof(input_too_big) > sizeof(buf), "");
static_assert(sizeof(input_empty) <= sizeof(buf));
static_assert(sizeof(input_that_fits) <= sizeof(buf));
static_assert(sizeof(input_too_big) > sizeof(buf));

EXPECT_EQ(strcpy_sx(buf, sizeof(buf), input_empty), 0);
EXPECT_EQ(buf[0], 0);
Expand Down

0 comments on commit 6b05379

Please sign in to comment.