21#include <test/jtx/WSClient.h>
23#include <xrpl/beast/unit_test.h>
24#include <xrpl/beast/unit_test/suite.h>
25#include <xrpl/protocol/jss.h>
106 if (t[jss::TransactionType].asString() != jss::Payment)
109 bool isSet = metaData.
isMember(jss::delivered_amount);
110 bool isSetUnavailable =
false;
111 bool isSetAvailable =
false;
114 if (metaData[jss::delivered_amount] !=
"unavailable")
115 isSetAvailable =
true;
117 isSetUnavailable =
true;
121 else if (isSetUnavailable)
128 if (metaData.
isMember(sfDeliveredAmount.jsonName))
130 if (metaData[jss::delivered_amount] !=
131 metaData[sfDeliveredAmount.jsonName])
138 if (metaData[jss::delivered_amount] != t[jss::Amount])
143 if (metaData[jss::delivered_amount] !=
"unavailable")
149 if (metaData[sfTransactionResult.jsonName] !=
"tesSUCCESS")
163 if (metaData.
isMember(sfDeliveredAmount.jsonName))
170 if (!isSetUnavailable)
184 testcase(
"Ledger Request Subscribe DeliveredAmount");
186 using namespace test::jtx;
187 using namespace std::chrono_literals;
192 auto const gw =
Account(
"gateway");
193 auto const USD = gw[
"USD"];
195 for (
bool const afterSwitchTime : {
true,
false})
198 cfg->FEES.reference_fee = 10;
199 Env env(*
this, std::move(cfg));
200 env.
fund(
XRP(10000), alice, bob, carol, gw);
201 env.
trust(USD(1000), alice, bob, carol);
212 env(
pay(gw, alice, USD(50)));
213 checkDeliveredAmount.adjCountersSuccess();
214 env(
pay(gw, alice,
XRP(50)));
215 checkDeliveredAmount.adjCountersSuccess();
219 checkDeliveredAmount.adjCountersPartialPayment();
224 checkDeliveredAmount.adjCountersFail();
234 stream[jss::streams].append(
"ledger");
236 stream[jss::accounts].append(
toBase58(alice.
id()));
237 stream[jss::accounts].append(
toBase58(bob.
id()));
238 stream[jss::accounts].append(
toBase58(carol.
id()));
239 auto jv = wsc->invoke(
"subscribe", stream);
240 if (wsc->version() == 2)
243 jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] ==
"2.0");
245 jv.isMember(jss::ripplerpc) &&
246 jv[jss::ripplerpc] ==
"2.0");
247 BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5);
249 BEAST_EXPECT(jv[jss::result][jss::ledger_index] == 3);
256 auto const r = wsc->findMsg(1s, [&](
auto const& jv) {
257 return jv[jss::ledger_index] == 4;
262 if (!r->isMember(jss::transaction))
265 BEAST_EXPECT(checkDeliveredAmount.checkTxn(
266 (*r)[jss::transaction], (*r)[jss::meta]));
269 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
275 testcase(
"Ledger Request RPC DeliveredAmount");
277 using namespace test::jtx;
278 using namespace std::chrono_literals;
283 auto const gw =
Account(
"gateway");
284 auto const USD = gw[
"USD"];
286 for (
bool const afterSwitchTime : {
true,
false})
289 cfg->FEES.reference_fee = 10;
290 Env env(*
this, std::move(cfg));
291 env.
fund(
XRP(10000), alice, bob, carol, gw);
292 env.
trust(USD(1000), alice, bob, carol);
300 env(
pay(gw, alice, USD(50)));
301 checkDeliveredAmount.adjCountersSuccess();
302 env(
pay(gw, alice,
XRP(50)));
303 checkDeliveredAmount.adjCountersSuccess();
307 checkDeliveredAmount.adjCountersPartialPayment();
312 checkDeliveredAmount.adjCountersFail();
318 jvParams[jss::ledger_index] = 4u;
319 jvParams[jss::transactions] =
true;
320 jvParams[jss::expand] =
true;
321 auto const jtxn = env.
rpc(
325 jvParams))[jss::result][jss::ledger][jss::transactions];
326 for (
auto const& t : jtxn)
328 checkDeliveredAmount.checkTxn(t, t[jss::metaData]));
329 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
342 Env env{*
this, features};
345 env, alice, {.holders = {bob, carol}, .close =
false});
348 {.transferFee = 25000,
352 auto const MPT = mptAlice[
"MPT"];
354 mptAlice.authorize({.account = bob});
355 mptAlice.authorize({.account = carol});
358 mptAlice.pay(alice, bob, 10000);
367 Json::Value meta = env.rpc(
"tx", txHash)[jss::result][jss::meta];
369 if (features[fixMPTDeliveredAmount])
372 meta[sfDeliveredAmount.jsonName] ==
375 meta[jss::delivered_amount] ==
380 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
382 meta[jss::delivered_amount] =
Json::Value(
"unavailable"));
385 env(
pay(bob, carol,
MPT(1000)),
391 meta = env.rpc(
"tx", txHash)[jss::result][jss::meta];
393 if (features[fixMPTDeliveredAmount])
396 meta[sfDeliveredAmount.jsonName] ==
399 meta[jss::delivered_amount] ==
404 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
406 meta[jss::delivered_amount] =
Json::Value(
"unavailable"));
414 using namespace test::jtx;
bool isMember(char const *key) const
Return true if the object has a member named key.
testcase_t testcase
Memberspace for declaring test cases.
virtual Config & config()=0
Json::Value getJson(JsonOptions=JsonOptions::none) const override
CheckDeliveredAmount(bool afterSwitchTime)
void adjCountersSuccess()
void adjCounters(bool success, bool partial)
int numExpectedSetUnavailable_
int numExpectedAvailable_
void adjCountersPartialPayment()
bool checkExpectedCounters() const
bool checkTxn(Json::Value const &t, Json::Value const &metaData)
void testAccountDeliveredAmountSubscribe()
void testTxDeliveredAmountRPC()
void testMPTDeliveredAmountRPC(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
void require(Args const &... args)
Check a set of requirements.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
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)
void create(MPTCreate const &arg=MPTCreate{})
Converts to MPT Issue or STAmount.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Sets the SendMax on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
@ arrayValue
array value (ordered list)
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
FeatureBitset testable_amendments()
XRP_t const XRP
Converts to XRP Issue or STAmount.
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpc_version, 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.
constexpr std::uint32_t const tfMPTCanTransfer
constexpr std::uint32_t tfPartialPayment
std::string to_string(base_uint< Bits, Tag > const &a)