diff options
-rw-r--r-- | TestHelper.cpp | 3 | ||||
-rw-r--r-- | TestHelper.h | 3 | ||||
-rw-r--r-- | checkRandomTest.cpp | 2 | ||||
-rw-r--r-- | createRandomTest.cpp | 3 | ||||
-rw-r--r-- | fork.cpp | 3 | ||||
-rw-r--r-- | hexPrefix.cpp | 7 | ||||
-rw-r--r-- | net.cpp | 30 | ||||
-rw-r--r-- | rlp.cpp | 145 | ||||
-rw-r--r-- | state.cpp | 2 | ||||
-rw-r--r-- | trie.cpp | 3 | ||||
-rw-r--r-- | txTest.cpp | 3 | ||||
-rw-r--r-- | vm.cpp | 7 | ||||
-rw-r--r-- | vm.h | 3 | ||||
-rw-r--r-- | whisperTopic.cpp | 3 |
14 files changed, 128 insertions, 89 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp index 4ee53f88..16f0d6d1 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,8 +23,11 @@ #include <thread> #include <chrono> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/filesystem/path.hpp> + #include <libethereum/Client.h> #include <liblll/Compiler.h> #include <libevm/VMFactory.h> diff --git a/TestHelper.h b/TestHelper.h index 0b80273c..40294b03 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -22,8 +22,11 @@ #pragma once #include <functional> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include "JsonSpiritHeaders.h" #include <libethereum/State.h> #include <libevm/ExtVMFace.h> diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp index 50c3c367..f1daaecb 100644 --- a/checkRandomTest.cpp +++ b/checkRandomTest.cpp @@ -20,7 +20,9 @@ * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. */ +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> + #include <libdevcore/Common.h> #include <libdevcore/Exceptions.h> #include <libdevcore/Log.h> diff --git a/createRandomTest.cpp b/createRandomTest.cpp index da1a028b..140a7fb3 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -23,9 +23,12 @@ #include <string> #include <iostream> #include <chrono> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/random.hpp> #include <boost/filesystem/path.hpp> + #pragma GCC diagnostic ignored "-Wunused-parameter" #include <json_spirit/json_spirit.h> #include <json_spirit/json_spirit_reader_template.h> @@ -19,9 +19,12 @@ * @date 2014 * Tests for different forking behavior */ + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> #include <boost/filesystem/operations.hpp> + #include <libethereum/Client.h> #include <libethereum/CanonBlockChain.h> #include <libethereum/EthereumHost.h> diff --git a/hexPrefix.cpp b/hexPrefix.cpp index c96e9e98..5875d62f 100644 --- a/hexPrefix.cpp +++ b/hexPrefix.cpp @@ -21,8 +21,11 @@ */ #include <fstream> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include "JsonSpiritHeaders.h" #include <libdevcore/Log.h> #include <libdevcore/CommonIO.h> @@ -54,8 +57,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) ); } } @@ -19,8 +19,10 @@ * @date 2014 */ +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include <libdevcore/Worker.h> #include <libdevcrypto/Common.h> #include <libp2p/UDP.h> @@ -44,7 +46,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; }; @@ -53,23 +55,23 @@ struct TestNodeTable: public NodeTable { /// Constructor TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {} - + static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(unsigned _count) { std::vector<std::pair<KeyPair,unsigned>> 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<std::pair<KeyPair,unsigned>> const& _testNodes) { bi::address ourIp = bi::address::from_string("127.0.0.1"); @@ -79,7 +81,7 @@ struct TestNodeTable: public NodeTable this_thread::sleep_for(chrono::milliseconds(2)); } } - + void populateTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes, size_t _count = 0) { if (!_count) @@ -92,7 +94,7 @@ struct TestNodeTable: public NodeTable else break; } - + void reset() { Guard l(x_state); @@ -109,13 +111,13 @@ struct TestNodeTableHost: public TestHost ~TestNodeTableHost() { m_io.stop(); stopWorking(); } void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared<TestNodeTable>(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<TestNodeTable> nodeTable; std::vector<std::pair<KeyPair,unsigned>> testNodes; // keypair and port @@ -131,7 +133,7 @@ public: void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } shared_ptr<UDPSocket<TestUDPSocket, 1024>> m_socket; - + bool success = false; }; @@ -140,7 +142,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) KeyPair k = KeyPair::create(); std::vector<std::pair<KeyPair,unsigned>> 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) { @@ -187,7 +189,7 @@ 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; @@ -22,8 +22,11 @@ #include <fstream> #include <sstream> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include <libdevcore/Log.h> #include <libdevcore/RLP.h> #include <libdevcore/Common.h> @@ -67,76 +70,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) @@ -155,30 +158,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()) @@ -186,11 +189,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()); + bytes payloadToDecode = fromHex(o["out"].get_str()); - RLP payload(payloadToDecode); + RLP payload(payloadToDecode); dev::test::checkRLPAgainstJson(inputData, payload); @@ -20,9 +20,11 @@ * State test functions. */ +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/filesystem/operations.hpp> #include <boost/test/unit_test.hpp> + #include "JsonSpiritHeaders.h" #include <libdevcore/CommonIO.h> #include <libethereum/CanonBlockChain.h> @@ -22,8 +22,11 @@ #include <fstream> #include <random> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include "JsonSpiritHeaders.h" #include <libdevcore/CommonIO.h> #include <libdevcrypto/TrieDB.h> @@ -19,9 +19,12 @@ * @date 2014 * Simple peer transaction send test. */ + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> #include <boost/filesystem/operations.hpp> + #include <libethereum/Client.h> #include <libethereum/CanonBlockChain.h> #include <libethereum/EthereumHost.h> @@ -21,8 +21,11 @@ */ #include <chrono> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/filesystem.hpp> + #include <libethereum/Executive.h> #include <libevm/VMFactory.h> #include "vm.h" @@ -287,7 +290,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)); @@ -366,7 +369,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; @@ -25,8 +25,11 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <fstream> #include <cstdint> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include <json_spirit/json_spirit.h> #include <libdevcore/Log.h> #include <libdevcore/CommonIO.h> diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 2f90b4fb..0937ab92 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -19,8 +19,11 @@ * @date 2014 */ #include <functional> + +// Make sure boost/asio.hpp is included before windows.h. #include <boost/asio.hpp> #include <boost/test/unit_test.hpp> + #include <libp2p/Host.h> #include <libwhisper/WhisperPeer.h> #include <libwhisper/WhisperHost.h> |