xrpld
Loading...
Searching...
No Matches
TransactionProposalTests.cpp
1// Auto-generated unit tests for ledger entry TransactionProposal
2
3
4#include <gtest/gtest.h>
5
6#include <protocol_autogen/TestHelpers.h>
7
8#include <xrpl/protocol/STLedgerEntry.h>
9#include <xrpl/protocol_autogen/ledger_entries/TransactionProposal.h>
10#include <xrpl/protocol_autogen/ledger_entries/Ticket.h>
11
12#include <string>
13
14namespace xrpl::ledger_entries {
15
16// 1 & 4) Set fields via builder setters, build, then read them back via
17// wrapper getters. After build(), validate() should succeed for both the
18// builder's STObject and the wrapper's SLE.
19TEST(TransactionProposalTests, BuilderSettersRoundTrip)
20{
21 UInt256 const index{1u};
22
23 auto const previousTxnIDValue = canonical_UINT256();
24 auto const previousTxnLgrSeqValue = canonical_UINT32();
25 auto const ownerValue = canonical_ACCOUNT();
26 auto const proposedTransactionValue = canonical_OBJECT();
27 auto const expirationValue = canonical_UINT32();
28 auto const ownerNodeValue = canonical_UINT64();
29
31 previousTxnIDValue,
32 previousTxnLgrSeqValue,
33 ownerValue,
34 proposedTransactionValue,
35 expirationValue,
36 ownerNodeValue
37 };
38
39
40 builder.setLedgerIndex(index);
41 builder.setFlags(0x1u);
42
43 EXPECT_TRUE(builder.validate());
44
45 auto const entry = builder.build(index);
46
47 EXPECT_TRUE(entry.validate());
48
49 {
50 auto const& expected = previousTxnIDValue;
51 auto const actual = entry.getPreviousTxnID();
52 expectEqualField(expected, actual, "sfPreviousTxnID");
53 }
54
55 {
56 auto const& expected = previousTxnLgrSeqValue;
57 auto const actual = entry.getPreviousTxnLgrSeq();
58 expectEqualField(expected, actual, "sfPreviousTxnLgrSeq");
59 }
60
61 {
62 auto const& expected = ownerValue;
63 auto const actual = entry.getOwner();
64 expectEqualField(expected, actual, "sfOwner");
65 }
66
67 {
68 auto const& expected = proposedTransactionValue;
69 auto const actual = entry.getProposedTransaction();
70 expectEqualField(expected, actual, "sfProposedTransaction");
71 }
72
73 {
74 auto const& expected = expirationValue;
75 auto const actual = entry.getExpiration();
76 expectEqualField(expected, actual, "sfExpiration");
77 }
78
79 {
80 auto const& expected = ownerNodeValue;
81 auto const actual = entry.getOwnerNode();
82 expectEqualField(expected, actual, "sfOwnerNode");
83 }
84
85 EXPECT_TRUE(entry.hasLedgerIndex());
86 auto const ledgerIndex = entry.getLedgerIndex();
87 ASSERT_TRUE(ledgerIndex.has_value());
88 EXPECT_EQ(*ledgerIndex, index);
89 EXPECT_EQ(entry.getKey(), index);
90}
91
92// 2 & 4) Start from an SLE, set fields directly on it, construct a builder
93// from that SLE, build a new wrapper, and verify all fields (and validate()).
94TEST(TransactionProposalTests, BuilderFromSleRoundTrip)
95{
96 UInt256 const index{2u};
97
98 auto const previousTxnIDValue = canonical_UINT256();
99 auto const previousTxnLgrSeqValue = canonical_UINT32();
100 auto const ownerValue = canonical_ACCOUNT();
101 auto const proposedTransactionValue = canonical_OBJECT();
102 auto const expirationValue = canonical_UINT32();
103 auto const ownerNodeValue = canonical_UINT64();
104
106
107 sle->at(sfPreviousTxnID) = previousTxnIDValue;
108 sle->at(sfPreviousTxnLgrSeq) = previousTxnLgrSeqValue;
109 sle->at(sfOwner) = ownerValue;
110 sle->setFieldObject(sfProposedTransaction, proposedTransactionValue);
111 sle->at(sfExpiration) = expirationValue;
112 sle->at(sfOwnerNode) = ownerNodeValue;
113
114 TransactionProposalBuilder builderFromSle{sle};
115 EXPECT_TRUE(builderFromSle.validate());
116
117 auto const entryFromBuilder = builderFromSle.build(index);
118
119 TransactionProposal entryFromSle{sle};
120 EXPECT_TRUE(entryFromBuilder.validate());
121 EXPECT_TRUE(entryFromSle.validate());
122
123 {
124 auto const& expected = previousTxnIDValue;
125
126 auto const fromSle = entryFromSle.getPreviousTxnID();
127 auto const fromBuilder = entryFromBuilder.getPreviousTxnID();
128
129 expectEqualField(expected, fromSle, "sfPreviousTxnID");
130 expectEqualField(expected, fromBuilder, "sfPreviousTxnID");
131 }
132
133 {
134 auto const& expected = previousTxnLgrSeqValue;
135
136 auto const fromSle = entryFromSle.getPreviousTxnLgrSeq();
137 auto const fromBuilder = entryFromBuilder.getPreviousTxnLgrSeq();
138
139 expectEqualField(expected, fromSle, "sfPreviousTxnLgrSeq");
140 expectEqualField(expected, fromBuilder, "sfPreviousTxnLgrSeq");
141 }
142
143 {
144 auto const& expected = ownerValue;
145
146 auto const fromSle = entryFromSle.getOwner();
147 auto const fromBuilder = entryFromBuilder.getOwner();
148
149 expectEqualField(expected, fromSle, "sfOwner");
150 expectEqualField(expected, fromBuilder, "sfOwner");
151 }
152
153 {
154 auto const& expected = proposedTransactionValue;
155
156 auto const fromSle = entryFromSle.getProposedTransaction();
157 auto const fromBuilder = entryFromBuilder.getProposedTransaction();
158
159 expectEqualField(expected, fromSle, "sfProposedTransaction");
160 expectEqualField(expected, fromBuilder, "sfProposedTransaction");
161 }
162
163 {
164 auto const& expected = expirationValue;
165
166 auto const fromSle = entryFromSle.getExpiration();
167 auto const fromBuilder = entryFromBuilder.getExpiration();
168
169 expectEqualField(expected, fromSle, "sfExpiration");
170 expectEqualField(expected, fromBuilder, "sfExpiration");
171 }
172
173 {
174 auto const& expected = ownerNodeValue;
175
176 auto const fromSle = entryFromSle.getOwnerNode();
177 auto const fromBuilder = entryFromBuilder.getOwnerNode();
178
179 expectEqualField(expected, fromSle, "sfOwnerNode");
180 expectEqualField(expected, fromBuilder, "sfOwnerNode");
181 }
182
183 EXPECT_EQ(entryFromSle.getKey(), index);
184 EXPECT_EQ(entryFromBuilder.getKey(), index);
185}
186
187// 3) Verify wrapper throws when constructed from wrong ledger entry type.
188TEST(TransactionProposalTests, WrapperThrowsOnWrongEntryType)
189{
190 UInt256 const index{3u};
191
192 // Build a valid ledger entry of a different type
193 // Ticket requires: Account, OwnerNode, TicketSequence, PreviousTxnID, PreviousTxnLgrSeq
194 // Check requires: Account, Destination, SendMax, Sequence, OwnerNode, DestinationNode, PreviousTxnID, PreviousTxnLgrSeq
195 TicketBuilder wrongBuilder{
201 auto wrongEntry = wrongBuilder.build(index);
202
203 EXPECT_THROW(TransactionProposal{wrongEntry.getSle()}, std::runtime_error);
204}
205
206// 4) Verify builder throws when constructed from wrong ledger entry type.
207TEST(TransactionProposalTests, BuilderThrowsOnWrongEntryType)
208{
209 UInt256 const index{4u};
210
211 // Build a valid ledger entry of a different type
212 TicketBuilder wrongBuilder{
218 auto wrongEntry = wrongBuilder.build(index);
219
220 EXPECT_THROW(TransactionProposalBuilder{wrongEntry.getSle()}, std::runtime_error);
221}
222
223}
UInt256 const & getKey() const
Get the key (index) of this ledger entry.
bool validate() const
Validate the ledger entry.
Derived & setLedgerIndex(UInt256 const &value)
Set the ledger index.
Derived & setFlags(uint32_t value)
Set the flags.
bool validate() const
Validate the ledger entry.
Builder for Ticket ledger entries.
Definition Ticket.h:112
Ticket build(UInt256 const &index)
Build and return the completed Ticket wrapper.
Definition Ticket.h:211
Builder for TransactionProposal ledger entries.
TransactionProposal build(UInt256 const &index)
Build and return the completed TransactionProposal wrapper.
Ledger Entry: TransactionProposal.
STObject getProposedTransaction() const
Get sfProposedTransaction (SoeRequired).
SF_ACCOUNT::type::value_type getOwner() const
Get sfOwner (SoeRequired).
SF_UINT256::type::value_type getPreviousTxnID() const
Get sfPreviousTxnID (SoeRequired).
SF_UINT32::type::value_type getPreviousTxnLgrSeq() const
Get sfPreviousTxnLgrSeq (SoeRequired).
SF_UINT32::type::value_type getExpiration() const
Get sfExpiration (SoeRequired).
SF_UINT64::type::value_type getOwnerNode() const
Get sfOwnerNode (SoeRequired).
static constexpr LedgerEntryType entryType
T make_shared(T... args)
TEST(AccountRootTests, BuilderSettersRoundTrip)
BaseUInt< 256 > UInt256
Definition base_uint.h:580
void expectEqualField(T const &expected, T const &actual, char const *fieldName)