21#include <xrpl/protocol/TxFlags.h>
22#include <xrpl/protocol/jss.h>
37 "Test deletion of trust lines: revert trust line limit to zero");
45 env.
fund(
XRP(10000), becky, alice);
51 env(
trust(becky, alice[
"USD"](50)));
63 jv[
"account"] = becky.
human();
64 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
66 jv[
"account"] = alice.
human();
67 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
69 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
70 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
73 env(
trust(becky, alice[
"USD"](0)));
83 jv[
"account"] = becky.
human();
84 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
86 jv[
"account"] = alice.
human();
87 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
89 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
90 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
93 jv[
"account"] = becky.
human();
94 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
95 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
97 jv[
"account"] = alice.
human();
98 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
99 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
106 "Reset trust line limit with Authorised Lines: Verify "
107 "deletion of trust lines");
115 env.
fund(
XRP(10000), becky, alice);
125 env(
trust(becky, alice[
"USD"](50)));
141 jv[
"account"] = becky.
human();
142 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
144 jv[
"account"] = alice.
human();
145 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
147 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
148 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
151 env(
trust(becky, alice[
"USD"](0)));
161 jv[
"account"] = becky.
human();
162 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
164 jv[
"account"] = alice.
human();
165 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
167 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
168 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
174 bool thirdLineCreatesLE,
175 bool createOnHighAcct)
177 if (thirdLineCreatesLE)
178 testcase(
"Allow two free trustlines");
180 testcase(
"Dynamic reserve for trustline");
183 Env env(*
this, features);
185 auto const gwA =
Account{
"gwA"};
186 auto const gwB =
Account{
"gwB"};
187 auto const acctC =
Account{
"acctC"};
188 auto const acctD =
Account{
"acctD"};
190 auto const& creator = createOnHighAcct ? acctD : acctC;
191 auto const& assistor = createOnHighAcct ? acctC : acctD;
193 auto const txFee = env.
current()->fees().base;
194 auto const baseReserve = env.
current()->fees().accountReserve(0);
195 auto const threelineReserve = env.
current()->fees().accountReserve(3);
197 env.
fund(
XRP(10000), gwA, gwB, assistor);
208 if (thirdLineCreatesLE)
211 env(
trust(creator, assistor[
"USD"](100)),
218 env(
trust(assistor, creator[
"USD"](100)),
223 env(
trust(creator, assistor[
"USD"](100)),
230 if (thirdLineCreatesLE)
232 env(
trust(creator, assistor[
"USD"](100)),
237 env(
trust(creator, assistor[
"USD"](100)),
241 jv[
"account"] = creator.human();
244 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
245 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
246 for (
auto const& line :
lines[jss::result][jss::lines])
248 BEAST_EXPECT(line[jss::limit] ==
"100");
256 testcase(
"SetTrust using a ticket");
261 Env env{*
this, features};
262 auto const gw =
Account{
"gateway"};
263 auto const alice =
Account{
"alice"};
264 auto const USD = gw[
"USD"];
266 env.fund(
XRP(10000), gw, alice);
283 env(
pay(gw, alice, USD(200)));
291 jv[jss::Account] = a.
human();
293 jv[jss::TransactionType] = jss::TrustSet;
301 testcase(
"SetTrust checks for malformed transactions");
304 Env env{*
this, features};
306 auto const gw =
Account{
"gateway"};
307 auto const alice =
Account{
"alice"};
308 env.fund(
XRP(10000), gw, alice);
312 badFlag <= std::numeric_limits<std::uint32_t>::max();
349 "Ensure that trust line limits are respected in payment "
355 auto const gw =
Account{
"gateway"};
356 auto const alice =
Account{
"alice"};
357 env.fund(
XRP(10000), gw, alice);
360 env(
trust(alice, gw[
"USD"](100)));
368 env(
pay(gw, alice, gw[
"USD"](20)));
376 "Ensure that authorised trust lines do not allow payments "
377 "from unauthorised counter-parties");
382 auto const bob =
Account{
"bob"};
383 auto const alice =
Account{
"alice"};
384 env.fund(
XRP(10000), bob, alice);
393 env(
trust(bob, alice[
"USD"](100)));
405 "Check that trust line limits are respected in conjunction "
406 "with rippling feature");
411 auto const bob =
Account{
"bob"};
412 auto const alice =
Account{
"alice"};
413 env.fund(
XRP(10000), bob, alice);
417 env(
trust(bob, alice[
"USD"](100)));
443 bool createOnHighAcct)
445 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
446 <<
" quality of trustline for "
447 << (createOnHighAcct ?
"high" :
"low") <<
" account";
450 Env env{*
this, features};
452 auto const alice =
Account{
"alice"};
453 auto const bob =
Account{
"bob"};
455 auto const& fromAcct = createOnHighAcct ? alice : bob;
456 auto const& toAcct = createOnHighAcct ? bob : alice;
458 env.fund(
XRP(10000), fromAcct, toAcct);
460 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
461 txWithoutQuality[
"QualityIn"] =
"0";
462 txWithoutQuality[
"QualityOut"] =
"0";
464 auto txWithQuality = txWithoutQuality;
465 txWithQuality[
"QualityIn"] =
"1000";
466 txWithQuality[
"QualityOut"] =
"1000";
468 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
469 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
471 auto check_quality = [&](
const bool exists) {
473 jv[
"account"] = toAcct.human();
474 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
475 auto quality = exists ? 1000 : 0;
476 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
477 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
479 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
481 lines[jss::result][jss::lines][0u][jss::quality_out] ==
486 check_quality(createQuality);
489 check_quality(!createQuality);
495 testcase(
"Create trustline with disallow incoming");
497 using namespace test::jtx;
503 env.fund(
XRP(10000), alice);
506 auto const sle = env.le(alice);
507 uint32_t
flags = sle->getFlags();
513 for (
bool const withFix : {
true,
false})
515 auto const amend = withFix
519 Env env{*
this, amend};
520 auto const dist =
Account(
"dist");
522 auto const USD = gw[
"USD"];
523 auto const distUSD = dist[
"USD"];
525 env.fund(
XRP(1000), gw, dist);
534 env(
trust(dist, USD(10000)));
539 auto const trustResult =
541 env(
trust(gw, distUSD(10000)),
546 auto const txResult =
548 env(
pay(gw, dist, USD(1000)), txResult);
555 auto const gw =
Account{
"gateway"};
556 auto const alice =
Account{
"alice"};
557 auto const bob =
Account{
"bob"};
558 auto const USD = gw[
"USD"];
560 env.fund(
XRP(10000), gw, alice, bob);
576 env(
trust(alice, USD(1000)));
580 env(
pay(gw, alice, USD(200)));
588 env(
pay(gw, alice, USD(200)));
593 env(
pay(gw, alice, USD(200)));
614 env(
trust(bob, USD(1000)));
618 env(
pay(gw, bob, USD(200)));
649 using namespace test::jtx;
testcase_t testcase
Memberspace for declaring test cases.
A currency issued by an account.
Json::Value getJson(JsonOptions) 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.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
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.