rippled
Loading...
Searching...
No Matches
LedgerMaster_test.cpp
1#include <test/jtx.h>
2#include <test/jtx/Env.h>
3
4#include <xrpld/app/ledger/LedgerMaster.h>
5
6namespace xrpl {
7namespace test {
8
10{
12 makeNetworkConfig(uint32_t networkID)
13 {
14 using namespace jtx;
15 return envconfig([&](std::unique_ptr<Config> cfg) {
16 cfg->NETWORK_ID = networkID;
17 // This test relies on ledger hash so must lock it to fee 10.
18 cfg->FEES.reference_fee = 10;
19 return cfg;
20 });
21 }
22
23 void
25 {
26 testcase("tx_id_from_index");
27
28 using namespace test::jtx;
29 using namespace std::literals;
30
31 test::jtx::Env env{*this, makeNetworkConfig(11111)};
32
33 auto const alice = Account("alice");
34 env.fund(XRP(1000), alice);
35 env.close();
36
37 // build ledgers
40 auto const startLegSeq = env.current()->header().seq;
41 for (int i = 0; i < 2; ++i)
42 {
43 env(noop(alice));
44 txns.emplace_back(env.tx());
45 env.close();
46 metas.emplace_back(env.closed()->txRead(env.tx()->getTransactionID()).second);
47 }
48 // add last (empty) ledger
49 env.close();
50 auto const endLegSeq = env.closed()->header().seq;
51
52 // test invalid range
53 {
54 std::uint32_t ledgerSeq = -1;
55 std::uint32_t txnIndex = 0;
56 auto result = env.app().getLedgerMaster().txnIdFromIndex(ledgerSeq, txnIndex);
57 BEAST_EXPECT(!result);
58 }
59 // test not in ledger
60 {
61 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
62 auto result = env.app().getLedgerMaster().txnIdFromIndex(0, txnIndex);
63 BEAST_EXPECT(!result);
64 }
65 // test empty ledger
66 {
67 auto result = env.app().getLedgerMaster().txnIdFromIndex(endLegSeq, 0);
68 BEAST_EXPECT(!result);
69 }
70 // ended without result
71 {
72 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
73 auto result = env.app().getLedgerMaster().txnIdFromIndex(endLegSeq + 1, txnIndex);
74 BEAST_EXPECT(!result);
75 }
76 // success (first tx)
77 {
78 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
79 auto result = env.app().getLedgerMaster().txnIdFromIndex(startLegSeq, txnIndex);
80 BEAST_EXPECT(
81 *result ==
82 uint256("277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
83 "72679ADC65"));
84 }
85 // success (second tx)
86 {
87 uint32_t txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
88 auto result = env.app().getLedgerMaster().txnIdFromIndex(startLegSeq + 1, txnIndex);
89 BEAST_EXPECT(
90 *result ==
91 uint256("293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
92 "819F538FDE"));
93 }
94 }
95
96public:
97 void
98 run() override
99 {
100 using namespace test::jtx;
103 }
104
105 void
107 {
108 testTxnIdFromIndex(features);
109 }
110};
111
112BEAST_DEFINE_TESTSUITE(LedgerMaster, app, xrpl);
113
114} // namespace test
115} // namespace xrpl
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:148
void testWithFeats(FeatureBitset features)
void testTxnIdFromIndex(FeatureBitset features)
void run() override
Runs the suite.
std::unique_ptr< Config > makeNetworkConfig(uint32_t networkID)
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:98
T emplace_back(T... args)
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:90
FeatureBitset testable_amendments()
Definition Env.h:55
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 256 > uint256
Definition base_uint.h:527