xrpld
Loading...
Searching...
No Matches
TMTransactions_test.cpp
1#include <test/jtx/CheckMessageLogs.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/envconfig.h>
4#include <test/overlay/CapturePeer.h>
5
6#include <xrpld/overlay/ReduceRelayCommon.h>
7#include <xrpld/overlay/detail/Handshake.h>
8
9#include <xrpl/beast/unit_test/suite.h>
10#include <xrpl/resource/Fees.h>
11#include <xrpl/server/Handoff.h>
12
13#include <xrpl.pb.h>
14
15#include <cstddef>
16#include <memory>
17#include <optional>
18#include <utility>
19
20namespace xrpl::test {
21
22using namespace jtx;
23
25{
27 createRequest(std::size_t const numTransactions)
28 {
30 for (std::size_t i = 0; i < numTransactions; ++i)
31 {
32 request->mutable_transactions()->Add(protocol::TMTransaction{});
33 }
34 return request;
35 }
36
37 void
38 testTransactionCountAccepted(std::size_t const numTransactions, bool const expectRejected)
39 {
40 testcase("Transaction Count Accepted");
41
42 static constexpr auto kLimitExceededMessage = "TMTransactions: transaction list too large";
43 auto foundExpectedLog = false;
44 Env env{
45 *this,
46 envconfig(),
47 std::make_unique<CheckMessageLogs>(kLimitExceededMessage, &foundExpectedLog)};
48
49 // `PeerImp` decides `txReduceRelayEnabled()` in its constructor, from
50 // the config and the handshake header, so set this first.
51 env.app().config().txReduceRelayEnable = true;
52 HttpRequestType request;
53 request.insert("X-Protocol-Ctl", makeFeaturesRequestHeader(false, false, true, false));
54
55 auto peer = makeCapturePeer(env, std::nullopt, std::move(request));
56 peer->onMessage(createRequest(numTransactions));
57
58 auto fee = peer->feeCharge();
59 if (expectRejected)
60 {
61 BEAST_EXPECT(fee == resource::kFeeMalformedRequest);
62 BEAST_EXPECT(foundExpectedLog);
63 }
64 else
65 {
66 BEAST_EXPECT(!foundExpectedLog);
67 }
68 }
69
70 void
71 run() override
72 {
73 auto const limit = reduce_relay::kMaxTxQueueSize;
74 testTransactionCountAccepted(limit + 1, true);
75 testTransactionCountAccepted(limit, false);
76 testTransactionCountAccepted(limit - 1, false);
77 }
78};
79
80BEAST_DEFINE_TESTSUITE(TMTransactions, overlay, xrpl);
81
82} // namespace xrpl::test
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
virtual Config & config()=0
bool txReduceRelayEnable
////////////// END OF TEMPORARY CODE BLOCK /////////////////////
void testTransactionCountAccepted(std::size_t const numTransactions, bool const expectRejected)
void run() override
Runs the suite.
static std::shared_ptr< protocol::TMTransactions > createRequest(std::size_t const numTransactions)
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
T make_shared(T... args)
T make_unique(T... args)
static constexpr std::size_t kMaxTxQueueSize
Charge const kFeeMalformedRequest
Schedule of fees charged for imposing load on the server.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
std::shared_ptr< PeerType > makeCapturePeer(jtx::Env &env, std::optional< PublicKey > key=std::nullopt, HttpRequestType request={})
Build an active CapturePeer and register it with the overlay.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
boost::beast::http::request< boost::beast::http::dynamic_body > HttpRequestType
Definition Handoff.h:12
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
Definition Handshake.cpp:83