Changeset View
Changeset View
Standalone View
Standalone View
src/test/net_tests.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | void Serialize(CDataStream &s) const override { | ||||
s << nKey; | s << nKey; | ||||
s << 10; // nNew | s << 10; // nNew | ||||
s << 10; // nTried | s << 10; // nTried | ||||
int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30); | int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30); | ||||
s << nUBuckets; | s << nUBuckets; | ||||
CService serv; | CService serv; | ||||
Lookup("252.1.1.1", serv, 7777, false); | BOOST_CHECK(Lookup("252.1.1.1", serv, 7777, false)); | ||||
CAddress addr = CAddress(serv, NODE_NONE); | CAddress addr = CAddress(serv, NODE_NONE); | ||||
CNetAddr resolved; | CNetAddr resolved; | ||||
LookupHost("252.2.2.2", resolved, false); | BOOST_CHECK(LookupHost("252.2.2.2", resolved, false)); | ||||
CAddrInfo info = CAddrInfo(addr, resolved); | CAddrInfo info = CAddrInfo(addr, resolved); | ||||
s << info; | s << info; | ||||
} | } | ||||
}; | }; | ||||
class NetTestConfig : public DummyConfig { | class NetTestConfig : public DummyConfig { | ||||
public: | public: | ||||
bool SetMaxBlockSize(uint64_t maxBlockSize) override { | bool SetMaxBlockSize(uint64_t maxBlockSize) override { | ||||
Show All 18 Lines | |||||
BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup) | ||||
BOOST_AUTO_TEST_CASE(cnode_listen_port) { | BOOST_AUTO_TEST_CASE(cnode_listen_port) { | ||||
// test default | // test default | ||||
unsigned short port = GetListenPort(); | unsigned short port = GetListenPort(); | ||||
BOOST_CHECK(port == Params().GetDefaultPort()); | BOOST_CHECK(port == Params().GetDefaultPort()); | ||||
// test set port | // test set port | ||||
unsigned short altPort = 12345; | unsigned short altPort = 12345; | ||||
gArgs.SoftSetArg("-port", std::to_string(altPort)); | BOOST_CHECK(gArgs.SoftSetArg("-port", std::to_string(altPort))); | ||||
port = GetListenPort(); | port = GetListenPort(); | ||||
BOOST_CHECK(port == altPort); | BOOST_CHECK(port == altPort); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(caddrdb_read) { | BOOST_AUTO_TEST_CASE(caddrdb_read) { | ||||
CAddrManUncorrupted addrmanUncorrupted; | CAddrManUncorrupted addrmanUncorrupted; | ||||
addrmanUncorrupted.MakeDeterministic(); | addrmanUncorrupted.MakeDeterministic(); | ||||
CService addr1, addr2, addr3; | CService addr1, addr2, addr3; | ||||
Lookup("250.7.1.1", addr1, 8333, false); | BOOST_CHECK(Lookup("250.7.1.1", addr1, 8333, false)); | ||||
Lookup("250.7.2.2", addr2, 9999, false); | BOOST_CHECK(Lookup("250.7.2.2", addr2, 9999, false)); | ||||
Lookup("250.7.3.3", addr3, 9999, false); | BOOST_CHECK(Lookup("250.7.3.3", addr3, 9999, false)); | ||||
// Add three addresses to new table. | // Add three addresses to new table. | ||||
CService source; | CService source; | ||||
Lookup("252.5.1.1", source, 8333, false); | BOOST_CHECK(Lookup("252.5.1.1", source, 8333, false)); | ||||
addrmanUncorrupted.Add(CAddress(addr1, NODE_NONE), source); | BOOST_CHECK(addrmanUncorrupted.Add(CAddress(addr1, NODE_NONE), source)); | ||||
addrmanUncorrupted.Add(CAddress(addr2, NODE_NONE), source); | BOOST_CHECK(addrmanUncorrupted.Add(CAddress(addr2, NODE_NONE), source)); | ||||
addrmanUncorrupted.Add(CAddress(addr3, NODE_NONE), source); | BOOST_CHECK(addrmanUncorrupted.Add(CAddress(addr3, NODE_NONE), source)); | ||||
// Test that the de-serialization does not throw an exception. | // Test that the de-serialization does not throw an exception. | ||||
CDataStream ssPeers1 = AddrmanToStream(addrmanUncorrupted); | CDataStream ssPeers1 = AddrmanToStream(addrmanUncorrupted); | ||||
bool exceptionThrown = false; | bool exceptionThrown = false; | ||||
CAddrMan addrman1; | CAddrMan addrman1; | ||||
BOOST_CHECK(addrman1.size() == 0); | BOOST_CHECK(addrman1.size() == 0); | ||||
try { | try { | ||||
Show All 9 Lines | BOOST_AUTO_TEST_CASE(caddrdb_read) { | ||||
// Test that CAddrDB::Read creates an addrman with the correct number of | // Test that CAddrDB::Read creates an addrman with the correct number of | ||||
// addrs. | // addrs. | ||||
CDataStream ssPeers2 = AddrmanToStream(addrmanUncorrupted); | CDataStream ssPeers2 = AddrmanToStream(addrmanUncorrupted); | ||||
CAddrMan addrman2; | CAddrMan addrman2; | ||||
CAddrDB adb(Params()); | CAddrDB adb(Params()); | ||||
BOOST_CHECK(addrman2.size() == 0); | BOOST_CHECK(addrman2.size() == 0); | ||||
adb.Read(addrman2, ssPeers2); | BOOST_CHECK(adb.Read(addrman2, ssPeers2)); | ||||
BOOST_CHECK(addrman2.size() == 3); | BOOST_CHECK(addrman2.size() == 3); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted) { | BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted) { | ||||
CAddrManCorrupted addrmanCorrupted; | CAddrManCorrupted addrmanCorrupted; | ||||
addrmanCorrupted.MakeDeterministic(); | addrmanCorrupted.MakeDeterministic(); | ||||
// Test that the de-serialization of corrupted addrman throws an exception. | // Test that the de-serialization of corrupted addrman throws an exception. | ||||
Show All 15 Lines | BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted) { | ||||
// Test that CAddrDB::Read leaves addrman in a clean state if | // Test that CAddrDB::Read leaves addrman in a clean state if | ||||
// de-serialization fails. | // de-serialization fails. | ||||
CDataStream ssPeers2 = AddrmanToStream(addrmanCorrupted); | CDataStream ssPeers2 = AddrmanToStream(addrmanCorrupted); | ||||
CAddrMan addrman2; | CAddrMan addrman2; | ||||
CAddrDB adb(Params()); | CAddrDB adb(Params()); | ||||
BOOST_CHECK(addrman2.size() == 0); | BOOST_CHECK(addrman2.size() == 0); | ||||
adb.Read(addrman2, ssPeers2); | BOOST_CHECK(!adb.Read(addrman2, ssPeers2)); | ||||
BOOST_CHECK(addrman2.size() == 0); | BOOST_CHECK(addrman2.size() == 0); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(cnode_simple_test) { | BOOST_AUTO_TEST_CASE(cnode_simple_test) { | ||||
SOCKET hSocket = INVALID_SOCKET; | SOCKET hSocket = INVALID_SOCKET; | ||||
NodeId id = 0; | NodeId id = 0; | ||||
int height = 0; | int height = 0; | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |