Skip to content

Commit

Permalink
fix: no restriction on type field (#1644)
Browse files Browse the repository at this point in the history
'type' should not matter if 'full' or 'accounts' is false. Relax the
restriction for 'type'
  • Loading branch information
cindyyan317 committed Sep 11, 2024
1 parent bb0d912 commit f57706b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/rpc/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,11 @@ isAdminCmd(std::string const& method, boost::json::object const& request)
// https://github.com/XRPLF/rippled/issues/5119
auto const isFieldSet = [&jv](auto const field) { return jv.isMember(field) and jv[field].asBool(); };

if (isFieldSet(JS(full)) or isFieldSet(JS(accounts)) or isFieldSet(JS(type)))
// According to doc
// https://xrpl.org/docs/references/http-websocket-apis/public-api-methods/ledger-methods/ledger,
// full/accounts/type are admin only, but type only works when full/accounts are set, so we don't need to check
// type.
if (isFieldSet(JS(full)) or isFieldSet(JS(accounts)))
return true;
}

Expand Down
17 changes: 2 additions & 15 deletions tests/unit/rpc/RPCHelpersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ generateTestValuesForParametersTest()
{"featureVetoedIsStr", "feature", R"({"vetoed": "String"})", true},

{"ledger", "ledger", R"({})", false},
{"ledgerWithType", "ledger", R"({"type": "fee"})", false},
{"ledgerFullTrue", "ledger", R"({"full": true})", true},
{"ledgerFullFalse", "ledger", R"({"full": false})", false},
{"ledgerFullIsStr", "ledger", R"({"full": "String"})", true},
Expand All @@ -574,25 +575,11 @@ generateTestValuesForParametersTest()
{"ledgerFullIsObject", "ledger", R"({"full": {"key": 1}})", true},
{"ledgerFullIsEmptyObject", "ledger", R"({"full": {}})", false},

{"ledgerTypeTrue", "ledger", R"({"type": true})", true},
{"ledgerTypeFalse", "ledger", R"({"type": false})", false},
{"ledgerTypeIsStr", "ledger", R"({"type": "String"})", true},
{"ledgerTypeIsEmptyStr", "ledger", R"({"type": ""})", false},
{"ledgerTypeIsNumber1", "ledger", R"({"type": 1})", true},
{"ledgerTypeIsNumber0", "ledger", R"({"type": 0})", false},
{"ledgerTypeIsNull", "ledger", R"({"type": null})", false},
{"ledgerTypeIsFloat0", "ledger", R"({"type": 0.0})", false},
{"ledgerTypeIsFloat1", "ledger", R"({"type": 0.1})", true},
{"ledgerTypeIsArray", "ledger", R"({"type": [1]})", true},
{"ledgerTypeIsEmptyArray", "ledger", R"({"type": []})", false},
{"ledgerTypeIsObject", "ledger", R"({"type": {"key": 1}})", true},
{"ledgerTypeIsEmptyObject", "ledger", R"({"type": {}})", false},

{"ledgerAccountsTrue", "ledger", R"({"accounts": true})", true},
{"ledgerAccountsFalse", "ledger", R"({"accounts": false})", false},
{"ledgerAccountsIsStr", "ledger", R"({"accounts": "String"})", true},
{"ledgerAccountsIsEmptyStr", "ledger", R"({"accounts": ""})", false},
{"ledgerAccountsIsNumber1", "ledger", R"({"type": 1})", true},
{"ledgerAccountsIsNumber1", "ledger", R"({"accounts": 1})", true},
{"ledgerAccountsIsNumber0", "ledger", R"({"accounts": 0})", false},
{"ledgerAccountsIsNull", "ledger", R"({"accounts": null})", false},
{"ledgerAccountsIsFloat0", "ledger", R"({"accounts": 0.0})", false},
Expand Down

0 comments on commit f57706b

Please sign in to comment.