forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tests for network functions to a separate file
- Loading branch information
1 parent
53a1f95
commit 31e3f12
Showing
4 changed files
with
61 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <nano/node/transport/transport.hpp> | ||
#include <nano/test_common/testutil.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST (network_functions, reserved_address) | ||
{ | ||
// 0 port test | ||
ASSERT_TRUE (nano::transport::reserved_address (nano::endpoint (boost::asio::ip::make_address_v6 ("2001::"), 0))); | ||
// Valid address test | ||
ASSERT_FALSE (nano::transport::reserved_address (nano::endpoint (boost::asio::ip::make_address_v6 ("2001::"), 1))); | ||
nano::endpoint loopback (boost::asio::ip::make_address_v6 ("::1"), 1); | ||
ASSERT_FALSE (nano::transport::reserved_address (loopback)); | ||
nano::endpoint private_network_peer (boost::asio::ip::make_address_v6 ("::ffff:10.0.0.0"), 1); | ||
ASSERT_TRUE (nano::transport::reserved_address (private_network_peer, false)); | ||
ASSERT_FALSE (nano::transport::reserved_address (private_network_peer, true)); | ||
} | ||
|
||
TEST (network_functions, ipv6_bind_subnetwork) | ||
{ | ||
auto address1 (boost::asio::ip::make_address_v6 ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713")); | ||
auto subnet1 (boost::asio::ip::make_network_v6 (address1, 48)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("a41d:b7b2:8298::"), subnet1.network ()); | ||
auto address1_subnet (nano::transport::ipv4_address_or_ipv6_subnet (address1)); | ||
ASSERT_EQ (subnet1.network (), address1_subnet); | ||
// Ipv4 should return initial address | ||
auto address2 (boost::asio::ip::make_address_v6 ("::ffff:192.168.1.1")); | ||
auto address2_subnet (nano::transport::ipv4_address_or_ipv6_subnet (address2)); | ||
ASSERT_EQ (address2, address2_subnet); | ||
} | ||
|
||
TEST (network_functions, network_range_ipv6) | ||
{ | ||
auto address1 (boost::asio::ip::make_address_v6 ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713")); | ||
auto subnet1 (boost::asio::ip::make_network_v6 (address1, 58)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("a41d:b7b2:8298:cf40::"), subnet1.network ()); | ||
auto address2 (boost::asio::ip::make_address_v6 ("520d:2402:3d:5e65:11:f8:7c54:3f")); | ||
auto subnet2 (boost::asio::ip::make_network_v6 (address2, 33)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("520d:2402:0::"), subnet2.network ()); | ||
// Default settings test | ||
auto address3 (boost::asio::ip::make_address_v6 ("a719:0f12:536e:d88a:1331:ba53:4598:04e5")); | ||
auto subnet3 (boost::asio::ip::make_network_v6 (address3, 32)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("a719:0f12::"), subnet3.network ()); | ||
auto address3_subnet (nano::transport::map_address_to_subnetwork (address3)); | ||
ASSERT_EQ (subnet3.network (), address3_subnet); | ||
} | ||
|
||
TEST (network_functions, network_range_ipv4) | ||
{ | ||
auto address1 (boost::asio::ip::make_address_v6 ("::ffff:192.168.1.1")); | ||
auto subnet1 (boost::asio::ip::make_network_v6 (address1, 96 + 16)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("::ffff:192.168.0.0"), subnet1.network ()); | ||
// Default settings test | ||
auto address2 (boost::asio::ip::make_address_v6 ("::ffff:80.67.148.225")); | ||
auto subnet2 (boost::asio::ip::make_network_v6 (address2, 96 + 24)); | ||
ASSERT_EQ (boost::asio::ip::make_address_v6 ("::ffff:80.67.148.0"), subnet2.network ()); | ||
auto address2_subnet (nano::transport::map_address_to_subnetwork (address2)); | ||
ASSERT_EQ (subnet2.network (), address2_subnet); | ||
} |
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