2018-09-08 16:08:37 +02:00
|
|
|
// EVMC: Ethereum Client-VM Connector API.
|
2019-04-24 16:12:13 +02:00
|
|
|
// Copyright 2018-2019 The EVMC Authors.
|
2019-01-18 12:53:42 +01:00
|
|
|
// Licensed under the Apache License, Version 2.0.
|
2018-09-08 16:08:37 +02:00
|
|
|
|
2019-03-15 02:32:00 +01:00
|
|
|
#include <evmc/helpers.h>
|
2018-09-08 16:08:37 +02:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2019-03-15 02:32:00 +01:00
|
|
|
// 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");
|
2019-06-25 11:04:53 +02:00
|
|
|
static_assert(offsetof(evmc_message, value) % sizeof(size_t) == 0,
|
|
|
|
"evmc_message.value not aligned");
|
2019-03-15 02:32:00 +01:00
|
|
|
|
|
|
|
// 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);
|
2019-06-25 11:04:53 +02:00
|
|
|
static_assert(optionalDataSize >= sizeof(evmc_result_optional_storage),
|
|
|
|
"evmc_result's optional data space is too small");
|
2019-03-15 02:32:00 +01:00
|
|
|
|
2019-05-09 21:51:42 +02:00
|
|
|
TEST(helpers, release_result)
|
|
|
|
{
|
|
|
|
auto r1 = evmc_result{};
|
|
|
|
evmc_release_result(&r1);
|
|
|
|
|
|
|
|
static evmc_result r2;
|
|
|
|
static bool e;
|
|
|
|
|
|
|
|
e = false;
|
|
|
|
r2 = evmc_result{};
|
|
|
|
r2.release = [](const evmc_result* r) { e = r == &r2; };
|
|
|
|
EXPECT_FALSE(e);
|
|
|
|
evmc_release_result(&r2);
|
|
|
|
EXPECT_TRUE(e);
|
|
|
|
}
|