evmc/test/unittests/test_helpers.cpp

64 lines
1.9 KiB
C++
Raw Normal View History

2018-09-08 14:08:37 +00:00
// EVMC: Ethereum Client-VM Connector API.
// Copyright 2018-2019 The EVMC Authors.
2019-01-18 11:53:42 +00:00
// Licensed under the Apache License, Version 2.0.
2018-09-08 14:08:37 +00:00
#include <evmc/helpers.h>
2018-09-08 14:08:37 +00:00
#include <evmc/helpers.hpp>
#include <gtest/gtest.h>
#include <map>
#include <unordered_map>
// Compile time checks:
static_assert(sizeof(evmc_bytes32) == 32, "evmc_bytes32 is too big");
static_assert(sizeof(evmc_address) == 20, "evmc_address is too big");
static_assert(sizeof(evmc_result) <= 64, "evmc_result does not fit cache line");
static_assert(sizeof(evmc_instance) <= 64, "evmc_instance does not fit cache line");
static_assert(offsetof(evmc_message, value) % 8 == 0, "evmc_message.value not aligned");
// Check enums match int size.
// On GCC/clang the underlying type should be unsigned int, on MSVC int
static_assert(sizeof(evmc_call_kind) == sizeof(int),
"Enum `evmc_call_kind` is not the size of int");
static_assert(sizeof(evmc_revision) == sizeof(int), "Enum `evmc_revision` is not the size of int");
static constexpr size_t optionalDataSize =
sizeof(evmc_result) - offsetof(evmc_result, create_address);
static_assert(optionalDataSize == sizeof(evmc_result_optional_storage), "");
2018-09-08 14:08:37 +00:00
TEST(helpers, maps)
{
std::map<evmc_address, bool> addresses;
addresses[{}] = true;
ASSERT_EQ(addresses.size(), 1);
std::unordered_map<evmc_address, bool> unordered_addresses;
unordered_addresses.emplace(*addresses.begin());
EXPECT_EQ(unordered_addresses.size(), 1);
std::map<evmc_bytes32, bool> storage;
storage[{}] = true;
ASSERT_EQ(storage.size(), 1);
std::unordered_map<evmc_bytes32, bool> unordered_storage;
unordered_storage.emplace(*storage.begin());
EXPECT_EQ(unordered_storage.size(), 1);
}
2019-01-18 11:53:42 +00:00
TEST(helpers, is_zero)
{
auto a = evmc_address{};
EXPECT_TRUE(is_zero(a));
a.bytes[0] = 1;
EXPECT_FALSE(is_zero(a));
auto b = evmc_bytes32{};
EXPECT_TRUE(is_zero(b));
b.bytes[0] = 1;
EXPECT_FALSE(is_zero(b));
}