diff --git a/net.cpp b/net.cpp index ae6053795..fff3c182e 100644 --- a/net.cpp +++ b/net.cpp @@ -343,3 +343,30 @@ BOOST_AUTO_TEST_CASE(test_udp_once) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(netTypes) + +BOOST_AUTO_TEST_CASE(unspecifiedNode) +{ + Node n = UnspecifiedNode; + BOOST_REQUIRE(!n); + + Node node(Public(sha3("0")), NodeIPEndpoint(bi::address(), 0, 0)); + BOOST_REQUIRE(node); + BOOST_REQUIRE(n != node); + + Node nodeEq(Public(sha3("0")), NodeIPEndpoint(bi::address(), 0, 0)); + BOOST_REQUIRE_EQUAL(node, nodeEq); +} + +BOOST_AUTO_TEST_CASE(nodeTableReturnsUnspecifiedNode) +{ + ba::io_service io; + NodeTable t(io, KeyPair::create(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30303, 30303)); + if (Node n = t.node(NodeId())) + BOOST_REQUIRE(false); + else + BOOST_REQUIRE(n == UnspecifiedNode); +} + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/peer.cpp b/peer.cpp index 1d593534a..494231e3c 100644 --- a/peer.cpp +++ b/peer.cpp @@ -112,6 +112,29 @@ BOOST_AUTO_TEST_CASE(save_nodes) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(peerTypes) + +BOOST_AUTO_TEST_CASE(emptySharedPeer) +{ + shared_ptr p; + BOOST_REQUIRE(!p); + + std::map> peers; + p = peers[NodeId()]; + BOOST_REQUIRE(!p); + + p.reset(new Peer(UnspecifiedNode)); + BOOST_REQUIRE(!p->id); + BOOST_REQUIRE(!*p); + + p.reset(new Peer(Node(NodeId(EmptySHA3), UnspecifiedNodeIPEndpoint))); + BOOST_REQUIRE(!(!*p)); + BOOST_REQUIRE(*p); + BOOST_REQUIRE(p); +} + +BOOST_AUTO_TEST_SUITE_END() + int peerTest(int argc, char** argv) { Public remoteAlias;