xrpld
Loading...
Searching...
No Matches
RPCOverload_test.cpp
1#include <test/jtx/AbstractClient.h>
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/JSONRPCClient.h>
5#include <test/jtx/WSClient.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/envconfig.h>
8#include <test/jtx/pay.h>
9
10#include <xrpld/core/Config.h>
11
12#include <xrpl/beast/unit_test/suite.h>
13#include <xrpl/config/Constants.h>
14#include <xrpl/json/json_value.h>
15#include <xrpl/protocol/Seed.h>
16#include <xrpl/protocol/jss.h>
17
18#include <memory>
19#include <string>
20#include <utility>
21
22namespace xrpl::test {
23
25{
26public:
27 void
28 testOverload(bool useWS)
29 {
30 testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client";
31 using namespace jtx;
32 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
33 cfg->loadFromString(std::string("[") + Sections::kSigningSupport + "]\ntrue");
34 return noAdmin(std::move(cfg));
35 })};
36
37 Account const alice{"alice"};
38 Account const bob{"bob"};
39 env.fund(XRP(10000), alice, bob);
40
42 useWS ? makeWSClient(env.app().config()) : makeJSONRPCClient(env.app().config());
43
45 tx[jss::tx_json] = pay(alice, bob, XRP(1));
46 tx[jss::secret] = toBase58(generateSeed("alice"));
47
48 // Ask the server to repeatedly sign this transaction
49 // Signing is a resource heavy transaction, so we want the server
50 // to warn and eventually boot us.
51 bool warned = false, booted = false;
52 for (int i = 0; i < 500 && !booted; ++i)
53 {
54 auto jv = client->invoke("sign", tx);
55 if (!useWS)
56 jv = jv[jss::result];
57 // When booted, we just get a null json response
58 if (jv.isNull())
59 {
60 booted = true;
61 }
62 else if (!(jv.isMember(jss::status) && (jv[jss::status] == "success")))
63 {
64 // Don't use BEAST_EXPECT above b/c it will be called a
65 // non-deterministic number of times and the number of tests run
66 // should be deterministic
67 fail("", __FILE__, __LINE__);
68 }
69
70 if (jv.isMember(jss::warning))
71 warned = jv[jss::warning] == jss::load;
72 }
73 BEAST_EXPECT(warned && booted);
74 }
75
76 void
77 run() override
78 {
79 testOverload(false /* http */);
80 testOverload(true /* ws */);
81 }
82};
83
84BEAST_DEFINE_TESTSUITE(RPCOverload, rpc, xrpl);
85
86} // namespace xrpl::test
A testsuite class.
Definition suite.h:50
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition suite.h:522
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
Represents a JSON value.
Definition json_value.h:130
virtual Config & config()=0
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
A transaction testing environment.
Definition Env.h:143
Application & app()
Definition Env.h:280
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
@ Object
object value (collection of name/value pairs).
Definition json_value.h:26
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:28
std::unique_ptr< Config > noAdmin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:64
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpcVersion)
Returns a client using JSON-RPC over HTTP/S.
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
Definition WSClient.cpp:329
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:58
static constexpr auto kSigningSupport
Definition Constants.h:57