rippled
Loading...
Searching...
No Matches
RPCOverload_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted, provided that the above
7 copyright notice and this permission notice appear in all copies.
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16//==============================================================================
17
18#include <test/jtx.h>
19#include <test/jtx/JSONRPCClient.h>
20#include <test/jtx/WSClient.h>
21
22#include <xrpld/core/ConfigSections.h>
23
24#include <xrpl/beast/unit_test.h>
25#include <xrpl/protocol/jss.h>
26
27namespace ripple {
28namespace test {
29
31{
32public:
33 void
34 testOverload(bool useWS)
35 {
36 testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client";
37 using namespace jtx;
38 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
39 cfg->loadFromString("[" SECTION_SIGNING_SUPPORT "]\ntrue");
40 return no_admin(std::move(cfg));
41 })};
42
43 Account const alice{"alice"};
44 Account const bob{"bob"};
45 env.fund(XRP(10000), alice, bob);
46
48 ? makeWSClient(env.app().config())
49 : makeJSONRPCClient(env.app().config());
50
52 tx[jss::tx_json] = pay(alice, bob, XRP(1));
53 tx[jss::secret] = toBase58(generateSeed("alice"));
54
55 // Ask the server to repeatedly sign this transaction
56 // Signing is a resource heavy transaction, so we want the server
57 // to warn and eventually boot us.
58 bool warned = false, booted = false;
59 for (int i = 0; i < 500 && !booted; ++i)
60 {
61 auto jv = client->invoke("sign", tx);
62 if (!useWS)
63 jv = jv[jss::result];
64 // When booted, we just get a null json response
65 if (jv.isNull())
66 booted = true;
67 else if (!(jv.isMember(jss::status) &&
68 (jv[jss::status] == "success")))
69 {
70 // Don't use BEAST_EXPECT above b/c it will be called a
71 // non-deterministic number of times and the number of tests run
72 // should be deterministic
73 fail("", __FILE__, __LINE__);
74 }
75
76 if (jv.isMember(jss::warning))
77 warned = jv[jss::warning] == jss::load;
78 }
79 BEAST_EXPECT(warned && booted);
80 }
81
82 void
83 run() override
84 {
85 testOverload(false /* http */);
86 testOverload(true /* ws */);
87 }
88};
89
90BEAST_DEFINE_TESTSUITE(RPCOverload, app, ripple);
91
92} // namespace test
93} // namespace ripple
Represents a JSON value.
Definition: json_value.h:149
A testsuite class.
Definition: suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition: suite.h:533
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:121
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:45
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition: envconfig.cpp:76
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:30
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:54
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
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:302
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:25
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:114
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:76