21#include <test/jtx/WSClient.h>
23#include <xrpl/beast/unit_test.h>
24#include <xrpl/protocol/jss.h>
105 if (t[jss::TransactionType].asString() != jss::Payment)
108 bool isSet = metaData.
isMember(jss::delivered_amount);
109 bool isSetUnavailable =
false;
110 bool isSetAvailable =
false;
113 if (metaData[jss::delivered_amount] !=
"unavailable")
114 isSetAvailable =
true;
116 isSetUnavailable =
true;
120 else if (isSetUnavailable)
127 if (metaData.
isMember(sfDeliveredAmount.jsonName))
129 if (metaData[jss::delivered_amount] !=
130 metaData[sfDeliveredAmount.jsonName])
137 if (metaData[jss::delivered_amount] != t[jss::Amount])
142 if (metaData[jss::delivered_amount] !=
"unavailable")
148 if (metaData[sfTransactionResult.jsonName] !=
"tesSUCCESS")
162 if (metaData.
isMember(sfDeliveredAmount.jsonName))
169 if (!isSetUnavailable)
183 testcase(
"Ledger Request Subscribe DeliveredAmount");
185 using namespace test::jtx;
186 using namespace std::chrono_literals;
191 auto const gw =
Account(
"gateway");
192 auto const USD = gw[
"USD"];
194 for (
bool const afterSwitchTime : {
true,
false})
197 cfg->FEES.reference_fee = 10;
198 Env env(*
this, std::move(cfg));
199 env.
fund(
XRP(10000), alice, bob, carol, gw);
200 env.
trust(USD(1000), alice, bob, carol);
211 env(
pay(gw, alice, USD(50)));
212 checkDeliveredAmount.adjCountersSuccess();
213 env(
pay(gw, alice,
XRP(50)));
214 checkDeliveredAmount.adjCountersSuccess();
218 checkDeliveredAmount.adjCountersPartialPayment();
223 checkDeliveredAmount.adjCountersFail();
233 stream[jss::streams].append(
"ledger");
235 stream[jss::accounts].append(
toBase58(alice.
id()));
236 stream[jss::accounts].append(
toBase58(bob.
id()));
237 stream[jss::accounts].append(
toBase58(carol.
id()));
238 auto jv = wsc->invoke(
"subscribe", stream);
239 if (wsc->version() == 2)
242 jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] ==
"2.0");
244 jv.isMember(jss::ripplerpc) &&
245 jv[jss::ripplerpc] ==
"2.0");
246 BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5);
248 BEAST_EXPECT(jv[jss::result][jss::ledger_index] == 3);
255 auto const r = wsc->findMsg(1s, [&](
auto const& jv) {
256 return jv[jss::ledger_index] == 4;
261 if (!r->isMember(jss::transaction))
264 BEAST_EXPECT(checkDeliveredAmount.checkTxn(
265 (*r)[jss::transaction], (*r)[jss::meta]));
268 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
274 testcase(
"Ledger Request RPC DeliveredAmount");
276 using namespace test::jtx;
277 using namespace std::chrono_literals;
282 auto const gw =
Account(
"gateway");
283 auto const USD = gw[
"USD"];
285 for (
bool const afterSwitchTime : {
true,
false})
288 cfg->FEES.reference_fee = 10;
289 Env env(*
this, std::move(cfg));
290 env.
fund(
XRP(10000), alice, bob, carol, gw);
291 env.
trust(USD(1000), alice, bob, carol);
299 env(
pay(gw, alice, USD(50)));
300 checkDeliveredAmount.adjCountersSuccess();
301 env(
pay(gw, alice,
XRP(50)));
302 checkDeliveredAmount.adjCountersSuccess();
306 checkDeliveredAmount.adjCountersPartialPayment();
311 checkDeliveredAmount.adjCountersFail();
317 jvParams[jss::ledger_index] = 4u;
318 jvParams[jss::transactions] =
true;
319 jvParams[jss::expand] =
true;
320 auto const jtxn = env.
rpc(
324 jvParams))[jss::result][jss::ledger][jss::transactions];
325 for (
auto const& t : jtxn)
327 checkDeliveredAmount.checkTxn(t, t[jss::metaData]));
328 BEAST_EXPECT(checkDeliveredAmount.checkExpectedCounters());
341BEAST_DEFINE_TESTSUITE(DeliveredAmount, app,
ripple);
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
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 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)
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
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 tfPartialPayment
std::string to_string(base_uint< Bits, Tag > const &a)