Bitcoin Core 22.99.0
P2P Digital Currency
i2p_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2021-2021 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <i2p.h>
6#include <netaddress.h>
7#include <test/util/logging.h>
8#include <test/util/net.h>
10#include <threadinterrupt.h>
11#include <util/system.h>
12
13#include <boost/test/unit_test.hpp>
14
15#include <memory>
16#include <string>
17
19
20BOOST_AUTO_TEST_CASE(unlimited_recv)
21{
22 auto CreateSockOrig = CreateSock;
23
24 // Mock CreateSock() to create MockSock.
25 CreateSock = [](const CService&) {
26 return std::make_unique<StaticContentsSock>(std::string(i2p::sam::MAX_MSG_SIZE + 1, 'a'));
27 };
28
29 CThreadInterrupt interrupt;
30 i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", CService{}, &interrupt);
31
32 {
33 ASSERT_DEBUG_LOG("Creating SAM session");
34 ASSERT_DEBUG_LOG("too many bytes without a terminator");
35
36 i2p::Connection conn;
37 bool proxy_error;
38 BOOST_REQUIRE(!session.Connect(CService{}, conn, proxy_error));
39 }
40
41 CreateSock = CreateSockOrig;
42}
43
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:288
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:523
I2P SAM session.
Definition: i2p.h:56
bool Connect(const CService &to, Connection &conn, bool &proxy_error)
Connect to an I2P peer.
Definition: i2p.cpp:173
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(unlimited_recv)
Definition: i2p_tests.cpp:20
static constexpr size_t MAX_MSG_SIZE
The maximum size of an incoming message from the I2P SAM proxy (in bytes).
Definition: i2p.h:50
std::function< std::unique_ptr< Sock >(const CService &)> CreateSock
Socket factory.
Definition: netbase.cpp:529
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
Basic testing setup.
Definition: setup_common.h:76
An established connection with another peer.
Definition: i2p.h:31
#define ASSERT_DEBUG_LOG(message)
Definition: logging.h:39
ArgsManager gArgs
Definition: system.cpp:85