3#include <xrpl/protocol/TxFlags.h>
4#include <xrpl/protocol/jss.h>
19 "Test deletion of trust lines: revert trust line limit to zero");
27 env.
fund(
XRP(10000), becky, alice);
33 env(
trust(becky, alice[
"USD"](50)));
45 jv[
"account"] = becky.
human();
46 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
48 jv[
"account"] = alice.
human();
49 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
51 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
52 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
55 env(
trust(becky, alice[
"USD"](0)));
65 jv[
"account"] = becky.
human();
66 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
68 jv[
"account"] = alice.
human();
69 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
71 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
72 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
75 jv[
"account"] = becky.
human();
76 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
77 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
79 jv[
"account"] = alice.
human();
80 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
81 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
88 "Reset trust line limit with Authorised Lines: Verify "
89 "deletion of trust lines");
97 env.
fund(
XRP(10000), becky, alice);
107 env(
trust(becky, alice[
"USD"](50)));
123 jv[
"account"] = becky.
human();
124 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
126 jv[
"account"] = alice.
human();
127 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
129 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
130 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
133 env(
trust(becky, alice[
"USD"](0)));
143 jv[
"account"] = becky.
human();
144 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
146 jv[
"account"] = alice.
human();
147 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
149 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
150 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
156 bool thirdLineCreatesLE,
157 bool createOnHighAcct)
159 if (thirdLineCreatesLE)
160 testcase(
"Allow two free trustlines");
162 testcase(
"Dynamic reserve for trustline");
165 Env env(*
this, features);
167 auto const gwA =
Account{
"gwA"};
168 auto const gwB =
Account{
"gwB"};
169 auto const acctC =
Account{
"acctC"};
170 auto const acctD =
Account{
"acctD"};
172 auto const& creator = createOnHighAcct ? acctD : acctC;
173 auto const& assistor = createOnHighAcct ? acctC : acctD;
175 auto const txFee = env.
current()->fees().base;
176 auto const baseReserve = env.
current()->fees().reserve;
177 auto const threelineReserve = env.
current()->fees().accountReserve(3);
179 env.
fund(
XRP(10000), gwA, gwB, assistor);
190 if (thirdLineCreatesLE)
193 env(
trust(creator, assistor[
"USD"](100)),
200 env(
trust(assistor, creator[
"USD"](100)),
205 env(
trust(creator, assistor[
"USD"](100)),
212 if (thirdLineCreatesLE)
214 env(
trust(creator, assistor[
"USD"](100)),
219 env(
trust(creator, assistor[
"USD"](100)),
223 jv[
"account"] = creator.human();
226 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
227 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
228 for (
auto const& line :
lines[jss::result][jss::lines])
230 BEAST_EXPECT(line[jss::limit] ==
"100");
238 testcase(
"SetTrust using a ticket");
243 Env env{*
this, features};
244 auto const gw =
Account{
"gateway"};
245 auto const alice =
Account{
"alice"};
246 auto const USD = gw[
"USD"];
248 env.fund(
XRP(10000), gw, alice);
265 env(
pay(gw, alice, USD(200)));
273 jv[jss::Account] = a.
human();
275 jv[jss::TransactionType] = jss::TrustSet;
283 testcase(
"SetTrust checks for malformed transactions");
286 Env env{*
this, features};
288 auto const gw =
Account{
"gateway"};
289 auto const alice =
Account{
"alice"};
290 env.fund(
XRP(10000), gw, alice);
294 badFlag <= std::numeric_limits<std::uint32_t>::max();
331 "Ensure that trust line limits are respected in payment "
337 auto const gw =
Account{
"gateway"};
338 auto const alice =
Account{
"alice"};
339 env.fund(
XRP(10000), gw, alice);
342 env(
trust(alice, gw[
"USD"](100)));
350 env(
pay(gw, alice, gw[
"USD"](20)));
358 "Ensure that authorised trust lines do not allow payments "
359 "from unauthorised counter-parties");
364 auto const bob =
Account{
"bob"};
365 auto const alice =
Account{
"alice"};
366 env.fund(
XRP(10000), bob, alice);
375 env(
trust(bob, alice[
"USD"](100)));
387 "Check that trust line limits are respected in conjunction "
388 "with rippling feature");
393 auto const bob =
Account{
"bob"};
394 auto const alice =
Account{
"alice"};
395 env.fund(
XRP(10000), bob, alice);
399 env(
trust(bob, alice[
"USD"](100)));
425 bool createOnHighAcct)
427 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
428 <<
" quality of trustline for "
429 << (createOnHighAcct ?
"high" :
"low") <<
" account";
432 Env env{*
this, features};
434 auto const alice =
Account{
"alice"};
435 auto const bob =
Account{
"bob"};
437 auto const& fromAcct = createOnHighAcct ? alice : bob;
438 auto const& toAcct = createOnHighAcct ? bob : alice;
440 env.fund(
XRP(10000), fromAcct, toAcct);
442 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
443 txWithoutQuality[
"QualityIn"] =
"0";
444 txWithoutQuality[
"QualityOut"] =
"0";
446 auto txWithQuality = txWithoutQuality;
447 txWithQuality[
"QualityIn"] =
"1000";
448 txWithQuality[
"QualityOut"] =
"1000";
450 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
451 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
453 auto check_quality = [&](
bool const exists) {
455 jv[
"account"] = toAcct.human();
456 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
457 auto quality = exists ? 1000 : 0;
458 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
459 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
461 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
463 lines[jss::result][jss::lines][0u][jss::quality_out] ==
468 check_quality(createQuality);
471 check_quality(!createQuality);
477 testcase(
"Create trustline with disallow incoming");
479 using namespace test::jtx;
485 env.fund(
XRP(10000), alice);
488 auto const sle = env.le(alice);
489 uint32_t
flags = sle->getFlags();
495 for (
bool const withFix : {
true,
false})
497 auto const amend = withFix
501 Env env{*
this, amend};
502 auto const dist =
Account(
"dist");
504 auto const USD = gw[
"USD"];
505 auto const distUSD = dist[
"USD"];
507 env.fund(
XRP(1000), gw, dist);
516 env(
trust(dist, USD(10000)));
521 auto const trustResult =
523 env(
trust(gw, distUSD(10000)),
528 auto const txResult =
530 env(
pay(gw, dist, USD(1000)), txResult);
537 auto const gw =
Account{
"gateway"};
538 auto const alice =
Account{
"alice"};
539 auto const bob =
Account{
"bob"};
540 auto const USD = gw[
"USD"];
542 env.fund(
XRP(10000), gw, alice, bob);
558 env(
trust(alice, USD(1000)));
562 env(
pay(gw, alice, USD(200)));
570 env(
pay(gw, alice, USD(200)));
575 env(
pay(gw, alice, USD(200)));
596 env(
trust(bob, USD(1000)));
600 env(
pay(gw, bob, USD(200)));
631 using namespace test::jtx;
testcase_t testcase
Memberspace for declaring test cases.
A currency issued by an account.
Json::Value getJson(JsonOptions=JsonOptions::none) const override
void testTrustLineResetWithAuthFlag()
void run() override
Runs the suite.
void testExceedTrustLineLimit()
void testTrustLineDelete()
void testMalformedTransaction(FeatureBitset features)
void testTicketSetTrust(FeatureBitset features)
void testModifyQualityOfTrustline(FeatureBitset features, bool createQuality, bool createOnHighAcct)
void testFreeTrustlines(FeatureBitset features, bool thirdLineCreatesLE, bool createOnHighAcct)
void testAuthFlagTrustLines()
void testTrustLineLimitsWithRippling()
void testWithFeats(FeatureBitset features)
void testDisallowIncoming(FeatureBitset features)
FeatureBitset const disallowIncoming
Json::Value trust_explicit_amt(jtx::Account const &a, STAmount const &amt)
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Check a set of conditions.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Set a ticket sequence on a JTx.
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
owner_count< ltRIPPLE_STATE > lines
Match the number of trust lines in the account's owner directory.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
FeatureBitset testable_amendments()
XRP_t const XRP
Converts to XRP Issue or STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
AccountID const & noAccount()
A placeholder for empty accounts.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
@ lsfDisallowIncomingTrustline
constexpr std::uint32_t asfDisallowIncomingTrustline
constexpr std::uint32_t tfSetfAuth
@ tecNO_LINE_INSUF_RESERVE
constexpr std::uint32_t tfTrustSetMask
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t asfRequireAuth
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.