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