Skip to content
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

Additional support in ledger_entry #5236

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
312 changes: 311 additions & 1 deletion src/test/rpc/LedgerRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,46 @@ class LedgerRPC_test : public beast::unit_test::suite
}
}

void
testLedgerEntryAmendments()
{
testcase("ledger_entry Request Amendments");
using namespace test::jtx;

Env env{*this, envconfig(validator, ""), supported_amendments()};
env.close();

{
// Not Found
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::amendments] = true;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}

auto majorities = getMajorityAmendments(*env.closed());
for (int i = 0; i <= 256; ++i)
{
env.close();
majorities = getMajorityAmendments(*env.closed());
if (!majorities.empty())
break;
}

{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::amendments] = true;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Amendments);
}
}

void
testLedgerEntryCheck()
{
Expand Down Expand Up @@ -1719,6 +1759,27 @@ class LedgerRPC_test : public beast::unit_test::suite
}
}

void
testLedgerEntryFee()
{
testcase("ledger_entry Request Fee");
using namespace test::jtx;

Env env{*this};
env.close();

{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::fee] = true;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] == jss::FeeSettings);
}
}

void
testLedgerEntryOffer()
{
Expand Down Expand Up @@ -2156,6 +2217,201 @@ class LedgerRPC_test : public beast::unit_test::suite
}
}

void
testLedgerEntryHashes()
{
testcase("ledger_entry Request Hashes");
using namespace test::jtx;

Env env{*this, envconfig(validator, ""), supported_amendments()};
env.close();

{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::hashes] = true;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] ==
jss::LedgerHashes);
}

{
// Not Found
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::hashes][jss::ledger_index] = 5;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}

// proceed to the next flag ledger
for (int i = 0; i <= 256; ++i)
env.close();

{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::hashes][jss::ledger_index] = 5;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] ==
jss::LedgerHashes);
}

{
// Fail
Account const alice{"alice"};
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::fee][jss::owner] = alice.human();
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// Fail
Account const alice{"alice"};
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::fee][jss::ledger_index] = alice.human();
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
}

void
testLedgerEntryNegativeUNL()
{
testcase("ledger_entry Request NegativeUNL");
using namespace test::jtx;

Env env{*this, supported_amendments()};
env.close();

{
// Not found
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nunl] = true;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}

{
// TODO: test for when negativeUNL is set
// Success
// Json::Value jvParams;
// jvParams[jss::ledger_index] = "current";
// jvParams[jss::nunl] = true;
// auto const jrr = env.rpc(
// "json", "ledger_entry", to_string(jvParams))[jss::result];
// std::cout << "jrr: " << jrr << std::endl;
// BEAST_EXPECT(
// jrr[jss::node][sfLedgerEntryType.jsonName] ==
// jss::NegativeUNL);
}
}

void
testLedgerEntryNFTokenOffer()
{
testcase("ledger_entry Request NFTokenOffer");

using namespace test::jtx;
Env env{*this, supported_amendments()};
Account const alice{"alice"};

env.fund(XRP(10000), alice);
env.close();

auto const aliceOfferSeq = env.seq(alice);
uint256 const offerID = keylet::nftoffer(alice, aliceOfferSeq).key;
auto createNFTokenAndOffer = [](test::jtx::Account const& account) {
Json::Value jv;
jv[jss::TransactionType] = jss::NFTokenMint;
jv[jss::Account] = account.human();
jv[sfNFTokenTaxon.jsonName] = 1;
jv[jss::Amount] = "10";
return jv;
};

env(createNFTokenAndOffer(alice));
env.close();

{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer] = to_string(offerID);
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] ==
jss::NFTokenOffer);
}
{
// Success
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer][jss::owner] = alice.human();
jvParams[jss::nft_offer][jss::seq] = aliceOfferSeq;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfLedgerEntryType.jsonName] ==
jss::NFTokenOffer);
}

{
// Not found
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer] = to_string(uint256{0});
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}
{
// Not found
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer][jss::owner] = alice.human();
jvParams[jss::nft_offer][jss::seq] = aliceOfferSeq + 1;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}

{
// Fail
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer][jss::owner] = alice.human();
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
{
// Fail
Account const alice{"alice"};
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::nft_offer][jss::account] = alice.human();
jvParams[jss::nft_offer][jss::seq] = aliceOfferSeq + 1;
auto const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "malformedRequest", "");
}
}

void
testLedgerEntryDID()
{
Expand Down Expand Up @@ -2272,7 +2528,12 @@ class LedgerRPC_test : public beast::unit_test::suite
}
// Fields that can handle objects just fine
for (auto const& field :
{jss::directory, jss::escrow, jss::offer, jss::ticket, jss::amm})
{jss::directory,
jss::escrow,
jss::offer,
jss::ticket,
jss::amm,
jss::nft_offer})
{
auto const jvParams =
makeParams([&field, &injectObject](Json::Value& jvParams) {
Expand All @@ -2284,6 +2545,34 @@ class LedgerRPC_test : public beast::unit_test::suite

checkErrorValue(jrr, "malformedRequest", "");
}
// Fields that can handle boolean values
for (auto const& field :
{jss::amendments, jss::fee, jss::hashes, jss::nunl})
{
auto const jvParams = makeParams(
[&field](Json::Value& jvParams) { jvParams[field] = false; });

Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];

checkErrorValue(jrr, "malformedRequest", "");
}
// Fields that can handle only boolean values
for (auto const& field : {jss::amendments, jss::fee, jss::nunl})
{
for (auto const& inject : {injectObject, injectArray})
{
auto const jvParams =
makeParams([&field, &inject](Json::Value& jvParams) {
jvParams[field] = inject;
});

Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];

checkErrorValue(jrr, "malformedRequest", "");
}
}

for (auto const& inject : {injectObject, injectArray})
{
Expand Down Expand Up @@ -2339,6 +2628,22 @@ class LedgerRPC_test : public beast::unit_test::suite
else
checkErrorValue(jrr, "invalidParams", "");
}
// nft_offer sub-fields
{
auto const jvParams =
makeParams([&inject](Json::Value& jvParams) {
jvParams[jss::nft_offer][jss::owner] = inject;
jvParams[jss::nft_offer][jss::seq] = 99;
});

Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];

if (apiVersion < 2u)
checkErrorValue(jrr, "internal", "Internal error.");
else
checkErrorValue(jrr, "invalidParams", "");
}
// offer sub-fields
{
auto const jvParams =
Expand Down Expand Up @@ -3098,16 +3403,21 @@ class LedgerRPC_test : public beast::unit_test::suite
testLedgerFullNonAdmin();
testLedgerAccounts();
testLedgerEntryAccountRoot();
testLedgerEntryAmendments();
testLedgerEntryCheck();
testLedgerEntryCredentials();
testLedgerEntryDepositPreauth();
testLedgerEntryDepositPreauthCred();
testLedgerEntryDirectory();
testLedgerEntryEscrow();
testLedgerEntryFee();
testLedgerEntryOffer();
testLedgerEntryPayChan();
testLedgerEntryRippleState();
testLedgerEntryTicket();
testLedgerEntryHashes();
testLedgerEntryNegativeUNL();
testLedgerEntryNFTokenOffer();
testLookupLedger();
testNoQueue();
testQueue();
Expand Down
Loading
Loading