Skip to content

Commit dcdfb9f

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 4a13c9a commit dcdfb9f

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
@@ -332,6 +332,13 @@ constexpr bytes32 operator""_bytes32() noexcept
332332
{
333333
return internal::from_literal<bytes32, c...>();
334334
}
335+
336+
/// Literal for evmc::uint256be.
337+
template <char... c>
338+
constexpr uint256be operator""_uint256be() noexcept
339+
{
340+
return internal::from_literal<uint256be, c...>();
341+
}
335342
} // namespace literals
336343

337344
using namespace literals;

test/unittests/cpp_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,28 @@ TEST(cpp, bytes32_from_uint)
387387
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_bytes32);
388388
}
389389

390+
TEST(cpp, uint256be_from_uint)
391+
{
392+
using evmc::uint256be;
393+
using evmc::operator""_uint256be;
394+
395+
static_assert(uint256be{0} == uint256be{}, "");
396+
static_assert(uint256be{3}.bytes[31] == 3, "");
397+
static_assert(uint256be{0xfe00000000000000}.bytes[24] == 0xfe, "");
398+
399+
EXPECT_EQ(uint256be{0}, uint256be{});
400+
EXPECT_EQ(uint256be{0x01},
401+
0x0000000000000000000000000000000000000000000000000000000000000001_uint256be);
402+
EXPECT_EQ(uint256be{0xff},
403+
0x00000000000000000000000000000000000000000000000000000000000000ff_uint256be);
404+
EXPECT_EQ(uint256be{0x500},
405+
0x0000000000000000000000000000000000000000000000000000000000000500_uint256be);
406+
EXPECT_EQ(uint256be{0x8000000000000000},
407+
0x0000000000000000000000000000000000000000000000008000000000000000_uint256be);
408+
EXPECT_EQ(uint256be{0xc1c2c3c4c5c6c7c8},
409+
0x000000000000000000000000000000000000000000000000c1c2c3c4c5c6c7c8_uint256be);
410+
}
411+
390412
TEST(cpp, address_from_uint)
391413
{
392414
using evmc::address;

0 commit comments

Comments
 (0)