From 2560af3a1da5162063c19817fdbd8e64bf6d4e42 Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 14 Apr 2015 02:22:39 -0400 Subject: [PATCH 1/6] cleanup/prep endpoint semantics for #1558 and #1557 --- net.cpp | 16 +++++++++++----- peer.cpp | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/net.cpp b/net.cpp index ec1efb360..1cc00e095 100644 --- a/net.cpp +++ b/net.cpp @@ -32,7 +32,13 @@ using namespace dev::p2p; namespace ba = boost::asio; namespace bi = ba::ip; -BOOST_AUTO_TEST_SUITE(net) +struct NetFixture +{ + NetFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true;; } + ~NetFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = false; } +}; + +BOOST_FIXTURE_TEST_SUITE(net, NetFixture) /** * Only used for testing. Not useful beyond tests. @@ -53,7 +59,7 @@ protected: struct TestNodeTable: public NodeTable { /// Constructor - TestNodeTable(ba::io_service& _io, KeyPair _alias, bi::address const& _addr, uint16_t _port = 30300): NodeTable(_io, _alias, _addr, _port) {} + TestNodeTable(ba::io_service& _io, KeyPair _alias, bi::address const& _addr, uint16_t _port = 30300): NodeTable(_io, _alias, NodeIPEndpoint(_addr, _port, _port)) {} static std::vector> createTestNodes(unsigned _count) { @@ -93,7 +99,7 @@ struct TestNodeTable: public NodeTable // manually add node for test { Guard ln(x_nodes); - shared_ptr node(new NodeEntry(m_node, n.first.pub(), NodeIPEndpoint(bi::udp::endpoint(ourIp, n.second), bi::tcp::endpoint(ourIp, n.second)))); + shared_ptr node(new NodeEntry(m_node, n.first.pub(), NodeIPEndpoint(ourIp, n.second, n.second))); node->pending = false; m_nodes[node->id] = node; } @@ -201,7 +207,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) { Neighbours::Node node; node.ipAddress = boost::asio::ip::address::from_string("127.0.0.1").to_string(); - node.port = n.second; + node.udpPort = n.second; node.node = n.first.pub(); out.nodes.push_back(node); } @@ -213,7 +219,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) int count = 0; for (auto n: in.nodes) { - BOOST_REQUIRE_EQUAL(testNodes[count].second, n.port); + BOOST_REQUIRE_EQUAL(testNodes[count].second, n.udpPort); BOOST_REQUIRE_EQUAL(testNodes[count].first.pub(), n.node); BOOST_REQUIRE_EQUAL(sha3(testNodes[count].first.pub()), sha3(n.node)); count++; diff --git a/peer.cpp b/peer.cpp index 2aeb99469..1d593534a 100644 --- a/peer.cpp +++ b/peer.cpp @@ -28,7 +28,13 @@ using namespace std; using namespace dev; using namespace dev::p2p; -BOOST_AUTO_TEST_SUITE(p2p) +struct P2PFixture +{ + P2PFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true;; } + ~P2PFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = false; } +}; + +BOOST_FIXTURE_TEST_SUITE(p2p, P2PFixture) BOOST_AUTO_TEST_CASE(host) { @@ -45,7 +51,7 @@ BOOST_AUTO_TEST_CASE(host) auto node2 = host2.id(); host2.start(); - host1.addNode(node2, bi::address::from_string("127.0.0.1"), host2prefs.listenPort, host2prefs.listenPort); + host1.addNode(node2, NodeIPEndpoint(bi::address::from_string("127.0.0.1"), host2prefs.listenPort, host2prefs.listenPort)); this_thread::sleep_for(chrono::seconds(3)); @@ -82,11 +88,11 @@ BOOST_AUTO_TEST_CASE(save_nodes) Host& host = *hosts.front(); for (auto const& h: hosts) - host.addNode(h->id(), bi::address::from_string("127.0.0.1"), h->listenPort(), h->listenPort()); + host.addNode(h->id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), h->listenPort(), h->listenPort())); Host& host2 = *hosts.back(); for (auto const& h: hosts) - host2.addNode(h->id(), bi::address::from_string("127.0.0.1"), h->listenPort(), h->listenPort()); + host2.addNode(h->id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), h->listenPort(), h->listenPort())); this_thread::sleep_for(chrono::milliseconds(2000)); bytes firstHostNetwork(host.saveNetwork()); @@ -131,7 +137,7 @@ int peerTest(int argc, char** argv) Host ph("Test", NetworkPreferences(listenPort)); if (!remoteHost.empty() && !remoteAlias) - ph.addNode(remoteAlias, bi::address::from_string(remoteHost), remotePort, remotePort); + ph.addNode(remoteAlias, NodeIPEndpoint(bi::address::from_string(remoteHost), remotePort, remotePort)); this_thread::sleep_for(chrono::milliseconds(200)); From 94aa125268cde3b18a523be02fd98aa243a3919f Mon Sep 17 00:00:00 2001 From: subtly Date: Wed, 15 Apr 2015 21:23:49 -0400 Subject: [PATCH 2/6] update test --- net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net.cpp b/net.cpp index 28b4f4286..ae6053795 100644 --- a/net.cpp +++ b/net.cpp @@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE(neighboursPacketLength) { Neighbours::Node node; node.ipAddress = boost::asio::ip::address::from_string("200.200.200.200").to_string(); - node.port = testNodes[i].second; + node.udpPort = testNodes[i].second; node.node = testNodes[i].first.pub(); out.nodes.push_back(node); } From 14adc795ac6efc48de5f63cd9b459ee96e968795 Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 16 Apr 2015 20:53:12 -0400 Subject: [PATCH 3/6] test constants --- net.cpp | 27 +++++++++++++++++++++++++++ peer.cpp | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) 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; From 6803c4f2db4ace4c1c07a1d05c4ba4a0ce7794dd Mon Sep 17 00:00:00 2001 From: subtly Date: Fri, 17 Apr 2015 06:41:45 -0400 Subject: [PATCH 4/6] style --- net.cpp | 2 +- peer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net.cpp b/net.cpp index fff3c182e..9a5dbb32f 100644 --- a/net.cpp +++ b/net.cpp @@ -34,7 +34,7 @@ namespace bi = ba::ip; struct NetFixture { - NetFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true;; } + NetFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true; } ~NetFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = false; } }; diff --git a/peer.cpp b/peer.cpp index 494231e3c..8271c1807 100644 --- a/peer.cpp +++ b/peer.cpp @@ -30,7 +30,7 @@ using namespace dev::p2p; struct P2PFixture { - P2PFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true;; } + P2PFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = true; } ~P2PFixture() { dev::p2p::NodeIPEndpoint::test_allowLocal = false; } }; From d0470999b225bf8b54fdaf9a63062079df996d4f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Apr 2015 17:43:30 +0200 Subject: [PATCH 5/6] Tests for signed integers in storage. --- SolidityEndToEndTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 0d7a933b0..3764949d9 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -3676,6 +3676,29 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_with_bytes0) BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); } +BOOST_AUTO_TEST_CASE(packed_storage_signed) +{ + char const* sourceCode = R"( + contract C { + int8 a; + uint8 b; + int8 c; + uint8 d; + function test() returns (uint x1, uint x2, uint x3, uint x4) { + a = -2; + b = -uint8(a) * 2; + c = a * int8(120) * int8(121); + x1 = uint(a); + x2 = b; + x3 = uint(c); + x4 = d; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK( callContractFunction("test()") == encodeArgs(u256(-2), u256(4), u256(-112), u256(0))); +} + BOOST_AUTO_TEST_SUITE_END() } From fbf48b6501384c869ec7860508f081745601a96a Mon Sep 17 00:00:00 2001 From: subtly Date: Fri, 17 Apr 2015 07:54:22 -0400 Subject: [PATCH 6/6] network save/restore: merge fixes, simpler code, limit parse of require flag to peers (reflecting save code). --- peer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peer.cpp b/peer.cpp index 459b758ce..727430fc8 100644 --- a/peer.cpp +++ b/peer.cpp @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(save_nodes) BOOST_REQUIRE(r.itemCount() == 3); BOOST_REQUIRE(r[0].toInt() == dev::p2p::c_protocolVersion); BOOST_REQUIRE_EQUAL(r[1].toBytes().size(), 32); // secret - BOOST_REQUIRE_EQUAL(r[2].itemCount(), 5); + BOOST_REQUIRE(r[2].itemCount() >= 5); for (auto i: r[2]) {