xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
rpc
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
22
namespace
xrpl::test
{
23
24
class
RPCOverload_test
:
public
beast::unit_test::Suite
25
{
26
public
:
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
41
std::unique_ptr<AbstractClient>
client =
42
useWS ?
makeWSClient
(env.
app
().
config
()) :
makeJSONRPCClient
(env.
app
().
config
());
43
44
json::Value
tx =
json::ValueType::Object
;
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
84
BEAST_DEFINE_TESTSUITE
(RPCOverload,
rpc
,
xrpl
);
85
86
}
// namespace xrpl::test
std::string
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::fail
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition
suite.h:554
beast::unit_test::Suite::testcase
TestcaseT testcase
Memberspace for declaring test cases.
Definition
suite.h:155
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::Application::config
virtual Config & config()=0
xrpl::test::RPCOverload_test
Definition
RPCOverload_test.cpp:25
xrpl::test::RPCOverload_test::run
void run() override
Runs the suite.
Definition
RPCOverload_test.cpp:77
xrpl::test::RPCOverload_test::testOverload
void testOverload(bool useWS)
Definition
RPCOverload_test.cpp:28
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::app
Application & app()
Definition
Env.h:300
xrpl::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition
Env.cpp:323
memory
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl::rpc
API version numbers used in later API versions.
Definition
ApiVersion.h:36
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::pay
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition
pay.cpp:14
xrpl::test::jtx::XRP
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition
amount.cpp:92
xrpl::test::jtx::envconfig
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition
envconfig.h:38
xrpl::test::jtx::noAdmin
std::unique_ptr< Config > noAdmin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition
envconfig.cpp:75
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
xrpl::test::makeJSONRPCClient
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpcVersion)
Returns a client using JSON-RPC over HTTP/S.
Definition
JSONRPCClient.cpp:233
xrpl::test::makeWSClient
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:371
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition
AccountID.cpp:95
xrpl::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition
Seed.cpp:58
string
xrpl::Sections::kSigningSupport
static constexpr auto kSigningSupport
Definition
Constants.h:58
std::unique_ptr
utility
Generated by
1.17.0