Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 57b3cc3

Browse files
committed
cpp: Add support for _uin256be literals
Only extending the literal tests, because the other tests are covered via bytes32 tests given uint256be is an alias.
1 parent 58913e0 commit 57b3cc3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/evmc/evmc.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ constexpr bytes32 operator""_bytes32() noexcept
344344
{
345345
return internal::from_literal<bytes32, c...>();
346346
}
347+
348+
/// Literal for evmc::uint256be.
349+
template <char... c>
350+
constexpr uint256be operator""_uint256be() noexcept
351+
{
352+
return internal::from_literal<uint256be, c...>();
353+
}
347354
} // namespace literals
348355

349356
using namespace literals;

test/unittests/cpp_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,28 @@ TEST(cpp, bytes32_from_uint)
400400
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_bytes32);
401401
}
402402

403+
TEST(cpp, uint256be_from_uint)
404+
{
405+
using evmc::uint256be;
406+
using evmc::operator""_uint256be;
407+
408+
static_assert(uint256be{0} == uint256be{}, "");
409+
static_assert(uint256be{3}.bytes[31] == 3, "");
410+
static_assert(uint256be{0xfe00000000000000}.bytes[24] == 0xfe, "");
411+
412+
EXPECT_EQ(uint256be{0}, uint256be{});
413+
EXPECT_EQ(uint256be{0x01},
414+
0x0000000000000000000000000000000000000000000000000000000000000001_uint256be);
415+
EXPECT_EQ(uint256be{0xff},
416+
0x00000000000000000000000000000000000000000000000000000000000000ff_uint256be);
417+
EXPECT_EQ(uint256be{0x500},
418+
0x0000000000000000000000000000000000000000000000000000000000000500_uint256be);
419+
EXPECT_EQ(uint256be{0x8000000000000000},
420+
0x0000000000000000000000000000000000000000000000008000000000000000_uint256be);
421+
EXPECT_EQ(uint256be{0xc1c2c3c4c5c6c7c8},
422+
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_uint256be);
423+
}
424+
403425
TEST(cpp, address_from_uint)
404426
{
405427
using evmc::address;

0 commit comments

Comments
 (0)