Skip to content

Commit d07beac

Browse files
committed
Add additional ledger send by test rippled implementation
1 parent 981c682 commit d07beac

File tree

1 file changed

+71
-49
lines changed

1 file changed

+71
-49
lines changed

src/test/main_test.cpp

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ extern const char ledgerEntryIss[];
8282
extern const char accTxLoc[];
8383
extern const char accTxIss[];
8484

85-
extern const char ledgerLoc1[];
86-
extern const char ledgerIss1[];
85+
extern const char ledgerAdvance[];
8786
extern const char accTxLoc1[];
8887
extern const char accTxLoc2[];
8988
extern const char accInfoIss1[];
@@ -142,6 +141,7 @@ class engineLoc
142141
{
143142
std::atomic_bool clientInit_ = false;
144143
unsigned accTxCtr = 0;
144+
unsigned closed_ledger = 5;
145145

146146
public:
147147
Json::Value
@@ -181,6 +181,7 @@ class engineLoc
181181

182182
if (!clientInit_)
183183
{
184+
DBG(std::cout << side() << " clientInit" << std::endl;)
184185
std::unique_lock l(gMcv);
185186
clientInit_ = true;
186187
gCv.notify_all();
@@ -192,33 +193,44 @@ class engineLoc
192193
Json::Value jv;
193194
Json::Reader().parse(s, jv);
194195
return jv;
195-
};
196+
}
196197

197198
bool
198199
clientInit() const
199200
{
200201
return clientInit_;
201-
};
202+
}
202203

203204
Json::Value
204-
getNewLedger() const
205+
getNewLedger()
205206
{
207+
++closed_ledger;
206208
Json::Value jv;
207-
Json::Reader().parse(ledgerLoc1, jv);
209+
Json::Reader().parse(
210+
fmt::format(
211+
fmt::runtime(prepForFmt(ledgerAdvance)),
212+
"closed_ledger"_a = closed_ledger),
213+
jv);
208214
return jv;
209215
}
210216

211217
bool
212218
attSubmitted() const
213219
{
214220
return false;
215-
};
221+
}
216222

217223
bool
218224
blobOk() const
219225
{
220226
return false;
221-
};
227+
}
228+
229+
std::string
230+
side() const
231+
{
232+
return "locking";
233+
}
222234
};
223235

224236
class engineIss
@@ -228,6 +240,7 @@ class engineIss
228240
std::atomic_bool blobOk_ = false;
229241
unsigned accInfoCtr = 0;
230242
unsigned accTxCtr = 0;
243+
unsigned closed_ledger = 4;
231244

232245
public:
233246
Json::Value
@@ -274,6 +287,7 @@ class engineIss
274287

275288
if (!clientInit_)
276289
{
290+
DBG(std::cout << side() << " clientInit" << std::endl;)
277291
std::unique_lock l(gMcv);
278292
clientInit_ = true;
279293
gCv.notify_all();
@@ -292,33 +306,44 @@ class engineIss
292306
Json::Value jv;
293307
Json::Reader().parse(s, jv);
294308
return jv;
295-
};
309+
}
296310

297311
bool
298312
clientInit() const
299313
{
300314
return clientInit_;
301-
};
315+
}
302316

303317
Json::Value
304-
getNewLedger() const
318+
getNewLedger()
305319
{
320+
++closed_ledger;
306321
Json::Value jv;
307-
Json::Reader().parse(ledgerIss1, jv);
322+
Json::Reader().parse(
323+
fmt::format(
324+
fmt::runtime(prepForFmt(ledgerAdvance)),
325+
"closed_ledger"_a = closed_ledger),
326+
jv);
308327
return jv;
309328
}
310329

311330
bool
312331
attSubmitted() const
313332
{
314333
return attSubmitted_;
315-
};
334+
}
316335

317336
bool
318337
blobOk() const
319338
{
320339
return blobOk_;
321-
};
340+
}
341+
342+
std::string
343+
side() const
344+
{
345+
return "issuing";
346+
}
322347
};
323348

324349
//------------------------------------------------------------------------------
@@ -398,13 +423,24 @@ class session : public std::enable_shared_from_this<session<engine>>
398423

399424
Json::Value jv;
400425
Json::Reader().parse(
401-
static_cast<const char*>(buffer_.data().data()), jv);
426+
static_cast<char const*>(buffer_.data().data()), jv);
402427
auto const jr = e_.process(jv);
428+
429+
auto const method = jv[ripple::jss::method].asString();
430+
if (method == "ledger_entry")
431+
{
432+
t_.expires_after(1s);
433+
t_.async_wait([this](const boost::system::error_code&) {
434+
return this->sendNewLedger();
435+
});
436+
}
437+
403438
if (!clientInit_)
404439
{
405440
if (e_.clientInit())
406441
{
407442
clientInit_ = true;
443+
t_.expires_after(1s);
408444
t_.async_wait([this](const boost::system::error_code&) {
409445
return this->sendNewLedger();
410446
});
@@ -465,7 +501,7 @@ class session : public std::enable_shared_from_this<session<engine>>
465501
void
466502
sendNewLedger()
467503
{
468-
DBG(std::cout << "session::sendNewLedger()" << std::endl;)
504+
DBG(std::cout << e_.side() << " session::sendNewLedger()" << std::endl;)
469505
auto const jv = e_.getNewLedger();
470506
auto const s = to_string(jv);
471507

@@ -481,7 +517,7 @@ class session : public std::enable_shared_from_this<session<engine>>
481517
void
482518
onWriteNewLedger(boost::beast::error_code ec, std::size_t bytes_transferred)
483519
{
484-
DBG(std::cout << "session::onWriteNewLedger(), ec:" << ec
520+
DBG(std::cout << e_.side() << " session::onWriteNewLedger(), ec:" << ec
485521
<< " bytes: " << bytes_transferred << std::endl;)
486522
boost::ignore_unused(bytes_transferred);
487523
if (ec == websocket::error::closed)
@@ -494,13 +530,13 @@ class session : public std::enable_shared_from_this<session<engine>>
494530
attSubmitted() const
495531
{
496532
return e_.attSubmitted();
497-
};
533+
}
498534

499535
bool
500536
blobOk() const
501537
{
502538
return e_.blobOk();
503-
};
539+
}
504540
};
505541

506542
//------------------------------------------------------------------------------
@@ -567,13 +603,13 @@ class listener : public std::enable_shared_from_this<listener<engine>>
567603
bool
568604
attSubmitted() const
569605
{
570-
return session_ ? session_->attSubmitted(): false;
606+
return session_ ? session_->attSubmitted() : false;
571607
};
572608

573609
bool
574610
blobOk() const
575611
{
576-
return session_ ? session_->blobOk(): false;
612+
return session_ ? session_->blobOk() : false;
577613
};
578614

579615
private:
@@ -677,7 +713,8 @@ struct Connection
677713
(serverIss_ ? serverIss_->clientInit() : false);
678714
}
679715

680-
bool checkAtt() const
716+
bool
717+
checkAtt() const
681718
{
682719
return (serverIss_ ? serverIss_->attSubmitted() : false) &&
683720
(serverIss_ ? serverIss_->blobOk() : false);
@@ -720,7 +757,7 @@ class Main_test : public beast::unit_test::suite
720757
gApp->start();
721758

722759
// wait till server send all the messages
723-
wait_for(5s, [&c]() {
760+
wait_for(7s, [&c]() {
724761
return c.clientInit();
725762
} DBG_ARGS("Wait for App init"));
726763
BEAST_EXPECT(c.clientInit());
@@ -1357,7 +1394,7 @@ const char accTxLoc[] = R"str(
13571394
"jsonrpc": "2.0",
13581395
"result": {
13591396
"account": "rL9vUaa9eBas32C5bgv4fEmHDfJr3oNd4D",
1360-
"ledger_index_max": 5,
1397+
"ledger_index_max": 6,
13611398
"ledger_index_min": 2,
13621399
"limit": 10,
13631400
"transactions": [
@@ -1698,7 +1735,7 @@ const char accTxIss[] = R"str(
16981735
"jsonrpc": "2.0",
16991736
"result": {
17001737
"account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
1701-
"ledger_index_max": 4,
1738+
"ledger_index_max": 5,
17021739
"ledger_index_min": 2,
17031740
"limit": 10,
17041741
"transactions": [
@@ -1969,33 +2006,18 @@ const char accTxIss[] = R"str(
19692006
}
19702007
)str";
19712008

1972-
const char ledgerLoc1[] = R"str(
2009+
const char ledgerAdvance[] = R"str(
19732010
{
19742011
"fee_base" : 10,
19752012
"fee_ref" : 10,
1976-
"ledger_hash" : "614D49AAB66C02D6D190D101BA0BFBEB157A60D52ABF6547FBF4DA4B3324034D",
1977-
"ledger_index" : 7,
1978-
"ledger_time" : 752637130,
2013+
"ledger_hash" : "B66BEC6A8C3A3585880B37B600A88B0B280104DCC2F4CCB2DED9C605113FE13E",
2014+
"ledger_index" : `closed_ledger`,
2015+
"ledger_time" : 766541670,
19792016
"reserve_base" : 10000000,
19802017
"reserve_inc" : 2000000,
19812018
"txn_count" : 1,
19822019
"type" : "ledgerClosed",
1983-
"validated_ledgers" : "2-7"
1984-
}
1985-
)str";
1986-
1987-
const char ledgerIss1[] = R"str(
1988-
{
1989-
"fee_base" : 10,
1990-
"fee_ref" : 10,
1991-
"ledger_hash" : "1BDC7FEDA9F41E30939D76D6BBD12ACE20CE36025CE879A303F0C434B17536DB",
1992-
"ledger_index" : 5,
1993-
"ledger_time" : 752637130,
1994-
"reserve_base" : 10000000,
1995-
"reserve_inc" : 2000000,
1996-
"txn_count" : 0,
1997-
"type" : "ledgerClosed",
1998-
"validated_ledgers" : "2-5"
2020+
"validated_ledgers" : "2-`closed_ledger`"
19992021
}
20002022
)str";
20012023

@@ -2184,8 +2206,8 @@ const char accTxIss1[] = R"str(
21842206
"jsonrpc" : "2.0",
21852207
"result" : {
21862208
"account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
2187-
"ledger_index_max" : 5,
2188-
"ledger_index_min" : 5,
2209+
"ledger_index_max" : 6,
2210+
"ledger_index_min" : 6,
21892211
"limit" : 10,
21902212
"transactions" : [],
21912213
"validated" : true
@@ -2202,8 +2224,8 @@ const char accTxIss2[] = R"str(
22022224
"jsonrpc" : "2.0",
22032225
"result" : {
22042226
"account" : "rnscFKLtPLn9MnUZh8EHi2KEnJR6qcZXWg",
2205-
"ledger_index_max" : 5,
2206-
"ledger_index_min" : 5,
2227+
"ledger_index_max" : 6,
2228+
"ledger_index_min" : 6,
22072229
"limit" : 10,
22082230
"transactions" : [],
22092231
"validated" : true

0 commit comments

Comments
 (0)