20#include <xrpl/protocol/TxFlags.h>
21#include <xrpl/protocol/jss.h>
36 "Test deletion of trust lines: revert trust line limit to zero");
44 env.
fund(
XRP(10000), becky, alice);
50 env(
trust(becky, alice[
"USD"](50)));
62 jv[
"account"] = becky.
human();
63 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
65 jv[
"account"] = alice.
human();
66 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
68 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
69 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
72 env(
trust(becky, alice[
"USD"](0)));
82 jv[
"account"] = becky.
human();
83 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
85 jv[
"account"] = alice.
human();
86 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
88 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
89 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
92 jv[
"account"] = becky.
human();
93 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
94 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
96 jv[
"account"] = alice.
human();
97 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
98 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
105 "Reset trust line limit with Authorised Lines: Verify "
106 "deletion of trust lines");
114 env.
fund(
XRP(10000), becky, alice);
124 env(
trust(becky, alice[
"USD"](50)));
140 jv[
"account"] = becky.
human();
141 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
143 jv[
"account"] = alice.
human();
144 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
146 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
147 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
150 env(
trust(becky, alice[
"USD"](0)));
160 jv[
"account"] = becky.
human();
161 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
163 jv[
"account"] = alice.
human();
164 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
166 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
167 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
173 bool thirdLineCreatesLE,
174 bool createOnHighAcct)
176 if (thirdLineCreatesLE)
177 testcase(
"Allow two free trustlines");
179 testcase(
"Dynamic reserve for trustline");
182 Env env(*
this, features);
184 auto const gwA =
Account{
"gwA"};
185 auto const gwB =
Account{
"gwB"};
186 auto const acctC =
Account{
"acctC"};
187 auto const acctD =
Account{
"acctD"};
189 auto const& creator = createOnHighAcct ? acctD : acctC;
190 auto const& assistor = createOnHighAcct ? acctC : acctD;
192 auto const txFee = env.
current()->fees().base;
193 auto const baseReserve = env.
current()->fees().accountReserve(0);
194 auto const threelineReserve = env.
current()->fees().accountReserve(3);
196 env.
fund(
XRP(10000), gwA, gwB, assistor);
207 if (thirdLineCreatesLE)
210 env(
trust(creator, assistor[
"USD"](100)),
217 env(
trust(assistor, creator[
"USD"](100)),
222 env(
trust(creator, assistor[
"USD"](100)),
229 if (thirdLineCreatesLE)
231 env(
trust(creator, assistor[
"USD"](100)),
236 env(
trust(creator, assistor[
"USD"](100)),
240 jv[
"account"] = creator.human();
243 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
244 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
245 for (
auto const& line :
lines[jss::result][jss::lines])
247 BEAST_EXPECT(line[jss::limit] ==
"100");
255 testcase(
"SetTrust using a ticket");
260 Env env{*
this, features};
261 auto const gw =
Account{
"gateway"};
262 auto const alice =
Account{
"alice"};
263 auto const USD = gw[
"USD"];
265 env.fund(
XRP(10000), gw, alice);
282 env(
pay(gw, alice, USD(200)));
290 jv[jss::Account] = a.
human();
292 jv[jss::TransactionType] = jss::TrustSet;
300 testcase(
"SetTrust checks for malformed transactions");
303 Env env{*
this, features};
305 auto const gw =
Account{
"gateway"};
306 auto const alice =
Account{
"alice"};
307 env.fund(
XRP(10000), gw, alice);
311 badFlag <= std::numeric_limits<std::uint32_t>::max();
348 "Ensure that trust line limits are respected in payment "
354 auto const gw =
Account{
"gateway"};
355 auto const alice =
Account{
"alice"};
356 env.fund(
XRP(10000), gw, alice);
359 env(
trust(alice, gw[
"USD"](100)));
367 env(
pay(gw, alice, gw[
"USD"](20)));
375 "Ensure that authorised trust lines do not allow payments "
376 "from unauthorised counter-parties");
381 auto const bob =
Account{
"bob"};
382 auto const alice =
Account{
"alice"};
383 env.fund(
XRP(10000), bob, alice);
392 env(
trust(bob, alice[
"USD"](100)));
404 "Check that trust line limits are respected in conjunction "
405 "with rippling feature");
410 auto const bob =
Account{
"bob"};
411 auto const alice =
Account{
"alice"};
412 env.fund(
XRP(10000), bob, alice);
416 env(
trust(bob, alice[
"USD"](100)));
442 bool createOnHighAcct)
444 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
445 <<
" quality of trustline for "
446 << (createOnHighAcct ?
"high" :
"low") <<
" account";
449 Env env{*
this, features};
451 auto const alice =
Account{
"alice"};
452 auto const bob =
Account{
"bob"};
454 auto const& fromAcct = createOnHighAcct ? alice : bob;
455 auto const& toAcct = createOnHighAcct ? bob : alice;
457 env.fund(
XRP(10000), fromAcct, toAcct);
459 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
460 txWithoutQuality[
"QualityIn"] =
"0";
461 txWithoutQuality[
"QualityOut"] =
"0";
463 auto txWithQuality = txWithoutQuality;
464 txWithQuality[
"QualityIn"] =
"1000";
465 txWithQuality[
"QualityOut"] =
"1000";
467 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
468 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
470 auto check_quality = [&](
const bool exists) {
472 jv[
"account"] = toAcct.human();
473 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
474 auto quality = exists ? 1000 : 0;
475 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
476 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
478 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
480 lines[jss::result][jss::lines][0u][jss::quality_out] ==
485 check_quality(createQuality);
488 check_quality(!createQuality);
494 testcase(
"Create trustline with disallow incoming");
496 using namespace test::jtx;
502 env.fund(
XRP(10000), alice);
505 auto const sle = env.le(alice);
506 uint32_t
flags = sle->getFlags();
512 for (
bool const withFix : {
true,
false})
514 auto const amend = withFix
518 Env env{*
this, amend};
519 auto const dist =
Account(
"dist");
521 auto const USD = gw[
"USD"];
522 auto const distUSD = dist[
"USD"];
524 env.fund(
XRP(1000), gw, dist);
533 env(
trust(dist, USD(10000)));
538 auto const trustResult =
540 env(
trust(gw, distUSD(10000)),
545 auto const txResult =
547 env(
pay(gw, dist, USD(1000)), txResult);
554 auto const gw =
Account{
"gateway"};
555 auto const alice =
Account{
"alice"};
556 auto const bob =
Account{
"bob"};
557 auto const USD = gw[
"USD"];
559 env.fund(
XRP(10000), gw, alice, bob);
575 env(
trust(alice, USD(1000)));
579 env(
pay(gw, alice, USD(200)));
587 env(
pay(gw, alice, USD(200)));
592 env(
pay(gw, alice, USD(200)));
613 env(
trust(bob, USD(1000)));
617 env(
pay(gw, bob, USD(200)));
648 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.