Browse Source

asio.h and windows.h build comments as per request.

cl-refactor
jhuntley 10 years ago
parent
commit
0bf7d15a57
  1. 3
      alethzero/MainWin.cpp
  2. 3
      alethzero/MainWin.h
  3. 3
      eth/main.cpp
  4. 2
      libethereum/All.h
  5. 3
      libethereum/Client.h
  6. 3
      libethereum/EthereumHost.h
  7. 3
      libethereum/EthereumPeer.h
  8. 3
      libp2p/Common.h
  9. 3
      libp2p/Host.cpp
  10. 3
      libp2p/Host.h
  11. 28
      libp2p/Network.cpp
  12. 15
      libp2p/NodeTable.h
  13. 3
      libp2p/Session.h
  14. 53
      libp2p/UDP.h
  15. 2
      libweb3jsonrpc/WebThreeStubServer.cpp
  16. 8
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  17. 3
      libwebthree/WebThree.cpp
  18. 5
      libwebthree/WebThree.h
  19. 3
      libwhisper/Common.h
  20. 3
      libwhisper/Interface.h
  21. 3
      libwhisper/Message.h
  22. 3
      libwhisper/WhisperHost.h
  23. 3
      libwhisper/WhisperPeer.h
  24. 2
      mix/AppContext.cpp
  25. 2
      mix/AppContext.h
  26. 2
      mix/ClientModel.cpp
  27. 2
      mix/CodeEditorExtensionManager.cpp
  28. 3
      mix/Extension.cpp
  29. 2
      mix/Extension.h
  30. 3
      mix/QContractDefinition.cpp
  31. 3
      neth/main.cpp
  32. 3
      test/TestHelper.cpp
  33. 3
      test/TestHelper.h
  34. 2
      test/checkRandomTest.cpp
  35. 3
      test/createRandomTest.cpp
  36. 3
      test/fork.cpp
  37. 7
      test/hexPrefix.cpp
  38. 30
      test/net.cpp
  39. 145
      test/rlp.cpp
  40. 2
      test/state.cpp
  41. 3
      test/trie.cpp
  42. 3
      test/txTest.cpp
  43. 7
      test/vm.cpp
  44. 3
      test/vm.h
  45. 3
      test/whisperTopic.cpp

3
alethzero/MainWin.cpp

@ -20,7 +20,10 @@
*/
#include <fstream>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QtNetwork/QNetworkReply>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>

3
alethzero/MainWin.h

@ -26,7 +26,10 @@
#endif
#include <map>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QtNetwork/QNetworkAccessManager>
#include <QtCore/QAbstractListModel>
#include <QtCore/QMutex>

3
eth/main.cpp

@ -25,9 +25,12 @@
#include <fstream>
#include <iostream>
#include <signal.h>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <libdevcrypto/FileSystem.h>
#include <libevmcore/Instruction.h>
#include <libdevcore/StructuredLogger.h>

2
libethereum/All.h

@ -1,6 +1,8 @@
#pragma once
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include "Account.h"
#include "CanonBlockChain.h"
#include "Client.h"

3
libethereum/Client.h

@ -27,8 +27,11 @@
#include <atomic>
#include <string>
#include <array>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/utility.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/Guards.h>

3
libethereum/EthereumHost.h

@ -28,7 +28,10 @@
#include <memory>
#include <utility>
#include <thread>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h>

3
libethereum/EthereumPeer.h

@ -26,7 +26,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libdevcore/RangeMask.h>

3
libp2p/Common.h

@ -27,8 +27,11 @@
#include <string>
#include <set>
#include <vector>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <chrono>
#include <libdevcrypto/Common.h>
#include <libdevcore/Log.h>

3
libp2p/Host.cpp

@ -24,8 +24,11 @@
#include <chrono>
#include <thread>
#include <mutex>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/StructuredLogger.h>

3
libp2p/Host.h

@ -30,7 +30,10 @@
#include <utility>
#include <thread>
#include <chrono>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h>

28
libp2p/Network.cpp

@ -26,8 +26,10 @@
#include <ifaddrs.h>
#endif
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libethcore/Exceptions.h>
@ -47,7 +49,7 @@ std::vector<bi::address> Network::getInterfaceAddresses()
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
BOOST_THROW_EXCEPTION(NoNetworking());
char ac[80];
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR)
{
@ -55,7 +57,7 @@ std::vector<bi::address> Network::getInterfaceAddresses()
WSACleanup();
BOOST_THROW_EXCEPTION(NoNetworking());
}
struct hostent* phe = gethostbyname(ac);
if (phe == 0)
{
@ -63,7 +65,7 @@ std::vector<bi::address> Network::getInterfaceAddresses()
WSACleanup();
BOOST_THROW_EXCEPTION(NoNetworking());
}
for (int i = 0; phe->h_addr_list[i] != 0; ++i)
{
struct in_addr addr;
@ -73,18 +75,18 @@ std::vector<bi::address> Network::getInterfaceAddresses()
if (!isLocalHostAddress(address))
addresses.push_back(address.to_v4());
}
WSACleanup();
#else
ifaddrs* ifaddr;
if (getifaddrs(&ifaddr) == -1)
BOOST_THROW_EXCEPTION(NoNetworking());
for (auto ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if (!ifa->ifa_addr || string(ifa->ifa_name) == "lo0")
continue;
if (ifa->ifa_addr->sa_family == AF_INET)
{
in_addr addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
@ -103,12 +105,12 @@ std::vector<bi::address> Network::getInterfaceAddresses()
addresses.push_back(address);
}
}
if (ifaddr!=NULL)
freeifaddrs(ifaddr);
#endif
return std::move(addresses);
}
@ -135,7 +137,7 @@ int Network::tcp4Listen(bi::tcp::acceptor& _acceptor, unsigned short _listenPort
// both attempts failed
cwarn << "Couldn't start accepting connections on host. Something very wrong with network?\n" << boost::current_exception_diagnostic_information();
}
// first attempt failed
_acceptor.close();
continue;
@ -147,7 +149,7 @@ int Network::tcp4Listen(bi::tcp::acceptor& _acceptor, unsigned short _listenPort
bi::tcp::endpoint Network::traverseNAT(std::vector<bi::address> const& _ifAddresses, unsigned short _listenPort, bi::address& o_upnpifaddr)
{
asserts(_listenPort != 0);
UPnP* upnp = nullptr;
try
{
@ -155,7 +157,7 @@ bi::tcp::endpoint Network::traverseNAT(std::vector<bi::address> const& _ifAddres
}
// let m_upnp continue as null - we handle it properly.
catch (NoUPnPDevice) {}
bi::tcp::endpoint upnpep;
if (upnp && upnp->isValid())
{
@ -179,7 +181,7 @@ bi::tcp::endpoint Network::traverseNAT(std::vector<bi::address> const& _ifAddres
}
else
clog(NetWarn) << "Couldn't punch through NAT (or no NAT in place).";
if (upnp)
delete upnp;
}

15
libp2p/NodeTable.h

@ -1,16 +1,16 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
@ -23,8 +23,11 @@
#include <algorithm>
#include <deque>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/integer/static_log2.hpp>
#include <libp2p/UDP.h>
#include "Common.h"
@ -94,7 +97,7 @@ inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)
* obtain a list of potential nodes to connect to, and, passes events to
* Host whenever a node is added or removed to/from the table.
*
* Thread-safety is ensured by modifying NodeEntry details via
* Thread-safety is ensured by modifying NodeEntry details via
* shared_ptr replacement instead of mutating values.
*
* NodeTable accepts a port for UDP and will listen to the port on all available
@ -186,7 +189,7 @@ private:
static unsigned const s_bucketSize = 16; ///< Denoted by k in [Kademlia]. Number of nodes stored in each bucket.
static unsigned const s_alpha = 3; ///< Denoted by \alpha in [Kademlia]. Number of concurrent FindNode requests.
/// Intervals
/* todo: replace boost::posix_time; change constants to upper camelcase */
@ -361,7 +364,7 @@ struct FindNode: RLPXDatagram<FindNode>
h512 target;
unsigned expiration;
void streamRLP(RLPStream& _s) const { _s.appendList(2); _s << target << expiration; }
void interpretRLP(bytesConstRef _bytes) { RLP r(_bytes); target = r[0].toHash<h512>(); expiration = r[1].toInt<unsigned>(); }
};

3
libp2p/Session.h

@ -27,7 +27,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/RLP.h>
#include <libdevcore/RangeMask.h>

53
libp2p/UDP.h

@ -1,16 +1,16 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
@ -26,7 +26,10 @@
#include <vector>
#include <deque>
#include <array>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/Guards.h>
#include <libdevcrypto/Common.h>
#include <libdevcrypto/SHA3.h>
@ -50,7 +53,7 @@ public:
UDPDatagram(bi::udp::endpoint const& _ep): locus(_ep) {}
UDPDatagram(bi::udp::endpoint const& _ep, bytes _data): data(_data), locus(_ep) {}
bi::udp::endpoint const& endpoint() const { return locus; }
bytes data;
protected:
bi::udp::endpoint locus;
@ -98,7 +101,7 @@ struct UDPSocketEvents
virtual void onDisconnected(UDPSocketFace*) {};
virtual void onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytesConstRef _packetData) = 0;
};
/**
* @brief UDP Interface
* Handler must implement UDPSocketEvents.
@ -112,7 +115,7 @@ class UDPSocket: UDPSocketFace, public std::enable_shared_from_this<UDPSocket<Ha
public:
enum { maxDatagramSize = MaxDatagramSize };
static_assert(maxDatagramSize < 65507, "UDP datagrams cannot be larger than 65507 bytes");
UDPSocket(ba::io_service& _io, UDPSocketEvents& _host, unsigned _port): m_host(_host), m_endpoint(bi::udp::v4(), _port), m_socket(_io) { m_started.store(false); m_closed.store(true); };
virtual ~UDPSocket() { disconnect(); }
@ -121,32 +124,32 @@ public:
/// Send datagram.
bool send(UDPDatagram const& _datagram);
/// Returns if socket is open.
bool isOpen() { return !m_closed; }
/// Disconnect socket.
void disconnect() { disconnectWithError(boost::asio::error::connection_reset); }
protected:
void doRead();
void doWrite();
void disconnectWithError(boost::system::error_code _ec);
std::atomic<bool> m_started; ///< Atomically ensure connection is started once. Start cannot occur unless m_started is false. Managed by start and disconnectWithError.
std::atomic<bool> m_closed; ///< Connection availability.
UDPSocketEvents& m_host; ///< Interface which owns this socket.
bi::udp::endpoint m_endpoint; ///< Endpoint which we listen to.
Mutex x_sendQ;
std::deque<UDPDatagram> m_sendQ; ///< Queue for egress data.
std::array<byte, maxDatagramSize> m_recvData; ///< Buffer for ingress data.
bi::udp::endpoint m_recvEndpoint; ///< Endpoint data was received from.
bi::udp::socket m_socket; ///< Boost asio udp socket.
Mutex x_socketError; ///< Mutex for error which can be set from host or IO thread.
boost::system::error_code m_socketError; ///< Set when shut down due to error.
};
@ -157,29 +160,29 @@ void UDPSocket<Handler, MaxDatagramSize>::connect()
bool expect = false;
if (!m_started.compare_exchange_strong(expect, true))
return;
m_socket.open(bi::udp::v4());
m_socket.bind(m_endpoint);
// clear write queue so reconnect doesn't send stale messages
Guard l(x_sendQ);
m_sendQ.clear();
m_closed = false;
doRead();
}
template <typename Handler, unsigned MaxDatagramSize>
bool UDPSocket<Handler, MaxDatagramSize>::send(UDPDatagram const& _datagram)
{
if (m_closed)
return false;
Guard l(x_sendQ);
m_sendQ.push_back(_datagram);
if (m_sendQ.size() == 1)
doWrite();
return true;
}
@ -188,7 +191,7 @@ void UDPSocket<Handler, MaxDatagramSize>::doRead()
{
if (m_closed)
return;
auto self(UDPSocket<Handler, MaxDatagramSize>::shared_from_this());
m_socket.async_receive_from(boost::asio::buffer(m_recvData), m_recvEndpoint, [this, self](boost::system::error_code _ec, size_t _len)
{
@ -200,13 +203,13 @@ void UDPSocket<Handler, MaxDatagramSize>::doRead()
doRead();
});
}
template <typename Handler, unsigned MaxDatagramSize>
void UDPSocket<Handler, MaxDatagramSize>::doWrite()
{
if (m_closed)
return;
const UDPDatagram& datagram = m_sendQ[0];
auto self(UDPSocket<Handler, MaxDatagramSize>::shared_from_this());
m_socket.async_send_to(boost::asio::buffer(datagram.data), datagram.endpoint(), [this, self](boost::system::error_code _ec, std::size_t)
@ -245,11 +248,11 @@ void UDPSocket<Handler, MaxDatagramSize>::disconnectWithError(boost::system::err
bool expected = true;
if (!m_started.compare_exchange_strong(expected, false))
return;
// set m_closed to true to prevent undeliverable egress messages
bool wasClosed = m_closed;
m_closed = true;
// close sockets
boost::system::error_code ec;
m_socket.shutdown(bi::udp::socket::shutdown_both, ec);
@ -261,6 +264,6 @@ void UDPSocket<Handler, MaxDatagramSize>::disconnectWithError(boost::system::err
m_host.onDisconnected(this);
}
}
}

2
libweb3jsonrpc/WebThreeStubServer.cpp

@ -21,8 +21,10 @@
* @date 2014
*/
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <libwebthree/WebThree.h>
#include <libdevcrypto/FileSystem.h>
#include "WebThreeStubServer.h"

8
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -21,7 +21,9 @@
* @date 2014
*/
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libsolidity/CompilerStack.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/SourceReferenceFormatter.h>
@ -90,7 +92,7 @@ static Json::Value toJson(dev::eth::TransactionSkeleton const& _t)
static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e)
{
Json::Value res;
res["data"] = jsFromBinary(_e.data);
res["address"] = toJS(_e.address);
for (auto const& t: _e.topics)
@ -580,7 +582,7 @@ bool WebThreeStubServerBase::shh_post(Json::Value const& _json)
// TODO: insert validification hook here.
from = m_ids[m.from()];
}
face()->inject(toSealed(_json, m, from));
return true;
}
@ -648,7 +650,7 @@ Json::Value WebThreeStubServerBase::shh_changed(int _id)
continue;
ret.append(toJson(h, e, m));
}
return ret;
}

3
libwebthree/WebThree.cpp

@ -23,8 +23,11 @@
#include <chrono>
#include <thread>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <libdevcore/Log.h>
#include <libp2p/Host.h>
#include <libethereum/Defaults.h>

5
libwebthree/WebThree.h

@ -25,8 +25,11 @@
#include <mutex>
#include <list>
#include <atomic>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/utility.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/Guards.h>
@ -161,7 +164,7 @@ public:
/// Stop the network subsystem.
void stopNetwork() override { m_net.stop(); }
/// Is network working? there may not be any peers yet.
bool isNetworkStarted() const override { return m_net.isStarted(); }

3
libwhisper/Common.h

@ -23,7 +23,10 @@
#include <string>
#include <chrono>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/Log.h>
#include <libdevcore/RLP.h>

3
libwhisper/Interface.h

@ -26,7 +26,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libdevcrypto/SHA3.h>

3
libwhisper/Message.h

@ -26,7 +26,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libdevcrypto/Common.h>

3
libwhisper/WhisperHost.h

@ -26,7 +26,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/RLP.h>
#include <libdevcore/Worker.h>
#include <libdevcore/Guards.h>

3
libwhisper/WhisperPeer.h

@ -26,7 +26,10 @@
#include <set>
#include <memory>
#include <utility>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libdevcrypto/SHA3.h>

2
mix/AppContext.cpp

@ -22,7 +22,9 @@
* - KeyEventManager
*/
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QMessageBox>
#include <QClipboard>
#include <QQmlComponent>

2
mix/AppContext.h

@ -27,7 +27,9 @@
#pragma once
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <memory>
#include <QUrl>
#include <QObject>

2
mix/ClientModel.cpp

@ -18,7 +18,9 @@
* Ethereum IDE client.
*/
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QtConcurrent/QtConcurrent>
#include <QDebug>
#include <QQmlContext>

2
mix/CodeEditorExtensionManager.cpp

@ -20,7 +20,9 @@
* Ethereum IDE client.
*/
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QQuickItem>
#include <QGraphicsObject>
#include <QQmlEngine>

3
mix/Extension.cpp

@ -21,7 +21,10 @@
#include <QMessageBox>
#include <QDebug>
#include <QQmlApplicationEngine>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libevm/VM.h>
#include <libwebthree/WebThree.h>
#include "Extension.h"

2
mix/Extension.h

@ -19,7 +19,9 @@
#pragma once
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QApplication>
#include <QQmlComponent>

3
mix/QContractDefinition.cpp

@ -20,7 +20,10 @@
*/
#include <QObject>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <libsolidity/CompilerStack.h>
#include <libsolidity/AST.h>
#include <libsolidity/Scanner.h>

3
neth/main.cpp

@ -25,9 +25,12 @@
#include <fstream>
#include <iostream>
#include <signal.h>
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <libdevcrypto/FileSystem.h>
#include <libevmcore/Instruction.h>
#include <libethereum/All.h>

3
test/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>

3
test/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>

2
test/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>

3
test/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>

3
test/fork.cpp

@ -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>

7
test/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) );
}
}

30
test/net.cpp

@ -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;

145
test/rlp.cpp

@ -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);

2
test/state.cpp

@ -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>

3
test/trie.cpp

@ -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>

3
test/txTest.cpp

@ -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>

7
test/vm.cpp

@ -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;

3
test/vm.h

@ -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>

3
test/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>

Loading…
Cancel
Save