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
23#include <xrpld/app/ledger/LedgerMaster.h>
24
25namespace ripple {
26namespace test {
27
29{
31 makeNetworkConfig(uint32_t networkID)
32 {
33 using namespace jtx;
34 return envconfig([&](std::unique_ptr<Config> cfg) {
35 cfg->NETWORK_ID = networkID;
36 // This test relies on ledger hash so must lock it to fee 10.
37 cfg->FEES.reference_fee = 10;
38 return cfg;
39 });
40 }
41
42 void
44 {
45 testcase("tx_id_from_index");
46
47 using namespace test::jtx;
48 using namespace std::literals;
49
50 test::jtx::Env env{*this, makeNetworkConfig(11111)};
51
52 auto const alice = Account("alice");
53 env.fund(XRP(1000), alice);
54 env.close();
55
56 // build ledgers
59 auto const startLegSeq = env.current()->info().seq;
60 for (int i = 0; i < 2; ++i)
61 {
62 env(noop(alice));
63 txns.emplace_back(env.tx());
64 env.close();
65 metas.emplace_back(
66 env.closed()->txRead(env.tx()->getTransactionID()).second);
67 }
68 // add last (empty) ledger
69 env.close();
70 auto const endLegSeq = env.closed()->info().seq;
71
72 // test invalid range
73 {
74 std::uint32_t ledgerSeq = -1;
75 std::uint32_t txnIndex = 0;
76 auto result =
77 env.app().getLedgerMaster().txnIdFromIndex(ledgerSeq, txnIndex);
78 BEAST_EXPECT(!result);
79 }
80 // test not in ledger
81 {
82 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
83 auto result =
84 env.app().getLedgerMaster().txnIdFromIndex(0, txnIndex);
85 BEAST_EXPECT(!result);
86 }
87 // test empty ledger
88 {
89 auto result =
90 env.app().getLedgerMaster().txnIdFromIndex(endLegSeq, 0);
91 BEAST_EXPECT(!result);
92 }
93 // ended without result
94 {
95 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
96 auto result = env.app().getLedgerMaster().txnIdFromIndex(
97 endLegSeq + 1, txnIndex);
98 BEAST_EXPECT(!result);
99 }
100 // success (first tx)
101 {
102 uint32_t txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
103 auto result = env.app().getLedgerMaster().txnIdFromIndex(
104 startLegSeq, txnIndex);
105 BEAST_EXPECT(
106 *result ==
107 uint256("277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
108 "72679ADC65"));
109 }
110 // success (second tx)
111 {
112 uint32_t txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
113 auto result = env.app().getLedgerMaster().txnIdFromIndex(
114 startLegSeq + 1, txnIndex);
115 BEAST_EXPECT(
116 *result ==
117 uint256("293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
118 "819F538FDE"));
119 }
120 }
121
122public:
123 void
124 run() override
125 {
126 using namespace test::jtx;
129 }
130
131 void
133 {
134 testTxnIdFromIndex(features);
135 }
136};
137
138BEAST_DEFINE_TESTSUITE(LedgerMaster, app, ripple);
139
140} // namespace test
141} // 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:121
T emplace_back(T... args)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:54
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
FeatureBitset supported_amendments()
Definition: Env.h:74
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
base_uint< 256 > uint256
Definition: base_uint.h:558