mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Add tests for BoostAsioToCNetAddr
This commit is contained in:
parent
fdbd7075ca
commit
21bf3d257b
@ -359,8 +359,7 @@ void ErrorReply(std::ostream& stream, const Object& objError, const Value& id)
|
|||||||
stream << HTTPReply(nStatus, strReply, false) << std::flush;
|
stream << HTTPReply(nStatus, strReply, false) << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert boost::asio address to CNetAddr
|
CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address)
|
||||||
static CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address)
|
|
||||||
{
|
{
|
||||||
CNetAddr netaddr;
|
CNetAddr netaddr;
|
||||||
// Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
|
// Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "json/json_spirit_writer_template.h"
|
#include "json/json_spirit_writer_template.h"
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
|
class CNetAddr;
|
||||||
|
|
||||||
/* Start RPC threads */
|
/* Start RPC threads */
|
||||||
void StartRPCThreads();
|
void StartRPCThreads();
|
||||||
@ -50,6 +51,9 @@ void RPCTypeCheck(const json_spirit::Object& o,
|
|||||||
*/
|
*/
|
||||||
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
|
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
|
||||||
|
|
||||||
|
//! Convert boost::asio address to CNetAddr
|
||||||
|
extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address);
|
||||||
|
|
||||||
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
||||||
|
|
||||||
class CRPCCommand
|
class CRPCCommand
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "rpcclient.h"
|
#include "rpcclient.h"
|
||||||
|
|
||||||
#include "base58.h"
|
#include "base58.h"
|
||||||
|
#include "netbase.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
@ -138,4 +139,19 @@ BOOST_AUTO_TEST_CASE(rpc_parse_monetary_values)
|
|||||||
BOOST_CHECK(AmountFromValue(ValueFromString("20999999.99999999")) == 2099999999999999LL);
|
BOOST_CHECK(AmountFromValue(ValueFromString("20999999.99999999")) == 2099999999999999LL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(rpc_boostasiotocnetaddr)
|
||||||
|
{
|
||||||
|
// Check IPv4 addresses
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("1.2.3.4")).ToString(), "1.2.3.4");
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("127.0.0.1")).ToString(), "127.0.0.1");
|
||||||
|
// Check IPv6 addresses
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("::1")).ToString(), "::1");
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("123:4567:89ab:cdef:123:4567:89ab:cdef")).ToString(),
|
||||||
|
"123:4567:89ab:cdef:123:4567:89ab:cdef");
|
||||||
|
// v4 compatible must be interpreted as IPv4
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("::0:127.0.0.1")).ToString(), "127.0.0.1");
|
||||||
|
// v4 mapped must be interpreted as IPv4
|
||||||
|
BOOST_CHECK_EQUAL(BoostAsioToCNetAddr(boost::asio::ip::address::from_string("::ffff:127.0.0.1")).ToString(), "127.0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user