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 xrpl {
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 useWS ? makeWSClient(env.app().config()) : makeJSONRPCClient(env.app().config());
32
34 tx[jss::tx_json] = pay(alice, bob, XRP(1));
35 tx[jss::secret] = toBase58(generateSeed("alice"));
36
37 // Ask the server to repeatedly sign this transaction
38 // Signing is a resource heavy transaction, so we want the server
39 // to warn and eventually boot us.
40 bool warned = false, booted = false;
41 for (int i = 0; i < 500 && !booted; ++i)
42 {
43 auto jv = client->invoke("sign", tx);
44 if (!useWS)
45 jv = jv[jss::result];
46 // When booted, we just get a null json response
47 if (jv.isNull())
48 booted = true;
49 else if (!(jv.isMember(jss::status) && (jv[jss::status] == "success")))
50 {
51 // Don't use BEAST_EXPECT above b/c it will be called a
52 // non-deterministic number of times and the number of tests run
53 // should be deterministic
54 fail("", __FILE__, __LINE__);
55 }
56
57 if (jv.isMember(jss::warning))
58 warned = jv[jss::warning] == jss::load;
59 }
60 BEAST_EXPECT(warned && booted);
61 }
62
63 void
64 run() override
65 {
66 testOverload(false /* http */);
67 testOverload(true /* ws */);
68 }
69};
70
71BEAST_DEFINE_TESTSUITE(RPCOverload, rpc, xrpl);
72
73} // namespace test
74} // namespace xrpl
Represents a JSON value.
Definition json_value.h:131
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:148
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition suite.h:517
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:98
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:27
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:90
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
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:57
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpc_version)
Returns a client using JSON-RPC over HTTP/S.
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:285
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:92
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:57