Skip to content

Commit

Permalink
cpp: Add support for _uin256be literals
Browse files Browse the repository at this point in the history
Only extending the literal tests, because the other tests are covered
via bytes32 tests given uint256be is an alias.
  • Loading branch information
axic committed Jun 1, 2022
1 parent 58913e0 commit 57b3cc3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ constexpr bytes32 operator""_bytes32() noexcept
{
return internal::from_literal<bytes32, c...>();
}

/// Literal for evmc::uint256be.
template <char... c>
constexpr uint256be operator""_uint256be() noexcept
{
return internal::from_literal<uint256be, c...>();
}
} // namespace literals

using namespace literals;
Expand Down
22 changes: 22 additions & 0 deletions test/unittests/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,28 @@ TEST(cpp, bytes32_from_uint)
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_bytes32);
}

TEST(cpp, uint256be_from_uint)
{
using evmc::uint256be;
using evmc::operator""_uint256be;

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

EXPECT_EQ(uint256be{0}, uint256be{});
EXPECT_EQ(uint256be{0x01},
0x0000000000000000000000000000000000000000000000000000000000000001_uint256be);
EXPECT_EQ(uint256be{0xff},
0x00000000000000000000000000000000000000000000000000000000000000ff_uint256be);
EXPECT_EQ(uint256be{0x500},
0x0000000000000000000000000000000000000000000000000000000000000500_uint256be);
EXPECT_EQ(uint256be{0x8000000000000000},
0x0000000000000000000000000000000000000000000000008000000000000000_uint256be);
EXPECT_EQ(uint256be{0xc1c2c3c4c5c6c7c8},
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_uint256be);
}

TEST(cpp, address_from_uint)
{
using evmc::address;
Expand Down

0 comments on commit 57b3cc3

Please sign in to comment.