3#include <xrpl/protocol/TxFlags.h>
4#include <xrpl/protocol/jss.h>
17 "Test deletion of trust lines: revert trust line limit to zero");
25 env.
fund(
XRP(10000), becky, alice);
31 env(
trust(becky, alice[
"USD"](50)));
43 jv[
"account"] = becky.
human();
44 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
46 jv[
"account"] = alice.
human();
47 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
49 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
50 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
53 env(
trust(becky, alice[
"USD"](0)));
63 jv[
"account"] = becky.
human();
64 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
66 jv[
"account"] = alice.
human();
67 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
69 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
70 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
73 jv[
"account"] = becky.
human();
74 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
75 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
77 jv[
"account"] = alice.
human();
78 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
79 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
86 "Reset trust line limit with Authorised Lines: Verify "
87 "deletion of trust lines");
95 env.
fund(
XRP(10000), becky, alice);
105 env(
trust(becky, alice[
"USD"](50)));
121 jv[
"account"] = becky.
human();
122 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
124 jv[
"account"] = alice.
human();
125 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
127 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
128 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
131 env(
trust(becky, alice[
"USD"](0)));
141 jv[
"account"] = becky.
human();
142 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
144 jv[
"account"] = alice.
human();
145 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
147 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
148 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
154 bool thirdLineCreatesLE,
155 bool createOnHighAcct)
157 if (thirdLineCreatesLE)
158 testcase(
"Allow two free trustlines");
160 testcase(
"Dynamic reserve for trustline");
163 Env env(*
this, features);
165 auto const gwA =
Account{
"gwA"};
166 auto const gwB =
Account{
"gwB"};
167 auto const acctC =
Account{
"acctC"};
168 auto const acctD =
Account{
"acctD"};
170 auto const& creator = createOnHighAcct ? acctD : acctC;
171 auto const& assistor = createOnHighAcct ? acctC : acctD;
173 auto const txFee = env.
current()->fees().base;
174 auto const baseReserve = env.
current()->fees().reserve;
175 auto const threelineReserve = env.
current()->fees().accountReserve(3);
177 env.
fund(
XRP(10000), gwA, gwB, assistor);
188 if (thirdLineCreatesLE)
191 env(
trust(creator, assistor[
"USD"](100)),
198 env(
trust(assistor, creator[
"USD"](100)),
203 env(
trust(creator, assistor[
"USD"](100)),
210 if (thirdLineCreatesLE)
212 env(
trust(creator, assistor[
"USD"](100)),
217 env(
trust(creator, assistor[
"USD"](100)),
221 jv[
"account"] = creator.human();
224 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
225 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
226 for (
auto const& line :
lines[jss::result][jss::lines])
228 BEAST_EXPECT(line[jss::limit] ==
"100");
236 testcase(
"SetTrust using a ticket");
241 Env env{*
this, features};
242 auto const gw =
Account{
"gateway"};
243 auto const alice =
Account{
"alice"};
244 auto const USD = gw[
"USD"];
246 env.fund(
XRP(10000), gw, alice);
263 env(
pay(gw, alice, USD(200)));
271 jv[jss::Account] = a.
human();
273 jv[jss::TransactionType] = jss::TrustSet;
281 testcase(
"SetTrust checks for malformed transactions");
284 Env env{*
this, features};
286 auto const gw =
Account{
"gateway"};
287 auto const alice =
Account{
"alice"};
288 env.fund(
XRP(10000), gw, alice);
292 badFlag <= std::numeric_limits<std::uint32_t>::max();
329 "Ensure that trust line limits are respected in payment "
335 auto const gw =
Account{
"gateway"};
336 auto const alice =
Account{
"alice"};
337 env.fund(
XRP(10000), gw, alice);
340 env(
trust(alice, gw[
"USD"](100)));
348 env(
pay(gw, alice, gw[
"USD"](20)));
356 "Ensure that authorised trust lines do not allow payments "
357 "from unauthorised counter-parties");
362 auto const bob =
Account{
"bob"};
363 auto const alice =
Account{
"alice"};
364 env.fund(
XRP(10000), bob, alice);
373 env(
trust(bob, alice[
"USD"](100)));
385 "Check that trust line limits are respected in conjunction "
386 "with rippling feature");
391 auto const bob =
Account{
"bob"};
392 auto const alice =
Account{
"alice"};
393 env.fund(
XRP(10000), bob, alice);
397 env(
trust(bob, alice[
"USD"](100)));
423 bool createOnHighAcct)
425 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
426 <<
" quality of trustline for "
427 << (createOnHighAcct ?
"high" :
"low") <<
" account";
430 Env env{*
this, features};
432 auto const alice =
Account{
"alice"};
433 auto const bob =
Account{
"bob"};
435 auto const& fromAcct = createOnHighAcct ? alice : bob;
436 auto const& toAcct = createOnHighAcct ? bob : alice;
438 env.fund(
XRP(10000), fromAcct, toAcct);
440 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
441 txWithoutQuality[
"QualityIn"] =
"0";
442 txWithoutQuality[
"QualityOut"] =
"0";
444 auto txWithQuality = txWithoutQuality;
445 txWithQuality[
"QualityIn"] =
"1000";
446 txWithQuality[
"QualityOut"] =
"1000";
448 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
449 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
451 auto check_quality = [&](
bool const exists) {
453 jv[
"account"] = toAcct.human();
454 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
455 auto quality = exists ? 1000 : 0;
456 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
457 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
459 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
461 lines[jss::result][jss::lines][0u][jss::quality_out] ==
466 check_quality(createQuality);
469 check_quality(!createQuality);
475 testcase(
"Create trustline with disallow incoming");
477 using namespace test::jtx;
481 for (
bool const withFix : {
true,
false})
484 withFix ? features : features - fixDisallowIncomingV1;
486 Env env{*
this, amend};
487 auto const dist =
Account(
"dist");
489 auto const USD = gw[
"USD"];
490 auto const distUSD = dist[
"USD"];
492 env.fund(
XRP(1000), gw, dist);
501 env(
trust(dist, USD(10000)));
506 auto const trustResult =
508 env(
trust(gw, distUSD(10000)),
513 auto const txResult =
515 env(
pay(gw, dist, USD(1000)), txResult);
520 Env env{*
this, features};
522 auto const gw =
Account{
"gateway"};
523 auto const alice =
Account{
"alice"};
524 auto const bob =
Account{
"bob"};
525 auto const USD = gw[
"USD"];
527 env.fund(
XRP(10000), gw, alice, bob);
543 env(
trust(alice, USD(1000)));
547 env(
pay(gw, alice, USD(200)));
555 env(
pay(gw, alice, USD(200)));
560 env(
pay(gw, alice, USD(200)));
581 env(
trust(bob, USD(1000)));
585 env(
pay(gw, bob, USD(200)));
616 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)
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...
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.