Skip to content

Commit

Permalink
[FOLD] adds unittesting
Browse files Browse the repository at this point in the history
  • Loading branch information
natenichols committed Dec 16, 2021
2 parents ec01324 + 1a2b515 commit dc77f16
Showing 1 changed file with 50 additions and 31 deletions.
81 changes: 50 additions & 31 deletions src/test/rpc/AccountLinesRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,58 +374,77 @@ class AccountLinesRPC_test : public beast::unit_test::suite
// error message when the SLE pointed to by the marker is not owned by
// the Account being traversed.
//
// To start, we'll create an environment with some trust lines, and a
// signers list.
// To start, we'll create an environment with some trust lines, offers
// and a signers list.
Account const alice{"alice"};
Account const becky{"becky"};
Account const cheri{"cheri"};
Account const gw1{"gw1"};
Account const gw2{"gw2"};
env.fund(XRP(10000), alice, becky, cheri, gw1, gw2);
env.close();

auto const USD = gw1["USD"];
auto const AUD = gw1["AUD"];
auto const EUR = gw2["EUR"];
env(trust(alice, USD(200)));
env(trust(alice, AUD(200)));
env(trust(becky, EUR(200)));
env(trust(cheri, EUR(200)));
env.fund(XRP(10000), alice, becky, gw1);
env.close();

// Give alice a SignerList.
Account const bogie{"bogie"};
env(signers(alice, 2, {{bogie, 3}}));
env.close();

Json::Value const aliceSigners = signers(alice, 2, {{bogie, 3}});
env(aliceSigners);
auto const EUR = gw1["EUR"];
env(trust(alice, EUR(200)));
env(trust(becky, EUR(200)));
env.close();

// Get all account objects for alice and verify that her
// signerlist is first. This is only a (reliable) coincidence of
// object naming. So if any of alice's objects are renamed this
// may fail.
Json::Value const aliceObjects = env.rpc(
"json",
"account_objects",
R"({"account": ")" + alice.human() +
R"(", )"
R"("limit": 10})");
Json::Value const& aliceSignerList =
aliceObjects[jss::result][jss::account_objects][0u];
if (!(aliceSignerList[sfLedgerEntryType.jsonName] == jss::SignerList))
{
fail(
"alice's account objects are misordered. "
"Please reorder the objects so the SignerList is first.",
__FILE__,
__LINE__);
return;
}

// Get account_lines for alice. Limit at 1, so we get a marker pointing
// to a SignerList.
auto const aliceLines = env.rpc(
// Get account_lines for alice. Limit at 1, so we get a marker
// pointing to her SignerList.
auto const aliceLines1 = env.rpc(
"json",
"account_lines",
R"({"account": ")" + alice.human() + R"(", "limit": 1})");
BEAST_EXPECT(aliceLines[jss::result].isMember(jss::marker));
BEAST_EXPECT(aliceLines1[jss::result].isMember(jss::marker));

// When we fetch Alice's remaining lines, we should see only one more.
auto const aliceMarker = env.rpc(
// Verify that the marker points at the signer list.
std::string const aliceMarker =
aliceLines1[jss::result][jss::marker].asString();
std::string const markerIndex =
aliceMarker.substr(0, aliceMarker.find(','));
BEAST_EXPECT(markerIndex == aliceSignerList[jss::index].asString());

// When we fetch Alice's remaining lines we should find one and no more.
auto const aliceLines2 = env.rpc(
"json",
"account_lines",
R"({"account": ")" + alice.human() +
R"(", )"
R"("marker": ")" +
aliceLines[jss::result][jss::marker].asString() + R"("})");
BEAST_EXPECT(aliceMarker[jss::result][jss::lines].size() == 1);
R"({"account": ")" + alice.human() + R"(", "marker": ")" +
aliceMarker + R"("})");
BEAST_EXPECT(aliceLines2[jss::result][jss::lines].size() == 1);
BEAST_EXPECT(!aliceLines2[jss::result].isMember(jss::marker));

// Get account lines for beckys account, using alices SignerList as a
// marker. This should cause an error.
auto const beckyLines = env.rpc(
"json",
"account_lines",
R"({"account": ")" + becky.human() +
R"(", )"
R"("marker": ")" +
aliceLines[jss::result][jss::marker].asString() + R"("})");
R"({"account": ")" + becky.human() + R"(", "marker": ")" +
aliceMarker + R"("})");
BEAST_EXPECT(beckyLines[jss::result].isMember(jss::error_message));
}

Expand Down

0 comments on commit dc77f16

Please sign in to comment.