2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h>
7#include <test/jtx/flags.h>
8#include <test/jtx/paths.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/ter.h>
11#include <test/jtx/trust.h>
13#include <xrpl/beast/unit_test/suite.h>
14#include <xrpl/json/json_value.h>
15#include <xrpl/json/to_string.h>
16#include <xrpl/protocol/ApiVersion.h>
17#include <xrpl/protocol/ErrorCodes.h>
18#include <xrpl/protocol/Feature.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/TxFlags.h>
21#include <xrpl/protocol/jss.h>
38 auto const gw =
Account(
"gateway");
39 auto const alice =
Account(
"alice");
41 env.
fund(
XRP(10000), gw, alice);
43 auto const usd = gw[
"USD"];
46 accountGw[jss::account] = gw.human();
48 accountAlice[jss::account] = alice.human();
50 for (
auto const setOrClear : {
true,
false})
53 env(
trust(gw, usd(100), alice, setOrClear ? tfSetNoRipple : tfClearNoRipple));
58 auto const& gwLine0 = lines[jss::result][jss::lines][0u];
59 BEAST_EXPECT(gwLine0[jss::no_ripple].asBool() == setOrClear);
62 lines = env.
rpc(
"json",
"account_lines",
to_string(accountAlice));
63 auto const& aline0 = lines[jss::result][jss::lines][0u];
64 BEAST_EXPECT(aline0[jss::no_ripple_peer].asBool() == setOrClear);
71 testcase(
"Set noripple on a line with negative balance");
74 auto const gw =
Account(
"gateway");
75 auto const alice =
Account(
"alice");
76 auto const bob =
Account(
"bob");
77 auto const carol =
Account(
"carol");
79 Env env(*
this, features);
81 env.
fund(
XRP(10000), gw, alice, bob, carol);
84 env.
trust(alice[
"USD"](100), bob);
85 env.
trust(bob[
"USD"](100), carol);
91 env(
pay(alice, carol, carol[
"USD"](50)),
Path(bob));
96 env(
trust(alice, bob[
"USD"](100), bob, tfSetNoRipple),
Ter(terNeg));
97 env(
trust(bob, carol[
"USD"](100), carol, tfSetNoRipple),
Ter(terNeg));
101 params[jss::source_account] = alice.human();
102 params[jss::destination_account] = carol.human();
103 params[jss::destination_amount] = [] {
105 destAmt[jss::currency] =
"USD";
106 destAmt[jss::value] =
"1";
107 destAmt[jss::issuer] =
Account(
"carol").human();
111 auto const resp = env.
rpc(
"json",
"ripple_path_find",
to_string(params));
112 BEAST_EXPECT(resp[jss::result][jss::alternatives].size() == 1);
116 return r[jss::lines];
120 BEAST_EXPECT(aliceLines.size() == 1);
121 BEAST_EXPECT(aliceLines[0u][jss::no_ripple].asBool() ==
false);
124 BEAST_EXPECT(bobLines.size() == 2);
125 BEAST_EXPECT(bobLines[0u][jss::no_ripple].asBool() ==
false);
126 BEAST_EXPECT(bobLines[1u][jss::no_ripple].asBool() ==
false);
131 env(
pay(carol, alice, alice[
"USD"](50)),
Path(bob));
134 env(
trust(alice, bob[
"USD"](100), bob, tfSetNoRipple));
135 env(
trust(bob, carol[
"USD"](100), carol, tfSetNoRipple));
139 BEAST_EXPECT(aliceLines.size() == 1);
140 BEAST_EXPECT(aliceLines[0u].isMember(jss::no_ripple));
143 BEAST_EXPECT(bobLines.size() == 2);
144 BEAST_EXPECT(bobLines[0u].isMember(jss::no_ripple_peer));
145 BEAST_EXPECT(bobLines[1u].isMember(jss::no_ripple));
155 Env env(*
this, features);
157 auto const alice =
Account(
"alice");
158 auto const bob =
Account(
"bob");
159 auto const carol =
Account(
"carol");
161 env.
fund(
XRP(10000), alice, bob, carol);
163 env(
trust(bob, alice[
"USD"](100)));
164 env(
trust(carol, bob[
"USD"](100)));
166 env(
trust(bob, alice[
"USD"](100), alice, tfSetNoRipple));
167 env(
trust(bob, carol[
"USD"](100), carol, tfSetNoRipple));
171 params[jss::source_account] = alice.human();
172 params[jss::destination_account] = carol.human();
173 params[jss::destination_amount] = [] {
175 destAmt[jss::currency] =
"USD";
176 destAmt[jss::value] =
"1";
177 destAmt[jss::issuer] =
Account(
"carol").human();
182 BEAST_EXPECT(resp[jss::result][jss::alternatives].size() == 0);
191 "Set default ripple on an account and check new trustlines "
196 Env env(*
this, features);
198 auto const gw =
Account(
"gateway");
199 auto const alice =
Account(
"alice");
200 auto const bob =
Account(
"bob");
204 env(
fset(bob, asfDefaultRipple));
206 auto const usd = gw[
"USD"];
208 env(
trust(gw, usd(100), alice, 0));
209 env(
trust(gw, usd(100), bob, 0));
211 params[jss::api_version] = apiVersion;
214 params[jss::account] = gw.human();
215 params[jss::peer] = alice.human();
217 auto lines = env.
rpc(
"json",
"account_lines",
to_string(params));
218 auto const& line0 = lines[jss::result][jss::lines][0u];
219 BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() ==
true);
222 params[jss::account] = alice.human();
223 params[jss::peer] = gw.human();
225 auto lines = env.
rpc(
"json",
"account_lines",
to_string(params));
226 auto const& line0 = lines[jss::result][jss::lines][0u];
227 BEAST_EXPECT(line0[jss::no_ripple].asBool() ==
true);
230 params[jss::account] = gw.human();
231 params[jss::peer] = bob.human();
233 auto lines = env.
rpc(
"json",
"account_lines",
to_string(params));
234 auto const& line0 = lines[jss::result][jss::lines][0u];
235 BEAST_EXPECT(line0[jss::no_ripple].asBool() ==
false);
238 params[jss::account] = bob.human();
239 params[jss::peer] = gw.human();
241 auto lines = env.
rpc(
"json",
"account_lines",
to_string(params));
242 auto const& line0 = lines[jss::result][jss::lines][0u];
243 BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() ==
false);
248 params[jss::account] = bob.human();
249 params[jss::role] =
"gateway";
250 params[jss::transactions] =
"asdf";
252 auto lines = env.
rpc(
"json",
"noripple_check",
to_string(params));
255 BEAST_EXPECT(lines[jss::result][jss::status] ==
"success");
259 BEAST_EXPECT(lines[jss::result][jss::error] ==
"invalidParams");
262 lines[jss::result][jss::error_message] ==
"Invalid field 'transactions'.");
281 withFeatsTests(sa - featurePermissionedDEX);
TestcaseT testcase
Memberspace for declaring test cases.
void testPairwise(FeatureBitset features)
void run() override
Runs the suite.
void testDefaultRipple(FeatureBitset features, unsigned int apiVersion)
void testNegativeBalance(FeatureBitset features)
Immutable cryptographic account descriptor.
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 trust(STAmount const &amount, Account const &account)
Establish trust lines.
Set the expected result code for a JTx The test will fail if the code doesn't match.
The api_version numbers this server serves.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
json::Value getAccountLines(Env &env, AccountID const &acctId)
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void forAllApiVersions(Fn const &fn, Args &&... args)
std::string to_string(BaseUInt< Bits, Tag > const &a)
TERSubset< CanCvtToTER > TER