mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 03:35:55 +00:00
@@ -96,7 +96,7 @@ SubscriptionManager::forwardProposedTransaction(boost::json::object const& recei
|
||||
boost::json::object
|
||||
SubscriptionManager::subLedger(boost::asio::yield_context yield, SubscriberSharedPtr const& subscriber)
|
||||
{
|
||||
return ledgerFeed_.sub(yield, backend_, subscriber);
|
||||
return ledgerFeed_.sub(yield, backend_, subscriber, networkID_);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -113,7 +113,7 @@ SubscriptionManager::pubLedger(
|
||||
std::uint32_t const txnCount
|
||||
)
|
||||
{
|
||||
ledgerFeed_.pub(lgrInfo, fees, ledgerRange, txnCount);
|
||||
ledgerFeed_.pub(lgrInfo, fees, ledgerRange, txnCount, networkID_);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -44,7 +44,8 @@ LedgerFeed::makeLedgerPubMessage(
|
||||
ripple::LedgerHeader const& lgrInfo,
|
||||
ripple::Fees const& fees,
|
||||
std::string const& ledgerRange,
|
||||
std::uint32_t const txnCount
|
||||
uint32_t const txnCount,
|
||||
uint32_t const networkID
|
||||
)
|
||||
{
|
||||
boost::json::object pubMsg;
|
||||
@@ -57,6 +58,7 @@ LedgerFeed::makeLedgerPubMessage(
|
||||
pubMsg["reserve_inc"] = rpc::toBoostJson(fees.increment.jsonClipped());
|
||||
pubMsg["validated_ledgers"] = ledgerRange;
|
||||
pubMsg["txn_count"] = txnCount;
|
||||
pubMsg["network_id"] = networkID;
|
||||
return pubMsg;
|
||||
}
|
||||
|
||||
@@ -64,7 +66,8 @@ boost::json::object
|
||||
LedgerFeed::sub(
|
||||
boost::asio::yield_context yield,
|
||||
std::shared_ptr<data::BackendInterface const> const& backend,
|
||||
SubscriberSharedPtr const& subscriber
|
||||
SubscriberSharedPtr const& subscriber,
|
||||
uint32_t const networkID
|
||||
)
|
||||
{
|
||||
SingleFeedBase::sub(subscriber);
|
||||
@@ -81,7 +84,7 @@ LedgerFeed::sub(
|
||||
|
||||
auto const range = std::to_string(ledgerRange->minSequence) + "-" + std::to_string(ledgerRange->maxSequence);
|
||||
|
||||
auto pubMsg = makeLedgerPubMessage(*lgrInfo, *fees, range, 0);
|
||||
auto pubMsg = makeLedgerPubMessage(*lgrInfo, *fees, range, 0, networkID);
|
||||
pubMsg.erase("txn_count");
|
||||
pubMsg.erase("type");
|
||||
|
||||
@@ -93,9 +96,10 @@ LedgerFeed::pub(
|
||||
ripple::LedgerHeader const& lgrInfo,
|
||||
ripple::Fees const& fees,
|
||||
std::string const& ledgerRange,
|
||||
std::uint32_t const txnCount
|
||||
uint32_t const txnCount,
|
||||
uint32_t const networkID
|
||||
)
|
||||
{
|
||||
SingleFeedBase::pub(boost::json::serialize(makeLedgerPubMessage(lgrInfo, fees, ledgerRange, txnCount)));
|
||||
SingleFeedBase::pub(boost::json::serialize(makeLedgerPubMessage(lgrInfo, fees, ledgerRange, txnCount, networkID)));
|
||||
}
|
||||
} // namespace feed::impl
|
||||
|
||||
@@ -63,7 +63,8 @@ public:
|
||||
boost::json::object
|
||||
sub(boost::asio::yield_context yield,
|
||||
std::shared_ptr<data::BackendInterface const> const& backend,
|
||||
SubscriberSharedPtr const& subscriber);
|
||||
SubscriberSharedPtr const& subscriber,
|
||||
uint32_t networkID);
|
||||
|
||||
/**
|
||||
* @brief Publishes the ledger feed.
|
||||
@@ -76,7 +77,8 @@ public:
|
||||
pub(ripple::LedgerHeader const& lgrInfo,
|
||||
ripple::Fees const& fees,
|
||||
std::string const& ledgerRange,
|
||||
std::uint32_t txnCount);
|
||||
uint32_t txnCount,
|
||||
uint32_t networkID);
|
||||
|
||||
private:
|
||||
static boost::json::object
|
||||
@@ -84,7 +86,8 @@ private:
|
||||
ripple::LedgerHeader const& lgrInfo,
|
||||
ripple::Fees const& fees,
|
||||
std::string const& ledgerRange,
|
||||
std::uint32_t txnCount
|
||||
uint32_t txnCount,
|
||||
uint32_t networkID
|
||||
);
|
||||
};
|
||||
} // namespace feed::impl
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
@@ -46,6 +47,7 @@ protected:
|
||||
std::shared_ptr<TestedFeed> testFeedPtr = std::make_shared<TestedFeed>(ctx_);
|
||||
MockSession* mockSessionPtr = dynamic_cast<MockSession*>(sessionPtr.get());
|
||||
StrictMockAmendmentCenterSharedPtr mockAmendmentCenterPtr_;
|
||||
uint32_t const networkID{123};
|
||||
};
|
||||
|
||||
namespace feed::impl {
|
||||
|
||||
@@ -60,12 +60,13 @@ TEST_F(FeedLedgerTest, SubPub)
|
||||
"ledger_time": 0,
|
||||
"fee_base": 1,
|
||||
"reserve_base": 3,
|
||||
"reserve_inc": 2
|
||||
"reserve_inc": 2,
|
||||
"network_id": 123
|
||||
})JSON";
|
||||
boost::asio::io_context ioContext;
|
||||
util::spawn(ioContext, [this](boost::asio::yield_context yield) {
|
||||
EXPECT_CALL(*mockSessionPtr, onDisconnect);
|
||||
auto res = testFeedPtr->sub(yield, backend_, sessionPtr);
|
||||
auto res = testFeedPtr->sub(yield, backend_, sessionPtr, networkID);
|
||||
// check the response
|
||||
EXPECT_EQ(res, json::parse(kLEDGER_RESPONSE));
|
||||
});
|
||||
@@ -82,7 +83,8 @@ TEST_F(FeedLedgerTest, SubPub)
|
||||
"reserve_base": 10,
|
||||
"reserve_inc": 0,
|
||||
"validated_ledgers": "10-31",
|
||||
"txn_count": 8
|
||||
"txn_count": 8,
|
||||
"network_id": 123
|
||||
})JSON";
|
||||
|
||||
// test publish
|
||||
@@ -90,13 +92,13 @@ TEST_F(FeedLedgerTest, SubPub)
|
||||
auto const ledgerHeader2 = createLedgerHeader(kLEDGER_HASH, 31);
|
||||
auto fee2 = ripple::Fees();
|
||||
fee2.reserve = 10;
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8);
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8, networkID);
|
||||
|
||||
// test unsub, after unsub the send should not be called
|
||||
testFeedPtr->unsub(sessionPtr);
|
||||
EXPECT_EQ(testFeedPtr->count(), 0);
|
||||
EXPECT_CALL(*mockSessionPtr, send(_)).Times(0);
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8);
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8, networkID);
|
||||
}
|
||||
|
||||
TEST_F(FeedLedgerTest, AutoDisconnect)
|
||||
@@ -115,7 +117,8 @@ TEST_F(FeedLedgerTest, AutoDisconnect)
|
||||
"ledger_time": 0,
|
||||
"fee_base": 1,
|
||||
"reserve_base": 3,
|
||||
"reserve_inc": 2
|
||||
"reserve_inc": 2,
|
||||
"network_id": 123
|
||||
})JSON";
|
||||
|
||||
web::SubscriptionContextInterface::OnDisconnectSlot slot;
|
||||
@@ -123,7 +126,7 @@ TEST_F(FeedLedgerTest, AutoDisconnect)
|
||||
|
||||
boost::asio::io_context ioContext;
|
||||
util::spawn(ioContext, [this](boost::asio::yield_context yield) {
|
||||
auto res = testFeedPtr->sub(yield, backend_, sessionPtr);
|
||||
auto res = testFeedPtr->sub(yield, backend_, sessionPtr, networkID);
|
||||
// check the response
|
||||
EXPECT_EQ(res, json::parse(kLEDGER_RESPONSE));
|
||||
});
|
||||
@@ -142,5 +145,5 @@ TEST_F(FeedLedgerTest, AutoDisconnect)
|
||||
auto fee2 = ripple::Fees();
|
||||
fee2.reserve = 10;
|
||||
// no error
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8);
|
||||
testFeedPtr->pub(ledgerHeader2, fee2, "10-31", 8, networkID);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <xrpl/protocol/STObject.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
@@ -75,6 +76,7 @@ protected:
|
||||
std::make_shared<SubscriptionManager>(Execution(2), backend_, mockAmendmentCenterPtr_);
|
||||
web::SubscriptionContextPtr session_ = std::make_shared<MockSession>();
|
||||
MockSession* sessionPtr_ = dynamic_cast<MockSession*>(session_.get());
|
||||
uint32_t const networkID_ = 123;
|
||||
};
|
||||
|
||||
using SubscriptionManagerTest = SubscriptionManagerBaseTest<util::async::SyncExecutionContext>;
|
||||
@@ -271,6 +273,8 @@ TEST_F(SubscriptionManagerTest, BookChangesTest)
|
||||
TEST_F(SubscriptionManagerTest, LedgerTest)
|
||||
{
|
||||
backend_->setRange(10, 30);
|
||||
subscriptionManagerPtr_->setNetworkID(networkID_);
|
||||
|
||||
auto const ledgerHeader = createLedgerHeader(kLEDGER_HASH, 30);
|
||||
EXPECT_CALL(*backend_, fetchLedgerBySequence).WillOnce(testing::Return(ledgerHeader));
|
||||
|
||||
@@ -288,7 +292,8 @@ TEST_F(SubscriptionManagerTest, LedgerTest)
|
||||
"ledger_time": 0,
|
||||
"fee_base": 1,
|
||||
"reserve_base": 3,
|
||||
"reserve_inc": 2
|
||||
"reserve_inc": 2,
|
||||
"network_id": 123
|
||||
})JSON";
|
||||
boost::asio::io_context ctx;
|
||||
util::spawn(ctx, [this](boost::asio::yield_context yield) {
|
||||
@@ -314,7 +319,8 @@ TEST_F(SubscriptionManagerTest, LedgerTest)
|
||||
"reserve_base": 10,
|
||||
"reserve_inc": 0,
|
||||
"validated_ledgers": "10-31",
|
||||
"txn_count": 8
|
||||
"txn_count": 8,
|
||||
"network_id": 123
|
||||
})JSON";
|
||||
EXPECT_CALL(*sessionPtr_, send(sharedStringJsonEq(kLEDGER_PUB)));
|
||||
subscriptionManagerPtr_->pubLedger(ledgerHeader2, fee2, "10-31", 8);
|
||||
|
||||
Reference in New Issue
Block a user