22 #include <boost/test/unit_test.hpp> 50 static std::string
name() {
return "test"; }
56 virtual bool interpret(
unsigned _id,
RLP const& _r)
override;
65 ++m_cntReceivedMessages;
66 m_testSum += _r[0].
toInt();
79 for (
auto i: peerSessions())
80 if (_id == i.second->id)
81 capabilityFromSession<TestCapability>(*i.first)->sendTestMessage(_x);
88 for (
auto i: peerSessions())
89 if (_id == i.second->id)
91 cnt += capabilityFromSession<TestCapability>(*i.first)->countReceivedMessages();
92 checksum += capabilityFromSession<TestCapability>(*i.first)->testSum();
95 return std::pair<int, int>(cnt, checksum);
103 if (test::Options::get().nonetwork)
107 cnote <<
"Testing Capability...";
110 const char*
const localhost =
"127.0.0.1";
113 Host host1(
"Test", prefs1);
114 Host host2(
"Test", prefs2);
121 BOOST_REQUIRE(port1);
122 BOOST_REQUIRE(port2);
123 BOOST_REQUIRE_NE(port1, port2);
125 for (
unsigned i = 0; i < 3000; i += step)
127 this_thread::sleep_for(chrono::milliseconds(step));
137 for (
unsigned i = 0; i < 12000; i += step)
139 this_thread::sleep_for(chrono::milliseconds(step));
147 int const target = 64;
149 for (
int i = 0; i < target; checksum += i++)
150 thc2->sendTestMessage(host1.
id(), i);
152 this_thread::sleep_for(chrono::seconds(target / 64 + 1));
153 std::pair<int, int> testData = thc1->retrieveTestData(host2.
id());
154 BOOST_REQUIRE_EQUAL(target, testData.first);
155 BOOST_REQUIRE_EQUAL(checksum, testData.second);
void sendTestMessage(NodeID const &_id, int _x)
virtual ~TestHostCapability()
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
static unsigned messageCount()
std::pair< std::string, u256 > CapDesc
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not t...
unsigned short listenPort() const
Get the port we're listening on currently.
std::hash for asio::adress
virtual ~TestCapability()
size_t peerCount() const
Get number of peers connected.
BOOST_AUTO_TEST_CASE(capability)
NodeID id() const
Get our current node ID.
void requirePeer(NodeID const &_node, NodeIPEndpoint const &_endpoint)
Create Peer and attempt keeping peer connected.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Temporary changes system's verbosity for specific function.
void start()
Start network. .
int countReceivedMessages()
std::shared_ptr< T > registerCapability(std::shared_ptr< T > const &_t)
Register a peer-capability; all new peer connections will have this capability.
TestCapability(std::shared_ptr< SessionFace > _s, HostCapabilityFace *_h, unsigned _idOffset, CapDesc const &, uint16_t _capID)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_AUTO_TEST_SUITE_END()
static std::string name()
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Class for writing to an RLP bytestream.
std::pair< int, int > retrieveTestData(NodeID const &_id)
Class for interpreting Recursive Linear-Prefix Data.
void sendTestMessage(int _i)
static bool test_allowLocal
Setting true causes isAllowed to return true for all addresses. (Used by test fixtures) ...
int m_cntReceivedMessages
Helper functions to work with json::spirit and test files.
virtual bool interpret(unsigned _id, RLP const &_r) override