mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-19 11:15:50 +00:00
@@ -21,8 +21,11 @@
|
||||
#include <util/Fixtures.h>
|
||||
#include <util/TestObject.h>
|
||||
|
||||
#include <boost/json.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
using namespace rpc;
|
||||
@@ -337,3 +340,81 @@ TEST_F(RPCHelpersTest, DecodeInvalidCTID)
|
||||
EXPECT_FALSE(decodeCTID('c'));
|
||||
EXPECT_FALSE(decodeCTID(true));
|
||||
}
|
||||
|
||||
TEST_F(RPCHelpersTest, DeliverMaxAliasV1)
|
||||
{
|
||||
std::array<std::string, 3> const inputArray = {
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"Amount": {
|
||||
"test": "test"
|
||||
}
|
||||
})",
|
||||
R"({
|
||||
"TransactionType": "OfferCreate",
|
||||
"Amount": {
|
||||
"test": "test"
|
||||
}
|
||||
})",
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"Amount1": {
|
||||
"test": "test"
|
||||
}
|
||||
})"};
|
||||
|
||||
std::array<std::string, 3> outputArray = {
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"Amount": {
|
||||
"test": "test"
|
||||
},
|
||||
"DeliverMax": {
|
||||
"test": "test"
|
||||
}
|
||||
})",
|
||||
R"({
|
||||
"TransactionType": "OfferCreate",
|
||||
"Amount": {
|
||||
"test": "test"
|
||||
}
|
||||
})",
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"Amount1": {
|
||||
"test": "test"
|
||||
}
|
||||
})"};
|
||||
|
||||
for (size_t i = 0; i < inputArray.size(); i++) {
|
||||
auto req = boost::json::parse(inputArray[i]).as_object();
|
||||
insertDeliverMaxAlias(req, 1);
|
||||
EXPECT_EQ(req, boost::json::parse(outputArray[i]).as_object());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RPCHelpersTest, DeliverMaxAliasV2)
|
||||
{
|
||||
auto req = boost::json::parse(
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"Amount": {
|
||||
"test": "test"
|
||||
}
|
||||
})"
|
||||
)
|
||||
.as_object();
|
||||
|
||||
insertDeliverMaxAlias(req, 2);
|
||||
EXPECT_EQ(
|
||||
req,
|
||||
boost::json::parse(
|
||||
R"({
|
||||
"TransactionType": "Payment",
|
||||
"DeliverMax": {
|
||||
"test": "test"
|
||||
}
|
||||
})"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1714,6 +1714,7 @@ generateTransactionTypeTestValues()
|
||||
"tx": {
|
||||
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"Amount": "1",
|
||||
"DeliverMax": "1",
|
||||
"Destination": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"Fee": "1",
|
||||
"Sequence": 32,
|
||||
@@ -1763,7 +1764,7 @@ generateTransactionTypeTestValues()
|
||||
},
|
||||
"tx": {
|
||||
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"Amount": "1",
|
||||
"DeliverMax": "1",
|
||||
"Destination": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"Fee": "1",
|
||||
"Sequence": 32,
|
||||
|
||||
@@ -468,6 +468,7 @@ TEST_F(RPCLedgerHandlerTest, TransactionsExpandNotBinary)
|
||||
{
|
||||
"Account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"Amount":"100",
|
||||
"DeliverMax":"100",
|
||||
"Destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"Fee":"3",
|
||||
"Sequence":30,
|
||||
@@ -695,6 +696,7 @@ TEST_F(RPCLedgerHandlerTest, OwnerFundsEmtpy)
|
||||
{
|
||||
"Account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"Amount":"100",
|
||||
"DeliverMax":"100",
|
||||
"Destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"Fee":"3",
|
||||
"Sequence":30,
|
||||
|
||||
@@ -288,6 +288,72 @@ TEST_F(RPCTxTest, DefaultParameter_API_v1)
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, PaymentTx_API_v1)
|
||||
{
|
||||
auto const rawBackendPtr = dynamic_cast<MockBackend*>(mockBackendPtr.get());
|
||||
ASSERT_NE(rawBackendPtr, nullptr);
|
||||
|
||||
TransactionAndMetadata tx;
|
||||
tx.transaction = CreatePaymentTransactionObject(ACCOUNT, ACCOUNT2, 2, 3, 300).getSerializer().peekData();
|
||||
tx.metadata = CreatePaymentTransactionMetaObject(ACCOUNT, ACCOUNT2, 110, 30).getSerializer().peekData();
|
||||
tx.date = 123456;
|
||||
tx.ledgerSequence = 100;
|
||||
|
||||
EXPECT_CALL(*rawBackendPtr, fetchTransaction(ripple::uint256{TXNID}, _)).WillOnce(Return(tx));
|
||||
|
||||
auto const rawETLPtr = dynamic_cast<MockETLService*>(mockETLServicePtr.get());
|
||||
ASSERT_NE(rawETLPtr, nullptr);
|
||||
EXPECT_CALL(*rawETLPtr, getETLState).WillOnce(Return(etl::ETLState{}));
|
||||
|
||||
runSpawn([this](auto yield) {
|
||||
auto const handler = AnyHandler{TestTxHandler{mockBackendPtr, mockETLServicePtr}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"command": "tx",
|
||||
"transaction": "{}"
|
||||
}})",
|
||||
TXNID
|
||||
));
|
||||
auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 1u});
|
||||
ASSERT_TRUE(output);
|
||||
EXPECT_TRUE(output->as_object().contains("DeliverMax"));
|
||||
EXPECT_EQ(output->at("Amount"), output->at("DeliverMax"));
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, PaymentTx_API_v2)
|
||||
{
|
||||
auto const rawBackendPtr = dynamic_cast<MockBackend*>(mockBackendPtr.get());
|
||||
ASSERT_NE(rawBackendPtr, nullptr);
|
||||
|
||||
TransactionAndMetadata tx;
|
||||
tx.transaction = CreatePaymentTransactionObject(ACCOUNT, ACCOUNT2, 2, 3, 300).getSerializer().peekData();
|
||||
tx.metadata = CreatePaymentTransactionMetaObject(ACCOUNT, ACCOUNT2, 110, 30).getSerializer().peekData();
|
||||
tx.date = 123456;
|
||||
tx.ledgerSequence = 100;
|
||||
|
||||
EXPECT_CALL(*rawBackendPtr, fetchTransaction(ripple::uint256{TXNID}, _)).WillOnce(Return(tx));
|
||||
|
||||
auto const rawETLPtr = dynamic_cast<MockETLService*>(mockETLServicePtr.get());
|
||||
ASSERT_NE(rawETLPtr, nullptr);
|
||||
EXPECT_CALL(*rawETLPtr, getETLState).WillOnce(Return(etl::ETLState{}));
|
||||
|
||||
runSpawn([this](auto yield) {
|
||||
auto const handler = AnyHandler{TestTxHandler{mockBackendPtr, mockETLServicePtr}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"command": "tx",
|
||||
"transaction": "{}"
|
||||
}})",
|
||||
TXNID
|
||||
));
|
||||
auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2u});
|
||||
ASSERT_TRUE(output);
|
||||
EXPECT_TRUE(output->as_object().contains("DeliverMax"));
|
||||
EXPECT_FALSE(output->as_object().contains("Amount"));
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, DefaultParameter_API_v2)
|
||||
{
|
||||
auto const rawBackendPtr = dynamic_cast<MockBackend*>(mockBackendPtr.get());
|
||||
|
||||
Reference in New Issue
Block a user