@@ -191,80 +191,73 @@ class DeliveredAmount_test : public beast::unit_test::suite
191191 auto const gw = Account (" gateway" );
192192 auto const USD = gw[" USD" ];
193193
194- for (bool const afterSwitchTime : {true , false })
194+ Env env{*this , features};
195+ env.fund (XRP (10000 ), alice, bob, carol, gw);
196+ env.trust (USD (1000 ), alice, bob, carol);
197+ env.close ();
198+
199+ CheckDeliveredAmount checkDeliveredAmount{true };
195200 {
196- Env env{*this , features};
197- env.fund (XRP (10000 ), alice, bob, carol, gw);
198- env.trust (USD (1000 ), alice, bob, carol);
199- if (afterSwitchTime)
200- env.close (NetClock::time_point{446000000s});
201- else
202- env.close ();
201+ // add payments, but do no close until subscribed
203202
204- CheckDeliveredAmount checkDeliveredAmount{afterSwitchTime};
205- {
206- // add payments, but do no close until subscribed
207-
208- // normal payments
209- env (pay (gw, alice, USD (50 )));
210- checkDeliveredAmount.adjCountersSuccess ();
211- env (pay (gw, alice, XRP (50 )));
212- checkDeliveredAmount.adjCountersSuccess ();
213-
214- // partial payment
215- env (pay (gw, bob, USD (9999999 )), txflags (tfPartialPayment));
216- checkDeliveredAmount.adjCountersPartialPayment ();
217- env.require (balance (bob, USD (1000 )));
218-
219- // failed payment
220- env (pay (bob, carol, USD (9999999 )), ter (tecPATH_PARTIAL));
221- checkDeliveredAmount.adjCountersFail ();
222- env.require (balance (carol, USD (0 )));
223- }
203+ // normal payments
204+ env (pay (gw, alice, USD (50 )));
205+ checkDeliveredAmount.adjCountersSuccess ();
206+ env (pay (gw, alice, XRP (50 )));
207+ checkDeliveredAmount.adjCountersSuccess ();
224208
225- auto wsc = makeWSClient (env.app ().config ());
209+ // partial payment
210+ env (pay (gw, bob, USD (9999999 )), txflags (tfPartialPayment));
211+ checkDeliveredAmount.adjCountersPartialPayment ();
212+ env.require (balance (bob, USD (1000 )));
226213
214+ // failed payment
215+ env (pay (bob, carol, USD (9999999 )), ter (tecPATH_PARTIAL));
216+ checkDeliveredAmount.adjCountersFail ();
217+ env.require (balance (carol, USD (0 )));
218+ }
219+
220+ auto wsc = makeWSClient (env.app ().config ());
221+
222+ {
223+ Json::Value stream;
224+ // RPC subscribe to ledger stream
225+ stream[jss::streams] = Json::arrayValue;
226+ stream[jss::streams].append (" ledger" );
227+ stream[jss::accounts] = Json::arrayValue;
228+ stream[jss::accounts].append (toBase58 (alice.id ()));
229+ stream[jss::accounts].append (toBase58 (bob.id ()));
230+ stream[jss::accounts].append (toBase58 (carol.id ()));
231+ auto jv = wsc->invoke (" subscribe" , stream);
232+ if (wsc->version () == 2 )
227233 {
228- Json::Value stream;
229- // RPC subscribe to ledger stream
230- stream[jss::streams] = Json::arrayValue;
231- stream[jss::streams].append (" ledger" );
232- stream[jss::accounts] = Json::arrayValue;
233- stream[jss::accounts].append (toBase58 (alice.id ()));
234- stream[jss::accounts].append (toBase58 (bob.id ()));
235- stream[jss::accounts].append (toBase58 (carol.id ()));
236- auto jv = wsc->invoke (" subscribe" , stream);
237- if (wsc->version () == 2 )
238- {
239- BEAST_EXPECT (
240- jv.isMember (jss::jsonrpc) && jv[jss::jsonrpc] == " 2.0" );
241- BEAST_EXPECT (
242- jv.isMember (jss::ripplerpc) &&
243- jv[jss::ripplerpc] == " 2.0" );
244- BEAST_EXPECT (jv.isMember (jss::id) && jv[jss::id] == 5 );
245- }
246- BEAST_EXPECT (jv[jss::result][jss::ledger_index] == 3 );
234+ BEAST_EXPECT (
235+ jv.isMember (jss::jsonrpc) && jv[jss::jsonrpc] == " 2.0" );
236+ BEAST_EXPECT (
237+ jv.isMember (jss::ripplerpc) && jv[jss::ripplerpc] == " 2.0" );
238+ BEAST_EXPECT (jv.isMember (jss::id) && jv[jss::id] == 5 );
247239 }
240+ BEAST_EXPECT (jv[jss::result][jss::ledger_index] == 3 );
241+ }
242+ {
243+ env.close ();
244+ // Check stream update
245+ while (true )
248246 {
249- env.close ();
250- // Check stream update
251- while (true )
252- {
253- auto const r = wsc->findMsg (1s, [&](auto const & jv) {
254- return jv[jss::ledger_index] == 4 ;
255- });
256- if (!r)
257- break ;
247+ auto const r = wsc->findMsg (1s, [&](auto const & jv) {
248+ return jv[jss::ledger_index] == 4 ;
249+ });
250+ if (!r)
251+ break ;
258252
259- if (!r->isMember (jss::transaction))
260- continue ;
253+ if (!r->isMember (jss::transaction))
254+ continue ;
261255
262- BEAST_EXPECT (checkDeliveredAmount.checkTxn (
263- (*r)[jss::transaction], (*r)[jss::meta]));
264- }
256+ BEAST_EXPECT (checkDeliveredAmount.checkTxn (
257+ (*r)[jss::transaction], (*r)[jss::meta]));
265258 }
266- BEAST_EXPECT (checkDeliveredAmount.checkExpectedCounters ());
267259 }
260+ BEAST_EXPECT (checkDeliveredAmount.checkExpectedCounters ());
268261 }
269262 void
270263 testTxDeliveredAmountRPC (FeatureBitset features)
@@ -280,49 +273,41 @@ class DeliveredAmount_test : public beast::unit_test::suite
280273 auto const gw = Account (" gateway" );
281274 auto const USD = gw[" USD" ];
282275
283- for (bool const afterSwitchTime : {true , false })
284- {
285- Env env{*this , features};
286- env.fund (XRP (10000 ), alice, bob, carol, gw);
287- env.trust (USD (1000 ), alice, bob, carol);
288- if (afterSwitchTime)
289- env.close (NetClock::time_point{446000000s});
290- else
291- env.close ();
292-
293- CheckDeliveredAmount checkDeliveredAmount{afterSwitchTime};
294- // normal payments
295- env (pay (gw, alice, USD (50 )));
296- checkDeliveredAmount.adjCountersSuccess ();
297- env (pay (gw, alice, XRP (50 )));
298- checkDeliveredAmount.adjCountersSuccess ();
299-
300- // partial payment
301- env (pay (gw, bob, USD (9999999 )), txflags (tfPartialPayment));
302- checkDeliveredAmount.adjCountersPartialPayment ();
303- env.require (balance (bob, USD (1000 )));
304-
305- // failed payment
306- env (pay (gw, carol, USD (9999999 )), ter (tecPATH_PARTIAL));
307- checkDeliveredAmount.adjCountersFail ();
308- env.require (balance (carol, USD (0 )));
309-
310- env.close ();
311- std::string index;
312- Json::Value jvParams;
313- jvParams[jss::ledger_index] = 4u ;
314- jvParams[jss::transactions] = true ;
315- jvParams[jss::expand] = true ;
316- auto const jtxn = env.rpc (
317- " json" ,
318- " ledger" ,
319- to_string (
320- jvParams))[jss::result][jss::ledger][jss::transactions];
321- for (auto const & t : jtxn)
322- BEAST_EXPECT (
323- checkDeliveredAmount.checkTxn (t, t[jss::metaData]));
324- BEAST_EXPECT (checkDeliveredAmount.checkExpectedCounters ());
325- }
276+ Env env{*this , features};
277+ env.fund (XRP (10000 ), alice, bob, carol, gw);
278+ env.trust (USD (1000 ), alice, bob, carol);
279+ env.close ();
280+
281+ CheckDeliveredAmount checkDeliveredAmount{true };
282+ // normal payments
283+ env (pay (gw, alice, USD (50 )));
284+ checkDeliveredAmount.adjCountersSuccess ();
285+ env (pay (gw, alice, XRP (50 )));
286+ checkDeliveredAmount.adjCountersSuccess ();
287+
288+ // partial payment
289+ env (pay (gw, bob, USD (9999999 )), txflags (tfPartialPayment));
290+ checkDeliveredAmount.adjCountersPartialPayment ();
291+ env.require (balance (bob, USD (1000 )));
292+
293+ // failed payment
294+ env (pay (gw, carol, USD (9999999 )), ter (tecPATH_PARTIAL));
295+ checkDeliveredAmount.adjCountersFail ();
296+ env.require (balance (carol, USD (0 )));
297+
298+ env.close ();
299+ std::string index;
300+ Json::Value jvParams;
301+ jvParams[jss::ledger_index] = 4u ;
302+ jvParams[jss::transactions] = true ;
303+ jvParams[jss::expand] = true ;
304+ auto const jtxn = env.rpc (
305+ " json" ,
306+ " ledger" ,
307+ to_string (jvParams))[jss::result][jss::ledger][jss::transactions];
308+ for (auto const & t : jtxn)
309+ BEAST_EXPECT (checkDeliveredAmount.checkTxn (t, t[jss::metaData]));
310+ BEAST_EXPECT (checkDeliveredAmount.checkExpectedCounters ());
326311 }
327312
328313public:
0 commit comments