mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-03 00:36:37 +00:00
CTID sync rippled (#114)
* clang-format * add `'` seperator to hex constants fix bad seperator clang-format * remove impossible validation add parenthesis * pre-increment `it` * add leading 0 * use boost_regex * add leading 0 * `const` after declare variable * clang-format * add extra check on std::optional * move guard * add test * update test to match * rename `txnIDfromIndex` -> `txnIdFromIndex` * update test to match guard * fix test naming --------- Co-authored-by: Richard Holland <richard.holland@starstone.co.nz>
This commit is contained in:
@@ -38,7 +38,7 @@ class LedgerMaster_test : public beast::unit_test::suite
|
||||
}
|
||||
|
||||
void
|
||||
testTxnIDfromIndex(FeatureBitset features)
|
||||
testTxnIdFromIndex(FeatureBitset features)
|
||||
{
|
||||
testcase("tx_id_from_index");
|
||||
|
||||
@@ -72,39 +72,49 @@ class LedgerMaster_test : public beast::unit_test::suite
|
||||
std::uint32_t ledgerSeq = -1;
|
||||
std::uint32_t txnIndex = 0;
|
||||
auto result =
|
||||
env.app().getLedgerMaster().txnIDfromIndex(ledgerSeq, txnIndex);
|
||||
env.app().getLedgerMaster().txnIdFromIndex(ledgerSeq, txnIndex);
|
||||
BEAST_EXPECT(!result);
|
||||
}
|
||||
// test not in ledger
|
||||
{
|
||||
uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
|
||||
auto result =
|
||||
env.app().getLedgerMaster().txnIDfromIndex(0, txnIndex);
|
||||
env.app().getLedgerMaster().txnIdFromIndex(0, txnIndex);
|
||||
BEAST_EXPECT(!result);
|
||||
}
|
||||
// test empty ledger
|
||||
{
|
||||
auto result =
|
||||
env.app().getLedgerMaster().txnIDfromIndex(endLegSeq, 0);
|
||||
env.app().getLedgerMaster().txnIdFromIndex(endLegSeq, 0);
|
||||
BEAST_EXPECT(!result);
|
||||
}
|
||||
// ended without result
|
||||
{
|
||||
uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
|
||||
auto result = env.app().getLedgerMaster().txnIDfromIndex(
|
||||
auto result = env.app().getLedgerMaster().txnIdFromIndex(
|
||||
endLegSeq + 1, txnIndex);
|
||||
BEAST_EXPECT(!result);
|
||||
}
|
||||
// success
|
||||
// success (first tx)
|
||||
{
|
||||
uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
|
||||
auto result = env.app().getLedgerMaster().txnIDfromIndex(
|
||||
auto result = env.app().getLedgerMaster().txnIdFromIndex(
|
||||
startLegSeq, txnIndex);
|
||||
BEAST_EXPECT(
|
||||
*result ==
|
||||
uint256("277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
|
||||
"72679ADC65"));
|
||||
}
|
||||
// success (second tx)
|
||||
{
|
||||
uint32_t txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
|
||||
auto result = env.app().getLedgerMaster().txnIdFromIndex(
|
||||
startLegSeq + 1, txnIndex);
|
||||
BEAST_EXPECT(
|
||||
*result ==
|
||||
uint256("293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
|
||||
"819F538FDE"));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -119,7 +129,7 @@ public:
|
||||
void
|
||||
testWithFeats(FeatureBitset features)
|
||||
{
|
||||
testTxnIDfromIndex(features);
|
||||
testTxnIdFromIndex(features);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -133,7 +133,11 @@ public:
|
||||
auto jt = env.jtnofill(jvn, alice);
|
||||
Serializer s;
|
||||
jt.stx->add(s);
|
||||
BEAST_EXPECT(env.rpc("submit", strHex(s.slice()))[jss::result][jss::engine_result] == "telREQUIRES_NETWORK_ID");
|
||||
BEAST_EXPECT(
|
||||
env.rpc(
|
||||
"submit",
|
||||
strHex(s.slice()))[jss::result][jss::engine_result] ==
|
||||
"telREQUIRES_NETWORK_ID");
|
||||
env.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ class Transaction_test : public beast::unit_test::suite
|
||||
auto const tx = env.jt(noop(alice), seq(env.seq(alice))).stx;
|
||||
auto const ctid =
|
||||
*RPC::encodeCTID(endLegSeq, tx->getSeqProxy().value(), netID);
|
||||
for (int deltaEndSeq = 0; deltaEndSeq < 3; ++deltaEndSeq)
|
||||
for (int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
|
||||
{
|
||||
auto const result = env.rpc(
|
||||
COMMAND,
|
||||
@@ -367,7 +367,7 @@ class Transaction_test : public beast::unit_test::suite
|
||||
if (deltaEndSeq)
|
||||
BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
|
||||
else
|
||||
BEAST_EXPECT(result[jss::result][jss::searched_all].asBool());
|
||||
BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
|
||||
}
|
||||
|
||||
// Find transactions outside of provided range.
|
||||
@@ -435,7 +435,7 @@ class Transaction_test : public beast::unit_test::suite
|
||||
result[jss::result][jss::status] == jss::error &&
|
||||
result[jss::result][jss::error] == NOT_FOUND);
|
||||
|
||||
BEAST_EXPECT(result[jss::result][jss::searched_all].asBool());
|
||||
BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
|
||||
}
|
||||
|
||||
// Provide range without providing the `binary`
|
||||
@@ -552,7 +552,7 @@ class Transaction_test : public beast::unit_test::suite
|
||||
// Test case 1: Valid input values
|
||||
auto const expected11 = std::optional<std::string>("CFFFFFFFFFFFFFFF");
|
||||
BEAST_EXPECT(
|
||||
RPC::encodeCTID(0xFFFFFFFUL, 0xFFFFU, 0xFFFFU) == expected11);
|
||||
RPC::encodeCTID(0x0FFF'FFFFUL, 0xFFFFU, 0xFFFFU) == expected11);
|
||||
auto const expected12 = std::optional<std::string>("C000000000000000");
|
||||
BEAST_EXPECT(RPC::encodeCTID(0, 0, 0) == expected12);
|
||||
auto const expected13 = std::optional<std::string>("C000000100020003");
|
||||
@@ -561,21 +561,22 @@ class Transaction_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(RPC::encodeCTID(13249191UL, 12911U, 65535U) == expected14);
|
||||
|
||||
// Test case 2: ledger_seq greater than 0xFFFFFFF
|
||||
BEAST_EXPECT(!RPC::encodeCTID(0x10000000UL, 0xFFFFU, 0xFFFFU));
|
||||
BEAST_EXPECT(!RPC::encodeCTID(0x1000'0000UL, 0xFFFFU, 0xFFFFU));
|
||||
|
||||
// Test case 3: txn_index greater than 0xFFFF
|
||||
// this test case is impossible in c++ due to the type, left in for
|
||||
// completeness
|
||||
auto const expected3 = std::optional<std::string>("CFFFFFFF0000FFFF");
|
||||
BEAST_EXPECT(
|
||||
RPC::encodeCTID(0xFFFFFFF, (uint16_t)0x10000, 0xFFFF) == expected3);
|
||||
RPC::encodeCTID(0x0FFF'FFFF, (uint16_t)0x10000, 0xFFFF) ==
|
||||
expected3);
|
||||
|
||||
// Test case 4: network_id greater than 0xFFFF
|
||||
// this test case is impossible in c++ due to the type, left in for
|
||||
// completeness
|
||||
auto const expected4 = std::optional<std::string>("CFFFFFFFFFFF0000");
|
||||
BEAST_EXPECT(
|
||||
RPC::encodeCTID(0xFFFFFFFUL, 0xFFFFU, (uint16_t)0x10000U) ==
|
||||
RPC::encodeCTID(0x0FFF'FFFFUL, 0xFFFFU, (uint16_t)0x1000'0U) ==
|
||||
expected4);
|
||||
|
||||
// Test case 5: Valid input values
|
||||
@@ -609,24 +610,24 @@ class Transaction_test : public beast::unit_test::suite
|
||||
|
||||
// Test case 11: Valid input values
|
||||
BEAST_EXPECT(
|
||||
(RPC::decodeCTID(0xCFFFFFFFFFFFFFFFULL) ==
|
||||
(RPC::decodeCTID(0xCFFF'FFFF'FFFF'FFFFULL) ==
|
||||
std::optional<std::tuple<int32_t, uint16_t, uint16_t>>(
|
||||
std::make_tuple(0xFFFFFFFUL, 0xFFFFU, 0xFFFFU))));
|
||||
std::make_tuple(0x0FFF'FFFFUL, 0xFFFFU, 0xFFFFU))));
|
||||
BEAST_EXPECT(
|
||||
(RPC::decodeCTID(0xC000000000000000ULL) ==
|
||||
(RPC::decodeCTID(0xC000'0000'0000'0000ULL) ==
|
||||
std::optional<std::tuple<int32_t, uint16_t, uint16_t>>(
|
||||
std::make_tuple(0, 0, 0))));
|
||||
BEAST_EXPECT(
|
||||
(RPC::decodeCTID(0xC000000100020003ULL) ==
|
||||
(RPC::decodeCTID(0xC000'0001'0002'0003ULL) ==
|
||||
std::optional<std::tuple<int32_t, uint16_t, uint16_t>>(
|
||||
std::make_tuple(1U, 2U, 3U))));
|
||||
BEAST_EXPECT(
|
||||
(RPC::decodeCTID(0xC0CA2AA7326FC045ULL) ==
|
||||
(RPC::decodeCTID(0xC0CA'2AA7'326F'C045ULL) ==
|
||||
std::optional<std::tuple<int32_t, uint16_t, uint16_t>>(
|
||||
std::make_tuple(13249191UL, 12911U, 49221U))));
|
||||
std::make_tuple(1324'9191UL, 12911U, 49221U))));
|
||||
|
||||
// Test case 12: ctid not exactly 16 nibbles
|
||||
BEAST_EXPECT(!RPC::decodeCTID(0xC003FFFFFFFFFFF));
|
||||
BEAST_EXPECT(!RPC::decodeCTID(0xC003'FFFF'FFFF'FFF));
|
||||
|
||||
// Test case 13: ctid too large to be a valid CTID value
|
||||
// this test case is not possible in c++ because it would overflow the
|
||||
@@ -634,7 +635,7 @@ class Transaction_test : public beast::unit_test::suite
|
||||
// BEAST_EXPECT(!RPC::decodeCTID(0xCFFFFFFFFFFFFFFFFULL));
|
||||
|
||||
// Test case 14: ctid doesn't start with a C nibble
|
||||
BEAST_EXPECT(!RPC::decodeCTID(0xFFFFFFFFFFFFFFFFULL));
|
||||
BEAST_EXPECT(!RPC::decodeCTID(0xFFFF'FFFF'FFFF'FFFFULL));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user