3#include <xrpl/protocol/TxFlags.h>
4#include <xrpl/protocol/jss.h>
16 testcase(
"Test deletion of trust lines: revert trust line limit to zero");
24 env.
fund(
XRP(10000), becky, alice);
30 env(
trust(becky, alice[
"USD"](50)));
42 jv[
"account"] = becky.
human();
43 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
45 jv[
"account"] = alice.
human();
46 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
48 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
49 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
52 env(
trust(becky, alice[
"USD"](0)));
62 jv[
"account"] = becky.
human();
63 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
65 jv[
"account"] = alice.
human();
66 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
68 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
69 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
72 jv[
"account"] = becky.
human();
73 auto const beckyObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
74 BEAST_EXPECT(beckyObj[jss::result][jss::account_objects].size() == 0);
76 jv[
"account"] = alice.
human();
77 auto const aliceObj = env.
rpc(
"json",
"account_objects",
to_string(jv));
78 BEAST_EXPECT(aliceObj[jss::result][jss::account_objects].size() == 0);
85 "Reset trust line limit with Authorised Lines: Verify "
86 "deletion of trust lines");
94 env.
fund(
XRP(10000), becky, alice);
104 env(
trust(becky, alice[
"USD"](50)));
120 jv[
"account"] = becky.
human();
121 auto beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
123 jv[
"account"] = alice.
human();
124 auto aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
126 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 1);
127 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 1);
130 env(
trust(becky, alice[
"USD"](0)));
140 jv[
"account"] = becky.
human();
141 beckyLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
143 jv[
"account"] = alice.
human();
144 aliceLines = env.
rpc(
"json",
"account_lines",
to_string(jv));
146 BEAST_EXPECT(aliceLines[jss::result][jss::lines].size() == 0);
147 BEAST_EXPECT(beckyLines[jss::result][jss::lines].size() == 0);
153 if (thirdLineCreatesLE)
154 testcase(
"Allow two free trustlines");
156 testcase(
"Dynamic reserve for trustline");
159 Env env(*
this, features);
161 auto const gwA =
Account{
"gwA"};
162 auto const gwB =
Account{
"gwB"};
163 auto const acctC =
Account{
"acctC"};
164 auto const acctD =
Account{
"acctD"};
166 auto const& creator = createOnHighAcct ? acctD : acctC;
167 auto const& assistor = createOnHighAcct ? acctC : acctD;
169 auto const txFee = env.
current()->fees().base;
170 auto const baseReserve = env.
current()->fees().reserve;
171 auto const threelineReserve = env.
current()->fees().accountReserve(3);
173 env.
fund(
XRP(10000), gwA, gwB, assistor);
184 if (thirdLineCreatesLE)
202 if (thirdLineCreatesLE)
211 jv[
"account"] = creator.human();
214 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
215 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
216 for (
auto const& line :
lines[jss::result][jss::lines])
218 BEAST_EXPECT(line[jss::limit] ==
"100");
226 testcase(
"SetTrust using a ticket");
231 Env env{*
this, features};
232 auto const gw =
Account{
"gateway"};
233 auto const alice =
Account{
"alice"};
234 auto const USD = gw[
"USD"];
236 env.fund(
XRP(10000), gw, alice);
253 env(
pay(gw, alice, USD(200)));
261 jv[jss::Account] = a.
human();
263 jv[jss::TransactionType] = jss::TrustSet;
271 testcase(
"SetTrust checks for malformed transactions");
274 Env env{*
this, features};
276 auto const gw =
Account{
"gateway"};
277 auto const alice =
Account{
"alice"};
278 env.fund(
XRP(10000), gw, alice);
281 for (
std::uint64_t badFlag = 1u; badFlag <= std::numeric_limits<std::uint32_t>::max(); badFlag *= 2)
310 "Ensure that trust line limits are respected in payment "
316 auto const gw =
Account{
"gateway"};
317 auto const alice =
Account{
"alice"};
318 env.fund(
XRP(10000), gw, alice);
321 env(
trust(alice, gw[
"USD"](100)));
329 env(
pay(gw, alice, gw[
"USD"](20)));
337 "Ensure that authorised trust lines do not allow payments "
338 "from unauthorised counter-parties");
343 auto const bob =
Account{
"bob"};
344 auto const alice =
Account{
"alice"};
345 env.fund(
XRP(10000), bob, alice);
354 env(
trust(bob, alice[
"USD"](100)));
366 "Check that trust line limits are respected in conjunction "
367 "with rippling feature");
372 auto const bob =
Account{
"bob"};
373 auto const alice =
Account{
"alice"};
374 env.fund(
XRP(10000), bob, alice);
378 env(
trust(bob, alice[
"USD"](100)));
403 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes") <<
" quality of trustline for "
404 << (createOnHighAcct ?
"high" :
"low") <<
" account";
407 Env env{*
this, features};
409 auto const alice =
Account{
"alice"};
410 auto const bob =
Account{
"bob"};
412 auto const& fromAcct = createOnHighAcct ? alice : bob;
413 auto const& toAcct = createOnHighAcct ? bob : alice;
415 env.fund(
XRP(10000), fromAcct, toAcct);
417 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
418 txWithoutQuality[
"QualityIn"] =
"0";
419 txWithoutQuality[
"QualityOut"] =
"0";
421 auto txWithQuality = txWithoutQuality;
422 txWithQuality[
"QualityIn"] =
"1000";
423 txWithQuality[
"QualityOut"] =
"1000";
425 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
426 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
428 auto check_quality = [&](
bool const exists) {
430 jv[
"account"] = toAcct.human();
431 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
432 auto quality = exists ? 1000 : 0;
433 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
434 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
435 BEAST_EXPECT(
lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
436 BEAST_EXPECT(
lines[jss::result][jss::lines][0u][jss::quality_out] == quality);
440 check_quality(createQuality);
443 check_quality(!createQuality);
449 testcase(
"Create trustline with disallow incoming");
451 using namespace test::jtx;
455 for (
bool const withFix : {
true,
false})
457 auto const amend = withFix ? features : features - fixDisallowIncomingV1;
459 Env env{*
this, amend};
460 auto const dist =
Account(
"dist");
462 auto const USD = gw[
"USD"];
463 auto const distUSD = dist[
"USD"];
465 env.fund(
XRP(1000), gw, dist);
474 env(
trust(dist, USD(10000)));
484 env(
pay(gw, dist, USD(1000)), txResult);
489 Env env{*
this, features};
491 auto const gw =
Account{
"gateway"};
492 auto const alice =
Account{
"alice"};
493 auto const bob =
Account{
"bob"};
494 auto const USD = gw[
"USD"];
496 env.fund(
XRP(10000), gw, alice, bob);
512 env(
trust(alice, USD(1000)));
516 env(
pay(gw, alice, USD(200)));
524 env(
pay(gw, alice, USD(200)));
529 env(
pay(gw, alice, USD(200)));
550 env(
trust(bob, USD(1000)));
554 env(
pay(gw, bob, USD(200)));
585 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 testTrustLineLimitsWithRippling()
void testWithFeats(FeatureBitset features)
void testFreeTrustlines(FeatureBitset features, bool thirdLineCreatesLE, bool createOnHighAcct)
Json::Value trust_explicit_amt(jtx::Account const &a, STAmount const &amt)
void testTrustLineResetWithAuthFlag()
void run() override
Runs the suite.
void testMalformedTransaction(FeatureBitset features)
void testModifyQualityOfTrustline(FeatureBitset features, bool createQuality, bool createOnHighAcct)
void testTicketSetTrust(FeatureBitset features)
void testExceedTrustLineLimit()
void testAuthFlagTrustLines()
void testTrustLineDelete()
void testDisallowIncoming(FeatureBitset features)
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
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 require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
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.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
XRP_t const XRP
Converts to XRP Issue or STAmount.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
FeatureBitset testable_amendments()
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
owner_count< ltRIPPLE_STATE > lines
Match the number of trust lines in the account's owner directory.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t asfDisallowIncomingTrustline
constexpr std::uint32_t tfTrustSetMask
constexpr std::uint32_t tfSetfAuth
constexpr std::uint32_t asfRequireAuth
AccountID const & noAccount()
A placeholder for empty accounts.
@ tecNO_LINE_INSUF_RESERVE
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...