rippled
Loading...
Searching...
No Matches
BookChanges_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx.h>
21
22namespace ripple {
23namespace test {
24
26{
27public:
28 void
30 {
31 testcase("Specify well-known strings as ledger input");
32 jtx::Env env(*this);
33 Json::Value params, resp;
34
35 // As per convention in XRPL, ledgers can be specified with strings
36 // "closed", "validated" or "current"
37 params["ledger"] = "validated";
38 resp = env.rpc("json", "book_changes", to_string(params));
39 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
40 BEAST_EXPECT(resp[jss::result][jss::status] == "success");
41 BEAST_EXPECT(resp[jss::result][jss::validated] == true);
42
43 params["ledger"] = "current";
44 resp = env.rpc("json", "book_changes", to_string(params));
45 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
46 BEAST_EXPECT(resp[jss::result][jss::status] == "success");
47 BEAST_EXPECT(resp[jss::result][jss::validated] == false);
48
49 params["ledger"] = "closed";
50 resp = env.rpc("json", "book_changes", to_string(params));
51 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
52 BEAST_EXPECT(resp[jss::result][jss::status] == "success");
53
54 // In the unit-test framework, requesting for "closed" ledgers appears
55 // to yield "validated" ledgers. This is not new behavior. It is also
56 // observed in the unit tests for the LedgerHeader class.
57 BEAST_EXPECT(resp[jss::result][jss::validated] == true);
58
59 // non-conventional ledger input should throw an error
60 params["ledger"] = "non_conventional_ledger_input";
61 resp = env.rpc("json", "book_changes", to_string(params));
62 BEAST_EXPECT(resp[jss::result].isMember(jss::error));
63 BEAST_EXPECT(resp[jss::result][jss::status] != "success");
64 }
65
66 void
68 {
70 "If ledger_hash or ledger_index is not specified, the behavior "
71 "must default to the `current` ledger");
72 jtx::Env env(*this);
73
74 // As per convention in XRPL, ledgers can be specified with strings
75 // "closed", "validated" or "current"
76 Json::Value const resp =
77 env.rpc("json", "book_changes", to_string(Json::Value{}));
78 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
79 BEAST_EXPECT(resp[jss::result][jss::status] == "success");
80
81 // I dislike asserting the below statement, because its dependent on the
82 // unit-test framework BEAST_EXPECT(resp[jss::result][jss::ledger_index]
83 // == 3);
84 }
85
86 void
87 run() override
88 {
91
92 // Note: Other aspects of the book_changes rpc are fertile grounds for
93 // unit-testing purposes. It can be included in future work
94 }
95};
96
97BEAST_DEFINE_TESTSUITE(BookChanges, app, ripple);
98
99} // namespace test
100} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
A testsuite class.
Definition: suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
void run() override
Runs the suite.
A transaction testing environment.
Definition: Env.h:120
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition: Env.h:769
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630