22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
38 "Test deletion of trust lines: revert trust line limit to zero");
46 env.
fund(
XRP(10000), becky, alice);
52 env(
trust(becky, alice[
"USD"](50)));
64 jv[
"account"] = becky.
human();
65 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
67 jv[
"account"] = alice.
human();
68 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
70 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
71 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
74 env(
trust(becky, alice[
"USD"](0)));
84 jv[
"account"] = becky.
human();
85 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
87 jv[
"account"] = alice.
human();
88 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
90 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
91 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
94 jv[
"account"] = becky.
human();
95 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
96 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
98 jv[
"account"] = alice.
human();
99 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
100 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
107 "Reset trust line limit with Authorised Lines: Verify "
108 "deletion of trust lines");
116 env.
fund(
XRP(10000), becky, alice);
126 env(
trust(becky, alice[
"USD"](50)));
142 jv[
"account"] = becky.
human();
143 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
145 jv[
"account"] = alice.
human();
146 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
148 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
149 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
152 env(
trust(becky, alice[
"USD"](0)));
162 jv[
"account"] = becky.
human();
163 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
165 jv[
"account"] = alice.
human();
166 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
168 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
169 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
175 bool thirdLineCreatesLE,
176 bool createOnHighAcct)
178 if (thirdLineCreatesLE)
179 testcase(
"Allow two free trustlines");
181 testcase(
"Dynamic reserve for trustline");
184 Env env(*
this, features);
186 auto const gwA =
Account{
"gwA"};
187 auto const gwB =
Account{
"gwB"};
188 auto const acctC =
Account{
"acctC"};
189 auto const acctD =
Account{
"acctD"};
191 auto const& creator = createOnHighAcct ? acctD : acctC;
192 auto const& assistor = createOnHighAcct ? acctC : acctD;
194 auto const txFee = env.
current()->fees().base;
195 auto const baseReserve = env.
current()->fees().accountReserve(0);
196 auto const threelineReserve = env.
current()->fees().accountReserve(3);
198 env.
fund(
XRP(10000), gwA, gwB, assistor);
209 if (thirdLineCreatesLE)
212 env(
trust(creator, assistor[
"USD"](100)),
219 env(
trust(assistor, creator[
"USD"](100)),
224 env(
trust(creator, assistor[
"USD"](100)),
231 if (thirdLineCreatesLE)
233 env(
trust(creator, assistor[
"USD"](100)),
238 env(
trust(creator, assistor[
"USD"](100)),
242 jv[
"account"] = creator.human();
245 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
246 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
247 for (
auto const& line :
lines[jss::result][jss::lines])
249 BEAST_EXPECT(line[jss::limit] ==
"100");
257 testcase(
"SetTrust using a ticket");
262 Env env{*
this, features};
263 auto const gw =
Account{
"gateway"};
264 auto const alice =
Account{
"alice"};
265 auto const USD = gw[
"USD"];
267 env.fund(
XRP(10000), gw, alice);
284 env(
pay(gw, alice, USD(200)));
292 jv[jss::Account] = a.
human();
294 jv[jss::TransactionType] = jss::TrustSet;
302 testcase(
"SetTrust checks for malformed transactions");
305 Env env{*
this, features};
307 auto const gw =
Account{
"gateway"};
308 auto const alice =
Account{
"alice"};
309 env.fund(
XRP(10000), gw, alice);
313 badFlag <= std::numeric_limits<std::uint32_t>::max();
350 "Ensure that trust line limits are respected in payment "
356 auto const gw =
Account{
"gateway"};
357 auto const alice =
Account{
"alice"};
358 env.fund(
XRP(10000), gw, alice);
361 env(
trust(alice, gw[
"USD"](100)));
369 env(
pay(gw, alice, gw[
"USD"](20)));
377 "Ensure that authorised trust lines do not allow payments "
378 "from unauthorised counter-parties");
383 auto const bob =
Account{
"bob"};
384 auto const alice =
Account{
"alice"};
385 env.fund(
XRP(10000), bob, alice);
394 env(
trust(bob, alice[
"USD"](100)));
406 "Check that trust line limits are respected in conjunction "
407 "with rippling feature");
412 auto const bob =
Account{
"bob"};
413 auto const alice =
Account{
"alice"};
414 env.fund(
XRP(10000), bob, alice);
418 env(
trust(bob, alice[
"USD"](100)));
444 bool createOnHighAcct)
446 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
447 <<
" quality of trustline for "
448 << (createOnHighAcct ?
"high" :
"low") <<
" account";
451 Env env{*
this, features};
453 auto const alice =
Account{
"alice"};
454 auto const bob =
Account{
"bob"};
456 auto const& fromAcct = createOnHighAcct ? alice : bob;
457 auto const& toAcct = createOnHighAcct ? bob : alice;
459 env.fund(
XRP(10000), fromAcct, toAcct);
461 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
462 txWithoutQuality[
"QualityIn"] =
"0";
463 txWithoutQuality[
"QualityOut"] =
"0";
465 auto txWithQuality = txWithoutQuality;
466 txWithQuality[
"QualityIn"] =
"1000";
467 txWithQuality[
"QualityOut"] =
"1000";
469 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
470 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
472 auto check_quality = [&](
bool const exists) {
474 jv[
"account"] = toAcct.human();
475 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
476 auto quality = exists ? 1000 : 0;
477 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
478 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
480 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
482 lines[jss::result][jss::lines][0u][jss::quality_out] ==
487 check_quality(createQuality);
490 check_quality(!createQuality);
496 testcase(
"Create trustline with disallow incoming");
498 using namespace test::jtx;
504 env.fund(
XRP(10000), alice);
507 auto const sle = env.le(alice);
508 uint32_t
flags = sle->getFlags();
514 for (
bool const withFix : {
true,
false})
516 auto const amend = withFix
520 Env env{*
this, amend};
521 auto const dist =
Account(
"dist");
523 auto const USD = gw[
"USD"];
524 auto const distUSD = dist[
"USD"];
526 env.fund(
XRP(1000), gw, dist);
535 env(
trust(dist, USD(10000)));
540 auto const trustResult =
542 env(
trust(gw, distUSD(10000)),
547 auto const txResult =
549 env(
pay(gw, dist, USD(1000)), txResult);
556 auto const gw =
Account{
"gateway"};
557 auto const alice =
Account{
"alice"};
558 auto const bob =
Account{
"bob"};
559 auto const USD = gw[
"USD"];
561 env.fund(
XRP(10000), gw, alice, bob);
577 env(
trust(alice, USD(1000)));
581 env(
pay(gw, alice, USD(200)));
589 env(
pay(gw, alice, USD(200)));
594 env(
pay(gw, alice, USD(200)));
615 env(
trust(bob, USD(1000)));
619 env(
pay(gw, bob, USD(200)));
650 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.