8000 refactor: clean up `LedgerEntry.cpp` by mvadari · Pull Request #5199 · XRPLF/rippled · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: clean up LedgerEntry.cpp #5199

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

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions API-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ The [commandline](https://xrpl.org/docs/references/http-websocket-apis/api-conve

The `network_id` field was added in the `server_info` response in version 1.5.0 (2019), but it is not returned in [reporting mode](https://xrpl.org/rippled-server-modes.html#reporting-mode). However, use of reporting mode is now discouraged, in favor of using [Clio](https://github.com/XRPLF/clio) instead.

## XRP Ledger server version 2.2.0
## XRP Ledger server version 2.4.0

The following is a non-breaking addition to the API.
### Addition in 2.4

- The `feature` method now has a non-admin mode for users. (It was previously only available to admin connections.) The method returns an updated list of amendments, including their names and other information. ([#4781](https://github.com/XRPLF/rippled/pull/4781))
- `ledger_entry`: `state` is added an alias for `ripple_state`.

## XRP Ledger server version 2.3.0

### Breaking change in 2.3

Expand All @@ -105,6 +107,12 @@ The following additions are non-breaking (because they are purely additive).
- In `Payment` transactions, `DeliverMax` has been added. This is a replacement for the `Amount` field, which should not be used. Typically, the `delivered_amount` (in transaction metadata) should be used. To ease the transition, `DeliverMax` is present regardless of API version, since adding a field is non-breaking.
- API version 2 has been moved from beta to supported, meaning that it is generally available (regardless of the `beta_rpc_api` setting).

## XRP Ledger server version 2.2.0

The following is a non-breaking addition to the API.

- The `feature` method now has a non-admin mode for users. (It was previously only available to admin connections.) The method returns an updated list of amendments, including their names and other information. ([#4781](https://github.com/XRPLF/rippled/pull/4781))

## XRP Ledger server version 1.12.0

[Version 1.12.0](https://github.com/XRPLF/rippled/releases/tag/1.12.0) was released on Sep 6, 2023. The following additions are non-breaking (because they are purely additive).
Expand Down
338 changes: 185 additions & 153 deletions src/test/rpc/LedgerRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,160 +1877,164 @@ class LedgerRPC_test : public beast::unit_test::suite
env(pay(gw, alice, USD(97)));
env.close();

std::string const ledgerHash{to_string(env.closed()->info().hash)};
{
// Request the trust line using the accounts and currency.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfBalance.jsonName][jss::value] == "-97");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.jsonName][jss::value] == "999");
}
{
// ripple_state is not an object.
Json::Value jvParams;
jvParams[jss::ripple_state] = "ripple_state";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state.currency is missing.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state accounts is not an array.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = 2;
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state one of the accounts is missing.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state more than 2 accounts.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ripple_state][jss::accounts][2u] = alice.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
// check both aliases
for (auto const& fieldName : {jss::ripple_state, jss::state})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were only updated to cover the two aliases, and are otherwise completely unchanged.

{
// ripple_state account[0] is not a string.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = 44;
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state account[1] is not a string.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = 21;
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state account[0] == account[1].
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = alice.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state malformed account[0].
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] =
makeBadAddress(alice.human());
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedAddress", "");
}
{
// ripple_state malformed account[1].
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] =
makeBadAddress(gw.human());
jvParams[jss::ripple_state][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedAddress", "");
}
{
// ripple_state malformed currency.
Json::Value jvParams;
jvParams[jss::ripple_state] = Json::objectValue;
jvParams[jss::ripple_state][jss::accounts] = Json::arrayValue;
jvParams[jss::ripple_state][jss::accounts][0u] = alice.human();
jvParams[jss::ripple_state][jss::accounts][1u] = gw.human();
jvParams[jss::ripple_state][jss::currency] = "USDollars";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedCurrency", "");
std::string const ledgerHash{to_string(env.closed()->info().hash)};
{
// Request the trust line using the accounts and currency.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfBalance.jsonName][jss::value] == "-97");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.jsonName][jss::value] == "999");
}
{
// ripple_state is not an object.
Json::Value jvParams;
jvParams[fieldName] = "ripple_state";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state.currency is missing.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state accounts is not an array.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = 2;
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state one of the accounts is missing.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state more than 2 accounts.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[fieldName][jss::accounts][2u] = alice.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state account[0] is not a string.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = 44;
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state account[1] is not a string.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = 21;
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state account[0] == account[1].
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = alice.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// ripple_state malformed account[0].
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] =
makeBadAddress(alice.human());
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedAddress", "");
}
{
// ripple_state malformed account[1].
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] =
makeBadAddress(gw.human());
jvParams[fieldName][jss::currency] = "USD";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedAddress", "");
}
{
// ripple_state malformed currency.
Json::Value jvParams;
jvParams[fieldName] = Json::objectValue;
jvParams[fieldName][jss::accounts] = Json::arrayValue;
jvParams[fieldName][jss::accounts][0u] = alice.human();
jvParams[fieldName][jss::accounts][1u] = gw.human();
jvParams[fieldName][jss::currency] = "USDollars";
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedCurrency", "");
}
}
}

Expand Down Expand Up @@ -3055,6 +3059,33 @@ class LedgerRPC_test : public beast::unit_test::suite
}
}

void
testLedgerEntryCLI()
{
testcase("ledger_entry command-line");
using namespace test::jtx;

Env env{*this};
Account const alice{"alice"};
env.fund(XRP(10000), alice);
env.close();

auto const checkId = keylet::check(env.master, env.seq(env.master));

env(check::create(env.master, alice, XRP(100)));
env.close();

std::string const ledgerHash{to_string(env.closed()->info().hash)};
{
// Request a check.
Json::Value const jrr =
env.rpc("ledger_entry", to_string(checkId.key))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] == "100000000");
}
}

public:
void
run() override
Expand Down Expand Up @@ -3085,6 +3116,7 @@ class LedgerRPC_test : public beast::unit_test::suite
testInvalidOracleLedgerEntry();
testOracleLedgerEntry();
testLedgerEntryMPT();
testLedgerEntryCLI();

forAllApiVersions(std::bind_front(
&LedgerRPC_test::testLedgerEntryInvalidParams, this));
Expand Down
Loading
Loading
0