2#include <test/jtx/WSClient.h>
4#include <xrpl/beast/unit_test.h>
5#include <xrpl/beast/unit_test/suite.h>
6#include <xrpl/protocol/jss.h>
87 if (t[jss::TransactionType].asString() != jss::Payment)
90 bool isSet = metaData.
isMember(jss::delivered_amount);
91 bool isSetUnavailable =
false;
92 bool isSetAvailable =
false;
95 if (metaData[jss::delivered_amount] !=
"unavailable")
96 isSetAvailable =
true;
98 isSetUnavailable =
true;
102 else if (isSetUnavailable)
109 if (metaData.
isMember(sfDeliveredAmount.jsonName))
111 if (metaData[jss::delivered_amount] !=
112 metaData[sfDeliveredAmount.jsonName])
119 if (metaData[jss::delivered_amount] != t[jss::Amount])
124 if (metaData[jss::delivered_amount] !=
"unavailable")
130 if (metaData[sfTransactionResult.jsonName] !=
"tesSUCCESS")
144 if (metaData.
isMember(sfDeliveredAmount.jsonName))
151 if (!isSetUnavailable)
165 testcase(
"Ledger Request Subscribe DeliveredAmount");
167 using namespace test::jtx;
168 using namespace std::chrono_literals;
173 auto const gw =
Account(
"gateway");
174 auto const USD = gw[
"USD"];
176 for (
bool const afterSwitchTime : {
true,
false})
179 cfg->FEES.reference_fee = 10;
180 Env env(*
this, std::move(cfg));
181 env.
fund(
XRP(10000), alice, bob, carol, gw);
182 env.
trust(USD(1000), alice, bob, carol);
193 env(
pay(gw, alice, USD(50)));
194 checkDeliveredAmount.adjCountersSuccess();
195 env(
pay(gw, alice,
XRP(50)));
196 checkDeliveredAmount.adjCountersSuccess();
200 checkDeliveredAmount.adjCountersPartialPayment();
205 checkDeliveredAmount.adjCountersFail();
215 stream[jss::streams].append(
"ledger");
217 stream[jss::accounts].append(
toBase58(alice.
id()));
218 stream[jss::accounts].append(
toBase58(bob.
id()));
219 stream[jss::accounts].append(
toBase58(carol.
id()));
220 auto jv = wsc->invoke(
"subscribe", stream);
221 if (wsc->version() == 2)
224 jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] ==
"2.0");
226 jv.isMember(jss::ripplerpc) &&
227 jv[jss::ripplerpc] ==
"2.0");
228 BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5);
230 BEAST_EXPECT(jv[jss::result][jss::ledger_index] == 3);
237 auto const r = wsc->findMsg(1s, [&](
auto const& jv) {
238 return jv[jss::ledger_index] == 4;
243 if (!r->isMember(jss::transaction))
246 BEAST_EXPECT(checkDeliveredAmount.checkTxn(
247 (*r)[jss::transaction], (*r)[jss::meta]));
250 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
256 testcase(
"Ledger Request RPC DeliveredAmount");
258 using namespace test::jtx;
259 using namespace std::chrono_literals;
264 auto const gw =
Account(
"gateway");
265 auto const USD = gw[
"USD"];
267 for (
bool const afterSwitchTime : {
true,
false})
270 cfg->FEES.reference_fee = 10;
271 Env env(*
this, std::move(cfg));
272 env.
fund(
XRP(10000), alice, bob, carol, gw);
273 env.
trust(USD(1000), alice, bob, carol);
281 env(
pay(gw, alice, USD(50)));
282 checkDeliveredAmount.adjCountersSuccess();
283 env(
pay(gw, alice,
XRP(50)));
284 checkDeliveredAmount.adjCountersSuccess();
288 checkDeliveredAmount.adjCountersPartialPayment();
293 checkDeliveredAmount.adjCountersFail();
299 jvParams[jss::ledger_index] = 4u;
300 jvParams[jss::transactions] =
true;
301 jvParams[jss::expand] =
true;
302 auto const jtxn = env.
rpc(
306 jvParams))[jss::result][jss::ledger][jss::transactions];
307 for (
auto const& t : jtxn)
309 checkDeliveredAmount.checkTxn(t, t[jss::metaData]));
310 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
323 Env env{*
this, features};
326 env, alice, {.holders = {bob, carol}, .close =
false});
329 {.transferFee = 25000,
333 auto const MPT = mptAlice[
"MPT"];
335 mptAlice.authorize({.account = bob});
336 mptAlice.authorize({.account = carol});
339 mptAlice.pay(alice, bob, 10000);
348 Json::Value meta = env.rpc(
"tx", txHash)[jss::result][jss::meta];
350 if (features[fixMPTDeliveredAmount])
353 meta[sfDeliveredAmount.jsonName] ==
356 meta[jss::delivered_amount] ==
361 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
363 meta[jss::delivered_amount] =
Json::Value(
"unavailable"));
366 env(
pay(bob, carol,
MPT(1000)),
372 meta = env.rpc(
"tx", txHash)[jss::result][jss::meta];
374 if (features[fixMPTDeliveredAmount])
377 meta[sfDeliveredAmount.jsonName] ==
380 meta[jss::delivered_amount] ==
385 BEAST_EXPECT(!meta.
isMember(sfDeliveredAmount.jsonName));
387 meta[jss::delivered_amount] =
Json::Value(
"unavailable"));
395 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)