-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updates to book_changes RPC command #5096
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
52cd63c
[FIX] #5034 -- book_changes rpc method accepts conventional ledger-st…
ckeshava 88ef02e
[FIX] #5035 - book_changes rpc method response includes a "validated"…
ckeshava a8a21bf
Merge branch 'develop' into bookChanges
Bronek e20f4a6
specify include header directives in BookChanges header file
ckeshava b2603ed
remove non-test-framework #includes from BookChanges_test file. This …
ckeshava 0651c04
Merge branch 'develop' into bookChanges
ckeshava f69b235
update API-changelog
ckeshava 39f56ab
Merge branch 'develop' into bookChanges
ckeshava 75cb233
Update API-CHANGELOG.md
ckeshava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of rippled: https://github.com/ripple/rippled | ||
Copyright (c) 2024 Ripple Labs Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#include <test/jtx.h> | ||
|
||
namespace ripple { | ||
namespace test { | ||
|
||
class BookChanges_test : public beast::unit_test::suite | ||
{ | ||
public: | ||
void | ||
testConventionalLedgerInputStrings() | ||
{ | ||
testcase("Specify well-known strings as ledger input"); | ||
jtx::Env env(*this); | ||
Json::Value params, resp; | ||
|
||
// As per convention in XRPL, ledgers can be specified with strings | ||
// "closed", "validated" or "current" | ||
params["ledger"] = "validated"; | ||
resp = env.rpc("json", "book_changes", to_string(params)); | ||
BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT(resp[jss::result][jss::status] == "success"); | ||
BEAST_EXPECT(resp[jss::result][jss::validated] == true); | ||
|
||
params["ledger"] = "current"; | ||
resp = env.rpc("json", "book_changes", to_string(params)); | ||
BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT(resp[jss::result][jss::status] == "success"); | ||
BEAST_EXPECT(resp[jss::result][jss::validated] == false); | ||
|
||
params["ledger"] = "closed"; | ||
resp = env.rpc("json", "book_changes", to_string(params)); | ||
BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT(resp[jss::result][jss::status] == "success"); | ||
|
||
// In the unit-test framework, requesting for "closed" ledgers appears | ||
// to yield "validated" ledgers. This is not new behavior. It is also | ||
// observed in the unit tests for the LedgerHeader class. | ||
BEAST_EXPECT(resp[jss::result][jss::validated] == true); | ||
|
||
// non-conventional ledger input should throw an error | ||
params["ledger"] = "non_conventional_ledger_input"; | ||
resp = env.rpc("json", "book_changes", to_string(params)); | ||
BEAST_EXPECT(resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT(resp[jss::result][jss::status] != "success"); | ||
} | ||
|
||
void | ||
testLedgerInputDefaultBehavior() | ||
{ | ||
testcase( | ||
"If ledger_hash or ledger_index is not specified, the behavior " | ||
"must default to the `current` ledger"); | ||
jtx::Env env(*this); | ||
|
||
// As per convention in XRPL, ledgers can be specified with strings | ||
// "closed", "validated" or "current" | ||
Json::Value const resp = | ||
env.rpc("json", "book_changes", to_string(Json::Value{})); | ||
BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); | ||
BEAST_EXPECT(resp[jss::result][jss::status] == "success"); | ||
|
||
// I dislike asserting the below statement, because its dependent on the | ||
// unit-test framework BEAST_EXPECT(resp[jss::result][jss::ledger_index] | ||
// == 3); | ||
} | ||
|
||
void | ||
run() override | ||
{ | ||
testConventionalLedgerInputStrings(); | ||
testLedgerInputDefaultBehavior(); | ||
|
||
// Note: Other aspects of the book_changes rpc are fertile grounds for | ||
// unit-testing purposes. It can be included in future work | ||
} | ||
}; | ||
|
||
BEAST_DEFINE_TESTSUITE(BookChanges, app, ripple); | ||
|
||
} // namespace test | ||
} // namespace ripple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LedgerRequest.cpp
and eliminate getLedgerByContext() entirely?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ledger_index
handling (and errors) will be the same as in almost every other command, since the vast majority of commands uselookupLedger
. However, since with this change, the ledger won't be requested from other nodes, if a ledger which is not in the local cache is requested, this method will fail withledgerNotFound
error (just like other methods do in such situation)ledger_request
which, with this PR, will be the only method usinggetLedgerByContext()
, and it needs to rely on this function in order to download the ledger from other nodes.