1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/WSClient.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h>
7#include <test/jtx/envconfig.h>
8#include <test/jtx/mpt.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/sendmax.h>
11#include <test/jtx/ter.h>
12#include <test/jtx/txflags.h>
14#include <xrpl/basics/chrono.h>
15#include <xrpl/beast/unit_test/suite.h>
16#include <xrpl/json/json_value.h>
17#include <xrpl/json/to_string.h>
18#include <xrpl/protocol/AccountID.h>
19#include <xrpl/protocol/Feature.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/TER.h>
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
110 if (t[jss::TransactionType].asString() != jss::Payment)
113 bool const isSet = metaData.
isMember(jss::delivered_amount);
114 bool isSetUnavailable =
false;
115 bool isSetAvailable =
false;
118 if (metaData[jss::delivered_amount] !=
"unavailable")
120 isSetAvailable =
true;
124 isSetUnavailable =
true;
131 else if (isSetUnavailable)
142 if (metaData.
isMember(sfDeliveredAmount.jsonName))
144 if (metaData[jss::delivered_amount] != metaData[sfDeliveredAmount.jsonName])
151 if (metaData[jss::delivered_amount] != t[jss::Amount])
156 if (metaData[jss::delivered_amount] !=
"unavailable")
162 if (metaData[sfTransactionResult.jsonName] !=
"tesSUCCESS")
176 if (metaData.
isMember(sfDeliveredAmount.jsonName))
183 if (!isSetUnavailable)
197 testcase(
"Ledger Request Subscribe DeliveredAmount");
200 using namespace std::chrono_literals;
205 auto const gw =
Account(
"gateway");
206 auto const usd = gw[
"USD"];
208 for (
bool const afterSwitchTime : {
true,
false})
211 cfg->fees.referenceFee = 10;
212 Env env(*
this, std::move(cfg));
213 env.
fund(
XRP(10000), alice, bob, carol, gw);
214 env.
trust(usd(1000), alice, bob, carol);
229 env(
pay(gw, alice, usd(50)));
231 env(
pay(gw, alice,
XRP(50)));
235 env(
pay(gw, bob, usd(9999999)),
Txflags(tfPartialPayment));
251 stream[jss::streams].append(
"ledger");
253 stream[jss::accounts].append(
toBase58(alice.
id()));
254 stream[jss::accounts].append(
toBase58(bob.
id()));
255 stream[jss::accounts].append(
toBase58(carol.
id()));
256 auto jv = wsc->invoke(
"subscribe", stream);
257 if (wsc->version() == 2)
260 BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5);
262 BEAST_EXPECT(jv[jss::result][jss::ledger_index] == 3);
269 auto const r = wsc->findMsg(
270 1s, [&](
auto const& jv) {
return jv[jss::ledger_index] == 4; });
274 if (!r->isMember(jss::transaction))
278 checkDeliveredAmount.
checkTxn((*r)[jss::transaction], (*r)[jss::meta]));
287 testcase(
"Ledger Request RPC DeliveredAmount");
290 using namespace std::chrono_literals;
295 auto const gw =
Account(
"gateway");
296 auto const usd = gw[
"USD"];
298 for (
bool const afterSwitchTime : {
true,
false})
301 cfg->fees.referenceFee = 10;
302 Env env(*
this, std::move(cfg));
303 env.
fund(
XRP(10000), alice, bob, carol, gw);
304 env.
trust(usd(1000), alice, bob, carol);
316 env(
pay(gw, alice, usd(50)));
318 env(
pay(gw, alice,
XRP(50)));
322 env(
pay(gw, bob, usd(9999999)),
Txflags(tfPartialPayment));
333 jvParams[jss::ledger_index] = 4u;
334 jvParams[jss::transactions] =
true;
335 jvParams[jss::expand] =
true;
336 auto const jtxn = env.
rpc(
337 "json",
"ledger",
to_string(jvParams))[jss::result][jss::ledger][jss::transactions];
338 for (
auto const& t : jtxn)
339 BEAST_EXPECT(checkDeliveredAmount.
checkTxn(t, t[jss::metaData]));
353 Env env{*
this, features};
355 MPTTester mptAlice(env, alice, {.holders = {bob, carol}, .close =
false});
358 {.transferFee = 25000, .ownerCount = 1, .holderCount = 0, .flags = tfMPTCanTransfer});
359 auto const mpt = mptAlice[
"MPT"];
361 mptAlice.authorize({.account = bob});
362 mptAlice.authorize({.account = carol});
365 mptAlice.pay(alice, bob, 10000);
368 env(
pay(bob, carol, mptAlice.mpt(1000)),
Txflags(tfPartialPayment));
375 if (features[fixMPTDeliveredAmount])
378 meta[sfDeliveredAmount.jsonName] ==
381 meta[jss::delivered_amount] ==
386 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
387 BEAST_EXPECT(meta[jss::delivered_amount] =
json::Value(
"unavailable"));
394 meta = env.
rpc(
"tx", txHash)[jss::result][jss::meta];
396 if (features[fixMPTDeliveredAmount])
399 meta[sfDeliveredAmount.jsonName] ==
402 meta[jss::delivered_amount] ==
407 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
408 BEAST_EXPECT(meta[jss::delivered_amount] =
json::Value(
"unavailable"));
TestcaseT testcase
Memberspace for declaring test cases.
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual Config & config()=0
std::chrono::time_point< NetClock > time_point
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
void adjCountersSuccess()
CheckDeliveredAmount(bool afterSwitchTime)
bool checkExpectedCounters() const
int numExpectedSetUnavailable_
int numExpectedAvailable_
void adjCountersPartialPayment()
bool checkTxn(json::Value const &t, json::Value const &metaData)
void adjCounters(bool success, bool partial)
void run() override
Runs the suite.
void testAccountDeliveredAmountSubscribe()
void testMPTDeliveredAmountRPC(FeatureBitset features)
void testTxDeliveredAmountRPC()
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
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.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
void require(Args const &... args)
Check a set of requirements.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
Sets the SendMax on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
@ Array
array value (ordered list)
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.
bool hasEnvelope2(json::Value const &reply)
Reports whether reply carries the version 2 envelope: jsonrpc equal to rpc::kJsonRpcVersion and rippl...
FeatureBitset testableAmendments()
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(BaseUInt< Bits, Tag > const &a)