mirror of https://github.com/status-im/evmc.git
Merge pull request #182 from ethereum/is_zero
helpers: Add is_zero() helper
This commit is contained in:
commit
f27aa78a34
|
@ -1,6 +1,6 @@
|
|||
/* EVMC: Ethereum Client-VM Connector API.
|
||||
* Copyright 2018 The EVMC Authors.
|
||||
* Licensed under the Apache License, Version 2.0. See the LICENSE file.
|
||||
* Copyright 2019 The EVMC Authors.
|
||||
* 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;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
inline uint64_t fnv1a_64(const uint8_t* ptr, size_t len)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// EVMC: Ethereum Client-VM Connector API.
|
||||
// Copyright 2018 The EVMC Authors.
|
||||
// Licensed under the Apache License, Version 2.0. See the LICENSE file.
|
||||
// Copyright 2019 The EVMC Authors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
|
||||
#include <evmc/helpers.hpp>
|
||||
|
||||
|
@ -27,3 +27,16 @@ TEST(helpers, maps)
|
|||
unordered_storage.emplace(*storage.begin());
|
||||
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