-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load 64 bit integers for dec and hex string. Add unit tests.
- Loading branch information
Showing
6 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <gtest/gtest.h> | ||
#include <test/statetest/statetest.hpp> | ||
|
||
using namespace evmone; | ||
|
||
TEST(json_loader, uint64_t) | ||
{ | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json("0x00000005")), 5); | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json("5")), 5); | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json(7)), 7); | ||
|
||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json("0xffffffffffffffff")), | ||
std::numeric_limits<uint64_t>::max()); | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json("18446744073709551615")), | ||
std::numeric_limits<uint64_t>::max()); | ||
EXPECT_THROW( | ||
test::from_json<uint64_t>(json::basic_json("0x10000000000000000")), std::out_of_range); | ||
EXPECT_THROW( | ||
test::from_json<uint64_t>(json::basic_json("18446744073709551616")), std::out_of_range); | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json(0xffffffffffffffff)), | ||
std::numeric_limits<uint64_t>::max()); | ||
|
||
// TODO: Isn't it a little strange behaviour of std::stoull? | ||
EXPECT_EQ(test::from_json<uint64_t>(json::basic_json("0x000000000000000k")), 0); | ||
EXPECT_THROW(test::from_json<uint64_t>(json::basic_json("k")), std::invalid_argument); | ||
} | ||
|
||
TEST(json_loader, int64_t) | ||
{ | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("0x00000005")), 5); | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("-0x5")), -5); | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("-5")), -5); | ||
|
||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json(-7)), -7); | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json(0xffffffffffffffff)), -1); | ||
|
||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("0x7fffffffffffffff")), | ||
std::numeric_limits<int64_t>::max()); | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("9223372036854775807")), | ||
std::numeric_limits<int64_t>::max()); | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("-9223372036854775808")), | ||
std::numeric_limits<int64_t>::min()); | ||
EXPECT_THROW( | ||
test::from_json<int64_t>(json::basic_json("0xffffffffffffffff")), std::out_of_range); | ||
EXPECT_THROW( | ||
test::from_json<int64_t>(json::basic_json("9223372036854775808")), std::out_of_range); | ||
EXPECT_THROW( | ||
test::from_json<int64_t>(json::basic_json("-9223372036854775809")), std::out_of_range); | ||
|
||
// TODO: Isn't it a little strange behaviour of std::stoull? | ||
EXPECT_EQ(test::from_json<int64_t>(json::basic_json("0x000000000000000k")), 0); | ||
EXPECT_THROW(test::from_json<int64_t>(json::basic_json("k")), std::invalid_argument); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters