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 ripple {
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()->info().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(
47 env.closed()->txRead(env.tx()->getTransactionID()).second);
48 }
49 // add last (empty) ledger
50 env.close();
51 auto const endLegSeq = env.closed()->info().seq;
52
53 // test invalid range
54 {
55 std::uint32_t ledgerSeq = -1;
56 std::uint32_t txnIndex = 0;
57 auto result =
58 env.app().getLedgerMaster().txnIdFromIndex(ledgerSeq, txnIndex);
59 BEAST_EXPECT(!result);
60 }
61 // test not in ledger
62 {
63 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
64 auto result =
65 env.app().getLedgerMaster().txnIdFromIndex(0, txnIndex);
66 BEAST_EXPECT(!result);
67 }
68 // test empty ledger
69 {
70 auto result =
71 env.app().getLedgerMaster().txnIdFromIndex(endLegSeq, 0);
72 BEAST_EXPECT(!result);
73 }
74 // ended without result
75 {
76 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
77 auto result = env.app().getLedgerMaster().txnIdFromIndex(
78 endLegSeq + 1, txnIndex);
79 BEAST_EXPECT(!result);
80 }
81 // success (first tx)
82 {
83 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
84 auto result = env.app().getLedgerMaster().txnIdFromIndex(
85 startLegSeq, txnIndex);
86 BEAST_EXPECT(
87 *result ==
88 uint256("277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
89 "72679ADC65"));
90 }
91 // success (second tx)
92 {
93 uint32_t txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
94 auto result = env.app().getLedgerMaster().txnIdFromIndex(
95 startLegSeq + 1, txnIndex);
96 BEAST_EXPECT(
97 *result ==
98 uint256("293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
99 "819F538FDE"));
100 }
101 }
102
103public:
104 void
105 run() override
106 {
107 using namespace test::jtx;
110 }
111
112 void
114 {
115 testTxnIdFromIndex(features);
116 }
117};
118
119BEAST_DEFINE_TESTSUITE(LedgerMaster, app, ripple);
120
121} // namespace test
122} // namespace ripple
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void testTxnIdFromIndex(FeatureBitset features)
std::unique_ptr< Config > makeNetworkConfig(uint32_t networkID)
void testWithFeats(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
T emplace_back(T... args)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:35
FeatureBitset testable_amendments()
Definition Env.h:55
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
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:539