mirror of https://github.com/status-im/evmc.git
helpers: Add is_zero() helper
This commit is contained in:
parent
9aff0e98e8
commit
28b2b8d6cf
|
@ -1,6 +1,6 @@
|
||||||
/* EVMC: Ethereum Client-VM Connector API.
|
/* EVMC: Ethereum Client-VM Connector API.
|
||||||
* Copyright 2018 The EVMC Authors.
|
* Copyright 2019 The EVMC Authors.
|
||||||
* Licensed under the Apache License, Version 2.0. See the LICENSE file.
|
* Licensed under the Apache License, Version 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,6 +41,18 @@ inline bool operator==(const evmc_bytes32& a, const evmc_bytes32& b)
|
||||||
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) == 0;
|
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if the address is zero (all bytes are zeros).
|
||||||
|
inline bool is_zero(const evmc_address& address) noexcept
|
||||||
|
{
|
||||||
|
return address == evmc_address{};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if the hash is zero (all bytes are zeros).
|
||||||
|
inline bool is_zero(const evmc_bytes32& x) noexcept
|
||||||
|
{
|
||||||
|
return x == evmc_bytes32{};
|
||||||
|
}
|
||||||
|
|
||||||
/// FNV1a hash function with 64-bit result.
|
/// FNV1a hash function with 64-bit result.
|
||||||
inline uint64_t fnv1a_64(const uint8_t* ptr, size_t len)
|
inline uint64_t fnv1a_64(const uint8_t* ptr, size_t len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// EVMC: Ethereum Client-VM Connector API.
|
// EVMC: Ethereum Client-VM Connector API.
|
||||||
// Copyright 2018 The EVMC Authors.
|
// Copyright 2019 The EVMC Authors.
|
||||||
// Licensed under the Apache License, Version 2.0. See the LICENSE file.
|
// Licensed under the Apache License, Version 2.0.
|
||||||
|
|
||||||
#include <evmc/helpers.hpp>
|
#include <evmc/helpers.hpp>
|
||||||
|
|
||||||
|
@ -27,3 +27,16 @@ TEST(helpers, maps)
|
||||||
unordered_storage.emplace(*storage.begin());
|
unordered_storage.emplace(*storage.begin());
|
||||||
EXPECT_EQ(unordered_storage.size(), 1);
|
EXPECT_EQ(unordered_storage.size(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue