rippled
Loading...
Searching...
No Matches
LedgerMaster_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 XRPLF
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx.h>
21#include <test/jtx/Env.h>
22#include <xrpld/app/ledger/LedgerMaster.h>
23
24namespace ripple {
25namespace test {
26
28{
30 makeNetworkConfig(uint32_t networkID)
31 {
32 using namespace jtx;
33 return envconfig([&](std::unique_ptr<Config> cfg) {
34 cfg->NETWORK_ID = networkID;
35 return cfg;
36 });
37 }
38
39 void
41 {
42 testcase("tx_id_from_index");
43
44 using namespace test::jtx;
45 using namespace std::literals;
46
47 test::jtx::Env env{*this, makeNetworkConfig(11111)};
48
49 auto const alice = Account("alice");
50 env.fund(XRP(1000), alice);
51 env.close();
52
53 // build ledgers
56 auto const startLegSeq = env.current()->info().seq;
57 for (int i = 0; i < 2; ++i)
58 {
59 env(noop(alice));
60 txns.emplace_back(env.tx());
61 env.close();
62 metas.emplace_back(
63 env.closed()->txRead(env.tx()->getTransactionID()).second);
64 }
65 // add last (empty) ledger
66 env.close();
67 auto const endLegSeq = env.closed()->info().seq;
68
69 // test invalid range
70 {
71 std::uint32_t ledgerSeq = -1;
72 std::uint32_t txnIndex = 0;
73 auto result =
74 env.app().getLedgerMaster().txnIdFromIndex(ledgerSeq, txnIndex);
75 BEAST_EXPECT(!result);
76 }
77 // test not in ledger
78 {
79 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
80 auto result =
81 env.app().getLedgerMaster().txnIdFromIndex(0, txnIndex);
82 BEAST_EXPECT(!result);
83 }
84 // test empty ledger
85 {
86 auto result =
87 env.app().getLedgerMaster().txnIdFromIndex(endLegSeq, 0);
88 BEAST_EXPECT(!result);
89 }
90 // ended without result
91 {
92 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
93 auto result = env.app().getLedgerMaster().txnIdFromIndex(
94 endLegSeq + 1, txnIndex);
95 BEAST_EXPECT(!result);
96 }
97 // success (first tx)
98 {
99 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
100 auto result = env.app().getLedgerMaster().txnIdFromIndex(
101 startLegSeq, txnIndex);
102 BEAST_EXPECT(
103 *result ==
104 uint256("277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
105 "72679ADC65"));
106 }
107 // success (second tx)
108 {
109 uint32_t txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
110 auto result = env.app().getLedgerMaster().txnIdFromIndex(
111 startLegSeq + 1, txnIndex);
112 BEAST_EXPECT(
113 *result ==
114 uint256("293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
115 "819F538FDE"));
116 }
117 }
118
119public:
120 void
121 run() override
122 {
123 using namespace test::jtx;
126 }
127
128 void
130 {
131 testTxnIdFromIndex(features);
132 }
133};
134
135BEAST_DEFINE_TESTSUITE(LedgerMaster, app, ripple);
136
137} // namespace test
138} // namespace ripple
A testsuite class.
Definition: suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
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:39
A transaction testing environment.
Definition: Env.h:118
T emplace_back(T... args)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:54
Json::Value noop(Account const &account)
The null transaction.
Definition: noop.h:31
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:104
FeatureBitset supported_amendments()
Definition: Env.h:71
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 256 > uint256
Definition: base_uint.h:558