diff --git a/TestHelper.cpp b/TestHelper.cpp index f82b72b88..82add295e 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,7 +23,9 @@ #include #include + #include + #include #include #include diff --git a/TestHelper.h b/TestHelper.h index 3707a5fff..6f9143c5c 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -22,7 +22,9 @@ #pragma once #include + #include + #include "JsonSpiritHeaders.h" #include #include diff --git a/createRandomTest.cpp b/createRandomTest.cpp index fa5ed7bd3..55e023759 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -23,8 +23,10 @@ #include #include #include + #include #include + #pragma GCC diagnostic ignored "-Wunused-parameter" #include #include diff --git a/fork.cpp b/fork.cpp index bc6ed87bc..a2eb6f4eb 100644 --- a/fork.cpp +++ b/fork.cpp @@ -22,6 +22,7 @@ #include #include + #include #include #include diff --git a/genesis.cpp b/genesis.cpp index 7ca741ee9..5ac3ea2a8 100644 --- a/genesis.cpp +++ b/genesis.cpp @@ -22,10 +22,12 @@ #include #include + +#include + #include "JsonSpiritHeaders.h" #include #include -#include #include "TestHelper.h" using namespace std; @@ -40,7 +42,7 @@ BOOST_AUTO_TEST_CASE(emptySHA3Types) { h256 emptyListSHA3(fromHex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")); BOOST_REQUIRE_EQUAL(emptyListSHA3, EmptyListSHA3); - + h256 emptySHA3(fromHex("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); BOOST_REQUIRE_EQUAL(emptySHA3, EmptySHA3); } diff --git a/hexPrefix.cpp b/hexPrefix.cpp index 551983db3..da294ba5b 100644 --- a/hexPrefix.cpp +++ b/hexPrefix.cpp @@ -21,11 +21,13 @@ */ #include + +#include + #include "JsonSpiritHeaders.h" #include #include #include -#include #include "TestHelper.h" using namespace std; @@ -53,8 +55,8 @@ BOOST_AUTO_TEST_CASE(hexPrefix_test) for (auto& i: o["seq"].get_array()) v.push_back((byte)i.get_int()); auto e = hexPrefixEncode(v, o["term"].get_bool()); - BOOST_REQUIRE( ! o["out"].is_null() ); - BOOST_CHECK( o["out"].get_str() == toHex(e) ); + BOOST_REQUIRE( ! o["out"].is_null() ); + BOOST_CHECK( o["out"].get_str() == toHex(e) ); } } diff --git a/net.cpp b/net.cpp index 5039c5436..831c283e2 100644 --- a/net.cpp +++ b/net.cpp @@ -20,6 +20,7 @@ */ #include + #include #include #include @@ -43,7 +44,7 @@ public: void start() { startWorking(); } void doWork() { m_io.run(); } void doneWorking() { m_io.reset(); m_io.poll(); m_io.reset(); } - + protected: ba::io_service m_io; }; @@ -52,23 +53,23 @@ struct TestNodeTable: public NodeTable { /// Constructor TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {} - + static std::vector> createTestNodes(unsigned _count) { std::vector> ret; asserts(_count < 1000); static uint16_t s_basePort = 30500; - + ret.clear(); for (unsigned i = 0; i < _count; i++) { KeyPair k = KeyPair::create(); ret.push_back(make_pair(k,s_basePort+i)); } - + return std::move(ret); } - + void pingTestNodes(std::vector> const& _testNodes) { bi::address ourIp = bi::address::from_string("127.0.0.1"); @@ -78,7 +79,7 @@ struct TestNodeTable: public NodeTable this_thread::sleep_for(chrono::milliseconds(2)); } } - + void populateTestNodes(std::vector> const& _testNodes, size_t _count = 0) { if (!_count) @@ -91,7 +92,7 @@ struct TestNodeTable: public NodeTable else break; } - + void reset() { Guard l(x_state); @@ -108,13 +109,13 @@ struct TestNodeTableHost: public TestHost ~TestNodeTableHost() { m_io.stop(); stopWorking(); } void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared(m_io,n.first,n.second)); } - + void pingAll() { for (auto& t: nodeTables) t->pingTestNodes(testNodes); } - + void populateAll(size_t _count = 0) { for (auto& t: nodeTables) t->populateTestNodes(testNodes, _count); } - + void populate(size_t _count = 0) { nodeTable->populateTestNodes(testNodes, _count); } - + KeyPair m_alias; shared_ptr nodeTable; std::vector> testNodes; // keypair and port @@ -130,7 +131,7 @@ public: void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } shared_ptr> m_socket; - + bool success = false; }; @@ -139,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) KeyPair k = KeyPair::create(); std::vector> testNodes(TestNodeTable::createTestNodes(16)); bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000); - + Neighbours out(to); for (auto n: testNodes) { @@ -186,25 +187,25 @@ BOOST_AUTO_TEST_CASE(kademlia) node.setup(); node.populate(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + node.populateAll(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + auto nodes = node.nodeTable->nodes(); nodes.sort(); - + node.nodeTable->reset(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; node.populate(1); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + node.nodeTable->discover(); this_thread::sleep_for(chrono::milliseconds(2000)); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; BOOST_REQUIRE_EQUAL(node.nodeTable->count(), 8); - + auto netNodes = node.nodeTable->nodes(); netNodes.sort(); diff --git a/rlp.cpp b/rlp.cpp index be098d84d..9062b54f4 100644 --- a/rlp.cpp +++ b/rlp.cpp @@ -22,11 +22,13 @@ #include #include + +#include + #include #include #include #include -#include #include #include "JsonSpiritHeaders.h" #include "TestHelper.h" @@ -66,76 +68,76 @@ namespace dev testPath += "/BasicTests"; string s = asString(contents(testPath + "/rlptest.json")); - BOOST_REQUIRE_MESSAGE( s.length() > 0, - "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); + BOOST_REQUIRE_MESSAGE( s.length() > 0, + "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); js::read_string(s, v); - } + } static void checkRLPTestCase(js::mObject& o) - { - BOOST_REQUIRE( o.count("in") > 0 ); - BOOST_REQUIRE( o.count("out") > 0 ); - BOOST_REQUIRE(!o["out"].is_null()); - } + { + BOOST_REQUIRE( o.count("in") > 0 ); + BOOST_REQUIRE( o.count("out") > 0 ); + BOOST_REQUIRE(!o["out"].is_null()); + } static void checkRLPAgainstJson(js::mValue& v, RLP& u) { - if ( v.type() == js::str_type ) - { + if ( v.type() == js::str_type ) + { const std::string& expectedText = v.get_str(); - if ( !expectedText.empty() && expectedText.front() == '#' ) - { - // Deal with bigint instead of a raw string - std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); - std::stringstream bintStream(bigIntStr); - bigint val; - bintStream >> val; - BOOST_CHECK( !u.isList() ); + if ( !expectedText.empty() && expectedText.front() == '#' ) + { + // Deal with bigint instead of a raw string + std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); + std::stringstream bintStream(bigIntStr); + bigint val; + bintStream >> val; + BOOST_CHECK( !u.isList() ); BOOST_CHECK( !u.isNull() ); BOOST_CHECK( u ); // operator bool() - BOOST_CHECK(u == val); - } - else - { - BOOST_CHECK( !u.isList() ); - BOOST_CHECK( !u.isNull() ); - BOOST_CHECK( u.isData() ); - BOOST_CHECK( u ); - BOOST_CHECK( u.size() == expectedText.length() ); - BOOST_CHECK(u == expectedText); + BOOST_CHECK(u == val); } - } - else if ( v.type() == js::int_type ) - { - const int expectedValue = v.get_int(); - BOOST_CHECK( u.isInt() ); - BOOST_CHECK( !u.isList() ); + else + { + BOOST_CHECK( !u.isList() ); + BOOST_CHECK( !u.isNull() ); + BOOST_CHECK( u.isData() ); + BOOST_CHECK( u ); + BOOST_CHECK( u.size() == expectedText.length() ); + BOOST_CHECK(u == expectedText); + } + } + else if ( v.type() == js::int_type ) + { + const int expectedValue = v.get_int(); + BOOST_CHECK( u.isInt() ); + BOOST_CHECK( !u.isList() ); BOOST_CHECK( !u.isNull() ); BOOST_CHECK( u ); // operator bool() - BOOST_CHECK(u == expectedValue); - } - else if ( v.type() == js::array_type ) - { - BOOST_CHECK( u.isList() ); - BOOST_CHECK( !u.isInt() ); - BOOST_CHECK( !u.isData() ); - js::mArray& arr = v.get_array(); - BOOST_CHECK( u.itemCount() == arr.size() ); - unsigned i; - for( i = 0; i < arr.size(); i++ ) - { - RLP item = u[i]; - checkRLPAgainstJson(arr[i], item); - } - } - else - { + BOOST_CHECK(u == expectedValue); + } + else if ( v.type() == js::array_type ) + { + BOOST_CHECK( u.isList() ); + BOOST_CHECK( !u.isInt() ); + BOOST_CHECK( !u.isData() ); + js::mArray& arr = v.get_array(); + BOOST_CHECK( u.itemCount() == arr.size() ); + unsigned i; + for( i = 0; i < arr.size(); i++ ) + { + RLP item = u[i]; + checkRLPAgainstJson(arr[i], item); + } + } + else + { BOOST_ERROR("Invalid Javascript object!"); - } - - } + } + + } } -} +} BOOST_AUTO_TEST_SUITE(BasicTests) @@ -154,30 +156,30 @@ BOOST_AUTO_TEST_CASE(rlp_encoding_test) RLPStream s; dev::test::buildRLP(o["in"], s); - std::string expectedText(o["out"].get_str()); - std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); + std::string expectedText(o["out"].get_str()); + std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); - const std::string& computedText = toHex(s.out()); + const std::string& computedText = toHex(s.out()); - std::stringstream msg; + std::stringstream msg; msg << "Encoding Failed: expected: " << expectedText << std::endl; - msg << " But Computed: " << computedText; + msg << " But Computed: " << computedText; BOOST_CHECK_MESSAGE( - expectedText == computedText, + expectedText == computedText, msg.str() - ); + ); } } BOOST_AUTO_TEST_CASE(rlp_decoding_test) { - cnote << "Testing RLP decoding..."; - // Uses the same test cases as encoding but in reverse. - // We read into the string of hex values, convert to bytes, - // and then compare the output structure to the json of the - // input object. + cnote << "Testing RLP decoding..."; + // Uses the same test cases as encoding but in reverse. + // We read into the string of hex values, convert to bytes, + // and then compare the output structure to the json of the + // input object. js::mValue v; dev::test::getRLPTestCases(v); for (auto& i: v.get_obj()) @@ -185,11 +187,11 @@ BOOST_AUTO_TEST_CASE(rlp_decoding_test) js::mObject& o = i.second.get_obj(); cnote << i.first; dev::test::checkRLPTestCase(o); - - js::mValue& inputData = o["in"]; - bytes payloadToDecode = fromHex(o["out"].get_str()); - RLP payload(payloadToDecode); + js::mValue& inputData = o["in"]; + bytes payloadToDecode = fromHex(o["out"].get_str()); + + RLP payload(payloadToDecode); dev::test::checkRLPAgainstJson(inputData, payload); diff --git a/state.cpp b/state.cpp index fe133822a..17ebe2b77 100644 --- a/state.cpp +++ b/state.cpp @@ -22,6 +22,7 @@ #include #include + #include "JsonSpiritHeaders.h" #include #include diff --git a/trie.cpp b/trie.cpp index 39a3a59a5..dd335b4a6 100644 --- a/trie.cpp +++ b/trie.cpp @@ -22,12 +22,14 @@ #include #include + +#include + #include "JsonSpiritHeaders.h" #include #include #include "TrieHash.h" #include "MemTrie.h" -#include #include "TestHelper.h" using namespace std; diff --git a/txTest.cpp b/txTest.cpp index 8d067f9bb..e2a16e16c 100644 --- a/txTest.cpp +++ b/txTest.cpp @@ -22,6 +22,7 @@ #include #include + #include #include #include diff --git a/vm.cpp b/vm.cpp index 16f7385a0..e78753e6a 100644 --- a/vm.cpp +++ b/vm.cpp @@ -21,7 +21,9 @@ */ #include + #include + #include #include #include "vm.h" @@ -286,7 +288,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() /*add the storage*/ Object storage; for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) - storage.push_back(Pair( (string)i.first , (string)i.second)); + storage.push_back(Pair( (string)i.first , (string)i.second)); /*add all the other details*/ o_step.push_back(Pair("storage", storage)); @@ -365,7 +367,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) auto argc = boost::unit_test::framework::master_test_suite().argc; auto argv = boost::unit_test::framework::master_test_suite().argv; for (auto i = 0; i < argc; ++i) - { + { if (std::string(argv[i]) == "--show-times") { auto testDuration = endTime - startTime; diff --git a/vm.h b/vm.h index 0a5b5fb45..f27bce50b 100644 --- a/vm.h +++ b/vm.h @@ -25,7 +25,9 @@ along with cpp-ethereum. If not, see . #include #include + #include + #include #include #include diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 4609c957d..0ea681b67 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -19,7 +19,9 @@ * @date 2014 */ #include + #include + #include #include #include @@ -40,10 +42,10 @@ BOOST_AUTO_TEST_CASE(topic) Host host1("Test", NetworkPreferences(30303, "127.0.0.1", false, true)); auto whost1 = host1.registerCapability(new WhisperHost()); host1.start(); - + while (!host1.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + bool started = false; unsigned result = 0; std::thread listener([&]() @@ -71,19 +73,19 @@ BOOST_AUTO_TEST_CASE(topic) } this_thread::sleep_for(chrono::milliseconds(50)); } - + }); - + Host host2("Test", NetworkPreferences(30300, "127.0.0.1", false, true)); auto whost2 = host2.registerCapability(new WhisperHost()); host2.start(); - + while (!host2.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + this_thread::sleep_for(chrono::milliseconds(100)); host2.addNode(host1.id(), "127.0.0.1", 30303, 30303); - + this_thread::sleep_for(chrono::milliseconds(500)); while (!started) @@ -107,7 +109,7 @@ BOOST_AUTO_TEST_CASE(forwarding) cnote << "Testing Whisper forwarding..."; auto oldLogVerbosity = g_logVerbosity; g_logVerbosity = 0; - + // Host must be configured not to share peers. Host host1("Listner", NetworkPreferences(30303, "", false, true)); host1.setIdealPeerCount(0); @@ -115,7 +117,7 @@ BOOST_AUTO_TEST_CASE(forwarding) host1.start(); while (!host1.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + unsigned result = 0; bool done = false; @@ -142,7 +144,7 @@ BOOST_AUTO_TEST_CASE(forwarding) } }); - + // Host must be configured not to share peers. Host host2("Forwarder", NetworkPreferences(30305, "", false, true)); host2.setIdealPeerCount(1); @@ -150,7 +152,7 @@ BOOST_AUTO_TEST_CASE(forwarding) host2.start(); while (!host2.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + Public fwderid; bool startedForwarder = false; std::thread forwarder([&]() @@ -210,7 +212,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) unsigned result = 0; bool done = false; - + // Host must be configured not to share peers. Host host1("Forwarder", NetworkPreferences(30305, "", false, true)); host1.setIdealPeerCount(1); @@ -223,7 +225,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) std::thread forwarder([&]() { setThreadName("forwarder"); - + this_thread::sleep_for(chrono::milliseconds(500)); // ph.addNode("127.0.0.1", 30303, 30303); @@ -245,7 +247,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) while (!startedForwarder) this_thread::sleep_for(chrono::milliseconds(2)); - + { Host host2("Sender", NetworkPreferences(30300, "", false, true)); host2.setIdealPeerCount(1); @@ -257,7 +259,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) while (!host2.peerCount()) this_thread::sleep_for(chrono::milliseconds(5)); - + KeyPair us = KeyPair::create(); whost2->post(us.sec(), RLPStream().append(1).out(), BuildTopic("test")); this_thread::sleep_for(chrono::milliseconds(250));