Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp: Add support for _uint256be literals #596

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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