19 #include <ripple/protocol/TxFlags.h>
20 #include <ripple/protocol/jss.h>
35 bool thirdLineCreatesLE,
36 bool createOnHighAcct)
38 if (thirdLineCreatesLE)
39 testcase(
"Allow two free trustlines");
41 testcase(
"Dynamic reserve for trustline");
44 Env env(*
this, features);
46 auto const gwA =
Account{
"gwA"};
47 auto const gwB =
Account{
"gwB"};
48 auto const acctC =
Account{
"acctC"};
49 auto const acctD =
Account{
"acctD"};
51 auto const& creator = createOnHighAcct ? acctD : acctC;
52 auto const& assistor = createOnHighAcct ? acctC : acctD;
54 auto const txFee = env.
current()->fees().base;
55 auto const baseReserve = env.
current()->fees().accountReserve(0);
56 auto const threelineReserve = env.
current()->fees().accountReserve(3);
58 env.
fund(
XRP(10000), gwA, gwB, assistor);
69 if (thirdLineCreatesLE)
72 env(
trust(creator, assistor[
"USD"](100)),
79 env(
trust(assistor, creator[
"USD"](100)),
84 env(
trust(creator, assistor[
"USD"](100)),
91 if (thirdLineCreatesLE)
93 env(
trust(creator, assistor[
"USD"](100)),
98 env(
trust(creator, assistor[
"USD"](100)),
102 jv[
"account"] = creator.human();
105 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
106 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 3);
107 for (
auto const& line :
lines[jss::result][jss::lines])
109 BEAST_EXPECT(line[jss::limit] ==
"100");
117 testcase(
"SetTrust using a ticket");
122 Env env{*
this, features};
123 auto const gw =
Account{
"gateway"};
124 auto const alice =
Account{
"alice"};
125 auto const USD = gw[
"USD"];
127 env.fund(
XRP(10000), gw, alice);
136 env(ticket::create(alice, 1));
144 env(
pay(gw, alice, USD(200)));
152 jv[jss::Account] = a.
human();
154 jv[jss::TransactionType] = jss::TrustSet;
162 testcase(
"SetTrust checks for malformed transactions");
165 Env env{*
this, features};
167 auto const gw =
Account{
"gateway"};
168 auto const alice =
Account{
"alice"};
169 env.fund(
XRP(10000), gw, alice);
173 badFlag <= std::numeric_limits<std::uint32_t>::max();
210 bool createOnHighAcct)
212 testcase <<
"SetTrust " << (createQuality ?
"creates" :
"removes")
213 <<
" quality of trustline for "
214 << (createOnHighAcct ?
"high" :
"low") <<
" account";
217 Env env{*
this, features};
219 auto const alice =
Account{
"alice"};
220 auto const bob =
Account{
"bob"};
222 auto const& fromAcct = createOnHighAcct ? alice : bob;
223 auto const& toAcct = createOnHighAcct ? bob : alice;
225 env.fund(
XRP(10000), fromAcct, toAcct);
227 auto txWithoutQuality =
trust(toAcct, fromAcct[
"USD"](100));
228 txWithoutQuality[
"QualityIn"] =
"0";
229 txWithoutQuality[
"QualityOut"] =
"0";
231 auto txWithQuality = txWithoutQuality;
232 txWithQuality[
"QualityIn"] =
"1000";
233 txWithQuality[
"QualityOut"] =
"1000";
235 auto& tx1 = createQuality ? txWithQuality : txWithoutQuality;
236 auto& tx2 = createQuality ? txWithoutQuality : txWithQuality;
238 auto check_quality = [&](
const bool exists) {
240 jv[
"account"] = toAcct.human();
241 auto const lines = env.rpc(
"json",
"account_lines",
to_string(jv));
242 auto quality = exists ? 1000 : 0;
243 BEAST_EXPECT(
lines[jss::result][jss::lines].isArray());
244 BEAST_EXPECT(
lines[jss::result][jss::lines].size() == 1);
246 lines[jss::result][jss::lines][0u][jss::quality_in] == quality);
248 lines[jss::result][jss::lines][0u][jss::quality_out] ==
253 check_quality(createQuality);
256 check_quality(!createQuality);
262 testcase(
"Create trustline with disallow incoming");
264 using namespace test::jtx;
270 env.fund(
XRP(10000), alice);
273 auto const sle = env.le(alice);
274 uint32_t
flags = sle->getFlags();
280 auto const gw =
Account{
"gateway"};
281 auto const alice =
Account{
"alice"};
282 auto const bob =
Account{
"bob"};
283 auto const USD = gw[
"USD"];
285 env.fund(
XRP(10000), gw, alice, bob);
301 env(
trust(alice, USD(1000)));
305 env(
pay(gw, alice, USD(200)));
313 env(
pay(gw, alice, USD(200)));
318 env(
pay(gw, alice, USD(200)));
339 env(
trust(bob, USD(1000)));
343 env(
pay(gw, bob, USD(200)));
369 using namespace test::jtx;
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
bool to_currency(Currency ¤cy, std::string const &code)
Tries to convert a string to a Currency, returns true on success.
void testModifyQualityOfTrustline(FeatureBitset features, bool createQuality, bool createOnHighAcct)
const XRP_t XRP
Converts to XRP Issue or STAmount.
A currency issued by an account.
void testWithFeats(FeatureBitset features)
constexpr std::uint32_t tfTrustSetMask
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Json::Value getJson(JsonOptions) const override
Check a set of conditions.
std::string const & human() const
Returns the human readable public key.
Json::Value trust_explicit_amt(jtx::Account const &a, STAmount const &amt)
const FeatureBitset disallowIncoming
void testTicketSetTrust(FeatureBitset features)
void testFreeTrustlines(FeatureBitset features, bool thirdLineCreatesLE, bool createOnHighAcct)
constexpr std::uint32_t asfDisallowIncomingTrustline
Set a ticket sequence on a JTx.
const uint256 featureDisallowIncoming
void testDisallowIncoming(FeatureBitset features)
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
void testMalformedTransaction(FeatureBitset features)
FeatureBitset supported_amendments()
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
@ tecNO_LINE_INSUF_RESERVE
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
constexpr std::uint32_t tfSetfAuth
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
@ lsfDisallowIncomingTrustline
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Immutable cryptographic account descriptor.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
AccountID const & noAccount()
A placeholder for empty accounts.
A transaction testing environment.
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)