rippled
Loading...
Searching...
No Matches
LoanTests.cpp
1// Auto-generated unit tests for ledger entry Loan
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/Loan.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(LoanTests, BuilderSettersRoundTrip)
20{
21 uint256 const index{1u};
22
23 auto const previousTxnIDValue = canonical_UINT256();
24 auto const previousTxnLgrSeqValue = canonical_UINT32();
25 auto const ownerNodeValue = canonical_UINT64();
26 auto const loanBrokerNodeValue = canonical_UINT64();
27 auto const loanBrokerIDValue = canonical_UINT256();
28 auto const loanSequenceValue = canonical_UINT32();
29 auto const borrowerValue = canonical_ACCOUNT();
30 auto const loanOriginationFeeValue = canonical_NUMBER();
31 auto const loanServiceFeeValue = canonical_NUMBER();
32 auto const latePaymentFeeValue = canonical_NUMBER();
33 auto const closePaymentFeeValue = canonical_NUMBER();
34 auto const overpaymentFeeValue = canonical_UINT32();
35 auto const interestRateValue = canonical_UINT32();
36 auto const lateInterestRateValue = canonical_UINT32();
37 auto const closeInterestRateValue = canonical_UINT32();
38 auto const overpaymentInterestRateValue = canonical_UINT32();
39 auto const startDateValue = canonical_UINT32();
40 auto const paymentIntervalValue = canonical_UINT32();
41 auto const gracePeriodValue = canonical_UINT32();
42 auto const previousPaymentDueDateValue = canonical_UINT32();
43 auto const nextPaymentDueDateValue = canonical_UINT32();
44 auto const paymentRemainingValue = canonical_UINT32();
45 auto const periodicPaymentValue = canonical_NUMBER();
46 auto const principalOutstandingValue = canonical_NUMBER();
47 auto const totalValueOutstandingValue = canonical_NUMBER();
48 auto const managementFeeOutstandingValue = canonical_NUMBER();
49 auto const loanScaleValue = canonical_INT32();
50
51 LoanBuilder builder{
52 previousTxnIDValue,
53 previousTxnLgrSeqValue,
54 ownerNodeValue,
55 loanBrokerNodeValue,
56 loanBrokerIDValue,
57 loanSequenceValue,
58 borrowerValue,
59 startDateValue,
60 paymentIntervalValue,
61 periodicPaymentValue
62 };
63
64 builder.setLoanOriginationFee(loanOriginationFeeValue);
65 builder.setLoanServiceFee(loanServiceFeeValue);
66 builder.setLatePaymentFee(latePaymentFeeValue);
67 builder.setClosePaymentFee(closePaymentFeeValue);
68 builder.setOverpaymentFee(overpaymentFeeValue);
69 builder.setInterestRate(interestRateValue);
70 builder.setLateInterestRate(lateInterestRateValue);
71 builder.setCloseInterestRate(closeInterestRateValue);
72 builder.setOverpaymentInterestRate(overpaymentInterestRateValue);
73 builder.setGracePeriod(gracePeriodValue);
74 builder.setPreviousPaymentDueDate(previousPaymentDueDateValue);
75 builder.setNextPaymentDueDate(nextPaymentDueDateValue);
76 builder.setPaymentRemaining(paymentRemainingValue);
77 builder.setPrincipalOutstanding(principalOutstandingValue);
78 builder.setTotalValueOutstanding(totalValueOutstandingValue);
79 builder.setManagementFeeOutstanding(managementFeeOutstandingValue);
80 builder.setLoanScale(loanScaleValue);
81
82 builder.setLedgerIndex(index);
83 builder.setFlags(0x1u);
84
85 EXPECT_TRUE(builder.validate());
86
87 auto const entry = builder.build(index);
88
89 EXPECT_TRUE(entry.validate());
90
91 {
92 auto const& expected = previousTxnIDValue;
93 auto const actual = entry.getPreviousTxnID();
94 expectEqualField(expected, actual, "sfPreviousTxnID");
95 }
96
97 {
98 auto const& expected = previousTxnLgrSeqValue;
99 auto const actual = entry.getPreviousTxnLgrSeq();
100 expectEqualField(expected, actual, "sfPreviousTxnLgrSeq");
101 }
102
103 {
104 auto const& expected = ownerNodeValue;
105 auto const actual = entry.getOwnerNode();
106 expectEqualField(expected, actual, "sfOwnerNode");
107 }
108
109 {
110 auto const& expected = loanBrokerNodeValue;
111 auto const actual = entry.getLoanBrokerNode();
112 expectEqualField(expected, actual, "sfLoanBrokerNode");
113 }
114
115 {
116 auto const& expected = loanBrokerIDValue;
117 auto const actual = entry.getLoanBrokerID();
118 expectEqualField(expected, actual, "sfLoanBrokerID");
119 }
120
121 {
122 auto const& expected = loanSequenceValue;
123 auto const actual = entry.getLoanSequence();
124 expectEqualField(expected, actual, "sfLoanSequence");
125 }
126
127 {
128 auto const& expected = borrowerValue;
129 auto const actual = entry.getBorrower();
130 expectEqualField(expected, actual, "sfBorrower");
131 }
132
133 {
134 auto const& expected = startDateValue;
135 auto const actual = entry.getStartDate();
136 expectEqualField(expected, actual, "sfStartDate");
137 }
138
139 {
140 auto const& expected = paymentIntervalValue;
141 auto const actual = entry.getPaymentInterval();
142 expectEqualField(expected, actual, "sfPaymentInterval");
143 }
144
145 {
146 auto const& expected = periodicPaymentValue;
147 auto const actual = entry.getPeriodicPayment();
148 expectEqualField(expected, actual, "sfPeriodicPayment");
149 }
150
151 {
152 auto const& expected = loanOriginationFeeValue;
153 auto const actualOpt = entry.getLoanOriginationFee();
154 ASSERT_TRUE(actualOpt.has_value());
155 expectEqualField(expected, *actualOpt, "sfLoanOriginationFee");
156 EXPECT_TRUE(entry.hasLoanOriginationFee());
157 }
158
159 {
160 auto const& expected = loanServiceFeeValue;
161 auto const actualOpt = entry.getLoanServiceFee();
162 ASSERT_TRUE(actualOpt.has_value());
163 expectEqualField(expected, *actualOpt, "sfLoanServiceFee");
164 EXPECT_TRUE(entry.hasLoanServiceFee());
165 }
166
167 {
168 auto const& expected = latePaymentFeeValue;
169 auto const actualOpt = entry.getLatePaymentFee();
170 ASSERT_TRUE(actualOpt.has_value());
171 expectEqualField(expected, *actualOpt, "sfLatePaymentFee");
172 EXPECT_TRUE(entry.hasLatePaymentFee());
173 }
174
175 {
176 auto const& expected = closePaymentFeeValue;
177 auto const actualOpt = entry.getClosePaymentFee();
178 ASSERT_TRUE(actualOpt.has_value());
179 expectEqualField(expected, *actualOpt, "sfClosePaymentFee");
180 EXPECT_TRUE(entry.hasClosePaymentFee());
181 }
182
183 {
184 auto const& expected = overpaymentFeeValue;
185 auto const actualOpt = entry.getOverpaymentFee();
186 ASSERT_TRUE(actualOpt.has_value());
187 expectEqualField(expected, *actualOpt, "sfOverpaymentFee");
188 EXPECT_TRUE(entry.hasOverpaymentFee());
189 }
190
191 {
192 auto const& expected = interestRateValue;
193 auto const actualOpt = entry.getInterestRate();
194 ASSERT_TRUE(actualOpt.has_value());
195 expectEqualField(expected, *actualOpt, "sfInterestRate");
196 EXPECT_TRUE(entry.hasInterestRate());
197 }
198
199 {
200 auto const& expected = lateInterestRateValue;
201 auto const actualOpt = entry.getLateInterestRate();
202 ASSERT_TRUE(actualOpt.has_value());
203 expectEqualField(expected, *actualOpt, "sfLateInterestRate");
204 EXPECT_TRUE(entry.hasLateInterestRate());
205 }
206
207 {
208 auto const& expected = closeInterestRateValue;
209 auto const actualOpt = entry.getCloseInterestRate();
210 ASSERT_TRUE(actualOpt.has_value());
211 expectEqualField(expected, *actualOpt, "sfCloseInterestRate");
212 EXPECT_TRUE(entry.hasCloseInterestRate());
213 }
214
215 {
216 auto const& expected = overpaymentInterestRateValue;
217 auto const actualOpt = entry.getOverpaymentInterestRate();
218 ASSERT_TRUE(actualOpt.has_value());
219 expectEqualField(expected, *actualOpt, "sfOverpaymentInterestRate");
220 EXPECT_TRUE(entry.hasOverpaymentInterestRate());
221 }
222
223 {
224 auto const& expected = gracePeriodValue;
225 auto const actualOpt = entry.getGracePeriod();
226 ASSERT_TRUE(actualOpt.has_value());
227 expectEqualField(expected, *actualOpt, "sfGracePeriod");
228 EXPECT_TRUE(entry.hasGracePeriod());
229 }
230
231 {
232 auto const& expected = previousPaymentDueDateValue;
233 auto const actualOpt = entry.getPreviousPaymentDueDate();
234 ASSERT_TRUE(actualOpt.has_value());
235 expectEqualField(expected, *actualOpt, "sfPreviousPaymentDueDate");
236 EXPECT_TRUE(entry.hasPreviousPaymentDueDate());
237 }
238
239 {
240 auto const& expected = nextPaymentDueDateValue;
241 auto const actualOpt = entry.getNextPaymentDueDate();
242 ASSERT_TRUE(actualOpt.has_value());
243 expectEqualField(expected, *actualOpt, "sfNextPaymentDueDate");
244 EXPECT_TRUE(entry.hasNextPaymentDueDate());
245 }
246
247 {
248 auto const& expected = paymentRemainingValue;
249 auto const actualOpt = entry.getPaymentRemaining();
250 ASSERT_TRUE(actualOpt.has_value());
251 expectEqualField(expected, *actualOpt, "sfPaymentRemaining");
252 EXPECT_TRUE(entry.hasPaymentRemaining());
253 }
254
255 {
256 auto const& expected = principalOutstandingValue;
257 auto const actualOpt = entry.getPrincipalOutstanding();
258 ASSERT_TRUE(actualOpt.has_value());
259 expectEqualField(expected, *actualOpt, "sfPrincipalOutstanding");
260 EXPECT_TRUE(entry.hasPrincipalOutstanding());
261 }
262
263 {
264 auto const& expected = totalValueOutstandingValue;
265 auto const actualOpt = entry.getTotalValueOutstanding();
266 ASSERT_TRUE(actualOpt.has_value());
267 expectEqualField(expected, *actualOpt, "sfTotalValueOutstanding");
268 EXPECT_TRUE(entry.hasTotalValueOutstanding());
269 }
270
271 {
272 auto const& expected = managementFeeOutstandingValue;
273 auto const actualOpt = entry.getManagementFeeOutstanding();
274 ASSERT_TRUE(actualOpt.has_value());
275 expectEqualField(expected, *actualOpt, "sfManagementFeeOutstanding");
276 EXPECT_TRUE(entry.hasManagementFeeOutstanding());
277 }
278
279 {
280 auto const& expected = loanScaleValue;
281 auto const actualOpt = entry.getLoanScale();
282 ASSERT_TRUE(actualOpt.has_value());
283 expectEqualField(expected, *actualOpt, "sfLoanScale");
284 EXPECT_TRUE(entry.hasLoanScale());
285 }
286
287 EXPECT_TRUE(entry.hasLedgerIndex());
288 auto const ledgerIndex = entry.getLedgerIndex();
289 ASSERT_TRUE(ledgerIndex.has_value());
290 EXPECT_EQ(*ledgerIndex, index);
291 EXPECT_EQ(entry.getKey(), index);
292}
293
294// 2 & 4) Start from an SLE, set fields directly on it, construct a builder
295// from that SLE, build a new wrapper, and verify all fields (and validate()).
296TEST(LoanTests, BuilderFromSleRoundTrip)
297{
298 uint256 const index{2u};
299
300 auto const previousTxnIDValue = canonical_UINT256();
301 auto const previousTxnLgrSeqValue = canonical_UINT32();
302 auto const ownerNodeValue = canonical_UINT64();
303 auto const loanBrokerNodeValue = canonical_UINT64();
304 auto const loanBrokerIDValue = canonical_UINT256();
305 auto const loanSequenceValue = canonical_UINT32();
306 auto const borrowerValue = canonical_ACCOUNT();
307 auto const loanOriginationFeeValue = canonical_NUMBER();
308 auto const loanServiceFeeValue = canonical_NUMBER();
309 auto const latePaymentFeeValue = canonical_NUMBER();
310 auto const closePaymentFeeValue = canonical_NUMBER();
311 auto const overpaymentFeeValue = canonical_UINT32();
312 auto const interestRateValue = canonical_UINT32();
313 auto const lateInterestRateValue = canonical_UINT32();
314 auto const closeInterestRateValue = canonical_UINT32();
315 auto const overpaymentInterestRateValue = canonical_UINT32();
316 auto const startDateValue = canonical_UINT32();
317 auto const paymentIntervalValue = canonical_UINT32();
318 auto const gracePeriodValue = canonical_UINT32();
319 auto const previousPaymentDueDateValue = canonical_UINT32();
320 auto const nextPaymentDueDateValue = canonical_UINT32();
321 auto const paymentRemainingValue = canonical_UINT32();
322 auto const periodicPaymentValue = canonical_NUMBER();
323 auto const principalOutstandingValue = canonical_NUMBER();
324 auto const totalValueOutstandingValue = canonical_NUMBER();
325 auto const managementFeeOutstandingValue = canonical_NUMBER();
326 auto const loanScaleValue = canonical_INT32();
327
328 auto sle = std::make_shared<SLE>(Loan::entryType, index);
329
330 sle->at(sfPreviousTxnID) = previousTxnIDValue;
331 sle->at(sfPreviousTxnLgrSeq) = previousTxnLgrSeqValue;
332 sle->at(sfOwnerNode) = ownerNodeValue;
333 sle->at(sfLoanBrokerNode) = loanBrokerNodeValue;
334 sle->at(sfLoanBrokerID) = loanBrokerIDValue;
335 sle->at(sfLoanSequence) = loanSequenceValue;
336 sle->at(sfBorrower) = borrowerValue;
337 sle->at(sfLoanOriginationFee) = loanOriginationFeeValue;
338 sle->at(sfLoanServiceFee) = loanServiceFeeValue;
339 sle->at(sfLatePaymentFee) = latePaymentFeeValue;
340 sle->at(sfClosePaymentFee) = closePaymentFeeValue;
341 sle->at(sfOverpaymentFee) = overpaymentFeeValue;
342 sle->at(sfInterestRate) = interestRateValue;
343 sle->at(sfLateInterestRate) = lateInterestRateValue;
344 sle->at(sfCloseInterestRate) = closeInterestRateValue;
345 sle->at(sfOverpaymentInterestRate) = overpaymentInterestRateValue;
346 sle->at(sfStartDate) = startDateValue;
347 sle->at(sfPaymentInterval) = paymentIntervalValue;
348 sle->at(sfGracePeriod) = gracePeriodValue;
349 sle->at(sfPreviousPaymentDueDate) = previousPaymentDueDateValue;
350 sle->at(sfNextPaymentDueDate) = nextPaymentDueDateValue;
351 sle->at(sfPaymentRemaining) = paymentRemainingValue;
352 sle->at(sfPeriodicPayment) = periodicPaymentValue;
353 sle->at(sfPrincipalOutstanding) = principalOutstandingValue;
354 sle->at(sfTotalValueOutstanding) = totalValueOutstandingValue;
355 sle->at(sfManagementFeeOutstanding) = managementFeeOutstandingValue;
356 sle->at(sfLoanScale) = loanScaleValue;
357
358 LoanBuilder builderFromSle{sle};
359 EXPECT_TRUE(builderFromSle.validate());
360
361 auto const entryFromBuilder = builderFromSle.build(index);
362
363 Loan entryFromSle{sle};
364 EXPECT_TRUE(entryFromBuilder.validate());
365 EXPECT_TRUE(entryFromSle.validate());
366
367 {
368 auto const& expected = previousTxnIDValue;
369
370 auto const fromSle = entryFromSle.getPreviousTxnID();
371 auto const fromBuilder = entryFromBuilder.getPreviousTxnID();
372
373 expectEqualField(expected, fromSle, "sfPreviousTxnID");
374 expectEqualField(expected, fromBuilder, "sfPreviousTxnID");
375 }
376
377 {
378 auto const& expected = previousTxnLgrSeqValue;
379
380 auto const fromSle = entryFromSle.getPreviousTxnLgrSeq();
381 auto const fromBuilder = entryFromBuilder.getPreviousTxnLgrSeq();
382
383 expectEqualField(expected, fromSle, "sfPreviousTxnLgrSeq");
384 expectEqualField(expected, fromBuilder, "sfPreviousTxnLgrSeq");
385 }
386
387 {
388 auto const& expected = ownerNodeValue;
389
390 auto const fromSle = entryFromSle.getOwnerNode();
391 auto const fromBuilder = entryFromBuilder.getOwnerNode();
392
393 expectEqualField(expected, fromSle, "sfOwnerNode");
394 expectEqualField(expected, fromBuilder, "sfOwnerNode");
395 }
396
397 {
398 auto const& expected = loanBrokerNodeValue;
399
400 auto const fromSle = entryFromSle.getLoanBrokerNode();
401 auto const fromBuilder = entryFromBuilder.getLoanBrokerNode();
402
403 expectEqualField(expected, fromSle, "sfLoanBrokerNode");
404 expectEqualField(expected, fromBuilder, "sfLoanBrokerNode");
405 }
406
407 {
408 auto const& expected = loanBrokerIDValue;
409
410 auto const fromSle = entryFromSle.getLoanBrokerID();
411 auto const fromBuilder = entryFromBuilder.getLoanBrokerID();
412
413 expectEqualField(expected, fromSle, "sfLoanBrokerID");
414 expectEqualField(expected, fromBuilder, "sfLoanBrokerID");
415 }
416
417 {
418 auto const& expected = loanSequenceValue;
419
420 auto const fromSle = entryFromSle.getLoanSequence();
421 auto const fromBuilder = entryFromBuilder.getLoanSequence();
422
423 expectEqualField(expected, fromSle, "sfLoanSequence");
424 expectEqualField(expected, fromBuilder, "sfLoanSequence");
425 }
426
427 {
428 auto const& expected = borrowerValue;
429
430 auto const fromSle = entryFromSle.getBorrower();
431 auto const fromBuilder = entryFromBuilder.getBorrower();
432
433 expectEqualField(expected, fromSle, "sfBorrower");
434 expectEqualField(expected, fromBuilder, "sfBorrower");
435 }
436
437 {
438 auto const& expected = startDateValue;
439
440 auto const fromSle = entryFromSle.getStartDate();
441 auto const fromBuilder = entryFromBuilder.getStartDate();
442
443 expectEqualField(expected, fromSle, "sfStartDate");
444 expectEqualField(expected, fromBuilder, "sfStartDate");
445 }
446
447 {
448 auto const& expected = paymentIntervalValue;
449
450 auto const fromSle = entryFromSle.getPaymentInterval();
451 auto const fromBuilder = entryFromBuilder.getPaymentInterval();
452
453 expectEqualField(expected, fromSle, "sfPaymentInterval");
454 expectEqualField(expected, fromBuilder, "sfPaymentInterval");
455 }
456
457 {
458 auto const& expected = periodicPaymentValue;
459
460 auto const fromSle = entryFromSle.getPeriodicPayment();
461 auto const fromBuilder = entryFromBuilder.getPeriodicPayment();
462
463 expectEqualField(expected, fromSle, "sfPeriodicPayment");
464 expectEqualField(expected, fromBuilder, "sfPeriodicPayment");
465 }
466
467 {
468 auto const& expected = loanOriginationFeeValue;
469
470 auto const fromSleOpt = entryFromSle.getLoanOriginationFee();
471 auto const fromBuilderOpt = entryFromBuilder.getLoanOriginationFee();
472
473 ASSERT_TRUE(fromSleOpt.has_value());
474 ASSERT_TRUE(fromBuilderOpt.has_value());
475
476 expectEqualField(expected, *fromSleOpt, "sfLoanOriginationFee");
477 expectEqualField(expected, *fromBuilderOpt, "sfLoanOriginationFee");
478 }
479
480 {
481 auto const& expected = loanServiceFeeValue;
482
483 auto const fromSleOpt = entryFromSle.getLoanServiceFee();
484 auto const fromBuilderOpt = entryFromBuilder.getLoanServiceFee();
485
486 ASSERT_TRUE(fromSleOpt.has_value());
487 ASSERT_TRUE(fromBuilderOpt.has_value());
488
489 expectEqualField(expected, *fromSleOpt, "sfLoanServiceFee");
490 expectEqualField(expected, *fromBuilderOpt, "sfLoanServiceFee");
491 }
492
493 {
494 auto const& expected = latePaymentFeeValue;
495
496 auto const fromSleOpt = entryFromSle.getLatePaymentFee();
497 auto const fromBuilderOpt = entryFromBuilder.getLatePaymentFee();
498
499 ASSERT_TRUE(fromSleOpt.has_value());
500 ASSERT_TRUE(fromBuilderOpt.has_value());
501
502 expectEqualField(expected, *fromSleOpt, "sfLatePaymentFee");
503 expectEqualField(expected, *fromBuilderOpt, "sfLatePaymentFee");
504 }
505
506 {
507 auto const& expected = closePaymentFeeValue;
508
509 auto const fromSleOpt = entryFromSle.getClosePaymentFee();
510 auto const fromBuilderOpt = entryFromBuilder.getClosePaymentFee();
511
512 ASSERT_TRUE(fromSleOpt.has_value());
513 ASSERT_TRUE(fromBuilderOpt.has_value());
514
515 expectEqualField(expected, *fromSleOpt, "sfClosePaymentFee");
516 expectEqualField(expected, *fromBuilderOpt, "sfClosePaymentFee");
517 }
518
519 {
520 auto const& expected = overpaymentFeeValue;
521
522 auto const fromSleOpt = entryFromSle.getOverpaymentFee();
523 auto const fromBuilderOpt = entryFromBuilder.getOverpaymentFee();
524
525 ASSERT_TRUE(fromSleOpt.has_value());
526 ASSERT_TRUE(fromBuilderOpt.has_value());
527
528 expectEqualField(expected, *fromSleOpt, "sfOverpaymentFee");
529 expectEqualField(expected, *fromBuilderOpt, "sfOverpaymentFee");
530 }
531
532 {
533 auto const& expected = interestRateValue;
534
535 auto const fromSleOpt = entryFromSle.getInterestRate();
536 auto const fromBuilderOpt = entryFromBuilder.getInterestRate();
537
538 ASSERT_TRUE(fromSleOpt.has_value());
539 ASSERT_TRUE(fromBuilderOpt.has_value());
540
541 expectEqualField(expected, *fromSleOpt, "sfInterestRate");
542 expectEqualField(expected, *fromBuilderOpt, "sfInterestRate");
543 }
544
545 {
546 auto const& expected = lateInterestRateValue;
547
548 auto const fromSleOpt = entryFromSle.getLateInterestRate();
549 auto const fromBuilderOpt = entryFromBuilder.getLateInterestRate();
550
551 ASSERT_TRUE(fromSleOpt.has_value());
552 ASSERT_TRUE(fromBuilderOpt.has_value());
553
554 expectEqualField(expected, *fromSleOpt, "sfLateInterestRate");
555 expectEqualField(expected, *fromBuilderOpt, "sfLateInterestRate");
556 }
557
558 {
559 auto const& expected = closeInterestRateValue;
560
561 auto const fromSleOpt = entryFromSle.getCloseInterestRate();
562 auto const fromBuilderOpt = entryFromBuilder.getCloseInterestRate();
563
564 ASSERT_TRUE(fromSleOpt.has_value());
565 ASSERT_TRUE(fromBuilderOpt.has_value());
566
567 expectEqualField(expected, *fromSleOpt, "sfCloseInterestRate");
568 expectEqualField(expected, *fromBuilderOpt, "sfCloseInterestRate");
569 }
570
571 {
572 auto const& expected = overpaymentInterestRateValue;
573
574 auto const fromSleOpt = entryFromSle.getOverpaymentInterestRate();
575 auto const fromBuilderOpt = entryFromBuilder.getOverpaymentInterestRate();
576
577 ASSERT_TRUE(fromSleOpt.has_value());
578 ASSERT_TRUE(fromBuilderOpt.has_value());
579
580 expectEqualField(expected, *fromSleOpt, "sfOverpaymentInterestRate");
581 expectEqualField(expected, *fromBuilderOpt, "sfOverpaymentInterestRate");
582 }
583
584 {
585 auto const& expected = gracePeriodValue;
586
587 auto const fromSleOpt = entryFromSle.getGracePeriod();
588 auto const fromBuilderOpt = entryFromBuilder.getGracePeriod();
589
590 ASSERT_TRUE(fromSleOpt.has_value());
591 ASSERT_TRUE(fromBuilderOpt.has_value());
592
593 expectEqualField(expected, *fromSleOpt, "sfGracePeriod");
594 expectEqualField(expected, *fromBuilderOpt, "sfGracePeriod");
595 }
596
597 {
598 auto const& expected = previousPaymentDueDateValue;
599
600 auto const fromSleOpt = entryFromSle.getPreviousPaymentDueDate();
601 auto const fromBuilderOpt = entryFromBuilder.getPreviousPaymentDueDate();
602
603 ASSERT_TRUE(fromSleOpt.has_value());
604 ASSERT_TRUE(fromBuilderOpt.has_value());
605
606 expectEqualField(expected, *fromSleOpt, "sfPreviousPaymentDueDate");
607 expectEqualField(expected, *fromBuilderOpt, "sfPreviousPaymentDueDate");
608 }
609
610 {
611 auto const& expected = nextPaymentDueDateValue;
612
613 auto const fromSleOpt = entryFromSle.getNextPaymentDueDate();
614 auto const fromBuilderOpt = entryFromBuilder.getNextPaymentDueDate();
615
616 ASSERT_TRUE(fromSleOpt.has_value());
617 ASSERT_TRUE(fromBuilderOpt.has_value());
618
619 expectEqualField(expected, *fromSleOpt, "sfNextPaymentDueDate");
620 expectEqualField(expected, *fromBuilderOpt, "sfNextPaymentDueDate");
621 }
622
623 {
624 auto const& expected = paymentRemainingValue;
625
626 auto const fromSleOpt = entryFromSle.getPaymentRemaining();
627 auto const fromBuilderOpt = entryFromBuilder.getPaymentRemaining();
628
629 ASSERT_TRUE(fromSleOpt.has_value());
630 ASSERT_TRUE(fromBuilderOpt.has_value());
631
632 expectEqualField(expected, *fromSleOpt, "sfPaymentRemaining");
633 expectEqualField(expected, *fromBuilderOpt, "sfPaymentRemaining");
634 }
635
636 {
637 auto const& expected = principalOutstandingValue;
638
639 auto const fromSleOpt = entryFromSle.getPrincipalOutstanding();
640 auto const fromBuilderOpt = entryFromBuilder.getPrincipalOutstanding();
641
642 ASSERT_TRUE(fromSleOpt.has_value());
643 ASSERT_TRUE(fromBuilderOpt.has_value());
644
645 expectEqualField(expected, *fromSleOpt, "sfPrincipalOutstanding");
646 expectEqualField(expected, *fromBuilderOpt, "sfPrincipalOutstanding");
647 }
648
649 {
650 auto const& expected = totalValueOutstandingValue;
651
652 auto const fromSleOpt = entryFromSle.getTotalValueOutstanding();
653 auto const fromBuilderOpt = entryFromBuilder.getTotalValueOutstanding();
654
655 ASSERT_TRUE(fromSleOpt.has_value());
656 ASSERT_TRUE(fromBuilderOpt.has_value());
657
658 expectEqualField(expected, *fromSleOpt, "sfTotalValueOutstanding");
659 expectEqualField(expected, *fromBuilderOpt, "sfTotalValueOutstanding");
660 }
661
662 {
663 auto const& expected = managementFeeOutstandingValue;
664
665 auto const fromSleOpt = entryFromSle.getManagementFeeOutstanding();
666 auto const fromBuilderOpt = entryFromBuilder.getManagementFeeOutstanding();
667
668 ASSERT_TRUE(fromSleOpt.has_value());
669 ASSERT_TRUE(fromBuilderOpt.has_value());
670
671 expectEqualField(expected, *fromSleOpt, "sfManagementFeeOutstanding");
672 expectEqualField(expected, *fromBuilderOpt, "sfManagementFeeOutstanding");
673 }
674
675 {
676 auto const& expected = loanScaleValue;
677
678 auto const fromSleOpt = entryFromSle.getLoanScale();
679 auto const fromBuilderOpt = entryFromBuilder.getLoanScale();
680
681 ASSERT_TRUE(fromSleOpt.has_value());
682 ASSERT_TRUE(fromBuilderOpt.has_value());
683
684 expectEqualField(expected, *fromSleOpt, "sfLoanScale");
685 expectEqualField(expected, *fromBuilderOpt, "sfLoanScale");
686 }
687
688 EXPECT_EQ(entryFromSle.getKey(), index);
689 EXPECT_EQ(entryFromBuilder.getKey(), index);
690}
691
692// 3) Verify wrapper throws when constructed from wrong ledger entry type.
693TEST(LoanTests, WrapperThrowsOnWrongEntryType)
694{
695 uint256 const index{3u};
696
697 // Build a valid ledger entry of a different type
698 // Ticket requires: Account, OwnerNode, TicketSequence, PreviousTxnID, PreviousTxnLgrSeq
699 // Check requires: Account, Destination, SendMax, Sequence, OwnerNode, DestinationNode, PreviousTxnID, PreviousTxnLgrSeq
700 TicketBuilder wrongBuilder{
706 auto wrongEntry = wrongBuilder.build(index);
707
708 EXPECT_THROW(Loan{wrongEntry.getSle()}, std::runtime_error);
709}
710
711// 4) Verify builder throws when constructed from wrong ledger entry type.
712TEST(LoanTests, BuilderThrowsOnWrongEntryType)
713{
714 uint256 const index{4u};
715
716 // Build a valid ledger entry of a different type
717 TicketBuilder wrongBuilder{
723 auto wrongEntry = wrongBuilder.build(index);
724
725 EXPECT_THROW(LoanBuilder{wrongEntry.getSle()}, std::runtime_error);
726}
727
728// 5) Build with only required fields and verify optional fields return nullopt.
729TEST(LoanTests, OptionalFieldsReturnNullopt)
730{
731 uint256 const index{3u};
732
733 auto const previousTxnIDValue = canonical_UINT256();
734 auto const previousTxnLgrSeqValue = canonical_UINT32();
735 auto const ownerNodeValue = canonical_UINT64();
736 auto const loanBrokerNodeValue = canonical_UINT64();
737 auto const loanBrokerIDValue = canonical_UINT256();
738 auto const loanSequenceValue = canonical_UINT32();
739 auto const borrowerValue = canonical_ACCOUNT();
740 auto const startDateValue = canonical_UINT32();
741 auto const paymentIntervalValue = canonical_UINT32();
742 auto const periodicPaymentValue = canonical_NUMBER();
743
744 LoanBuilder builder{
745 previousTxnIDValue,
746 previousTxnLgrSeqValue,
747 ownerNodeValue,
748 loanBrokerNodeValue,
749 loanBrokerIDValue,
750 loanSequenceValue,
751 borrowerValue,
752 startDateValue,
753 paymentIntervalValue,
754 periodicPaymentValue
755 };
756
757 auto const entry = builder.build(index);
758
759 // Verify optional fields are not present
760 EXPECT_FALSE(entry.hasLoanOriginationFee());
761 EXPECT_FALSE(entry.getLoanOriginationFee().has_value());
762 EXPECT_FALSE(entry.hasLoanServiceFee());
763 EXPECT_FALSE(entry.getLoanServiceFee().has_value());
764 EXPECT_FALSE(entry.hasLatePaymentFee());
765 EXPECT_FALSE(entry.getLatePaymentFee().has_value());
766 EXPECT_FALSE(entry.hasClosePaymentFee());
767 EXPECT_FALSE(entry.getClosePaymentFee().has_value());
768 EXPECT_FALSE(entry.hasOverpaymentFee());
769 EXPECT_FALSE(entry.getOverpaymentFee().has_value());
770 EXPECT_FALSE(entry.hasInterestRate());
771 EXPECT_FALSE(entry.getInterestRate().has_value());
772 EXPECT_FALSE(entry.hasLateInterestRate());
773 EXPECT_FALSE(entry.getLateInterestRate().has_value());
774 EXPECT_FALSE(entry.hasCloseInterestRate());
775 EXPECT_FALSE(entry.getCloseInterestRate().has_value());
776 EXPECT_FALSE(entry.hasOverpaymentInterestRate());
777 EXPECT_FALSE(entry.getOverpaymentInterestRate().has_value());
778 EXPECT_FALSE(entry.hasGracePeriod());
779 EXPECT_FALSE(entry.getGracePeriod().has_value());
780 EXPECT_FALSE(entry.hasPreviousPaymentDueDate());
781 EXPECT_FALSE(entry.getPreviousPaymentDueDate().has_value());
782 EXPECT_FALSE(entry.hasNextPaymentDueDate());
783 EXPECT_FALSE(entry.getNextPaymentDueDate().has_value());
784 EXPECT_FALSE(entry.hasPaymentRemaining());
785 EXPECT_FALSE(entry.getPaymentRemaining().has_value());
786 EXPECT_FALSE(entry.hasPrincipalOutstanding());
787 EXPECT_FALSE(entry.getPrincipalOutstanding().has_value());
788 EXPECT_FALSE(entry.hasTotalValueOutstanding());
789 EXPECT_FALSE(entry.getTotalValueOutstanding().has_value());
790 EXPECT_FALSE(entry.hasManagementFeeOutstanding());
791 EXPECT_FALSE(entry.getManagementFeeOutstanding().has_value());
792 EXPECT_FALSE(entry.hasLoanScale());
793 EXPECT_FALSE(entry.getLoanScale().has_value());
794}
795}
std::shared_ptr< SLE const > getSle() const
Get the underlying SLE object.
Derived & setLedgerIndex(uint256 const &value)
Set the ledger index.
Derived & setFlags(uint32_t value)
Set the flags.
Builder for Loan ledger entries.
Definition Loan.h:575
LoanBuilder & setCloseInterestRate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfCloseInterestRate (soeDEFAULT)
Definition Loan.h:780
LoanBuilder & setGracePeriod(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfGracePeriod (soeDEFAULT)
Definition Loan.h:824
LoanBuilder & setLoanServiceFee(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfLoanServiceFee (soeDEFAULT)
Definition Loan.h:714
LoanBuilder & setClosePaymentFee(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfClosePaymentFee (soeDEFAULT)
Definition Loan.h:736
LoanBuilder & setLoanOriginationFee(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfLoanOriginationFee (soeDEFAULT)
Definition Loan.h:703
LoanBuilder & setLoanScale(std::decay_t< typename SF_INT32::type::value_type > const &value)
Set sfLoanScale (soeDEFAULT)
Definition Loan.h:912
LoanBuilder & setOverpaymentInterestRate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfOverpaymentInterestRate (soeDEFAULT)
Definition Loan.h:791
LoanBuilder & setInterestRate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfInterestRate (soeDEFAULT)
Definition Loan.h:758
LoanBuilder & setOverpaymentFee(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfOverpaymentFee (soeDEFAULT)
Definition Loan.h:747
LoanBuilder & setPrincipalOutstanding(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfPrincipalOutstanding (soeDEFAULT)
Definition Loan.h:879
LoanBuilder & setTotalValueOutstanding(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfTotalValueOutstanding (soeDEFAULT)
Definition Loan.h:890
LoanBuilder & setLatePaymentFee(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfLatePaymentFee (soeDEFAULT)
Definition Loan.h:725
LoanBuilder & setPreviousPaymentDueDate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfPreviousPaymentDueDate (soeDEFAULT)
Definition Loan.h:835
LoanBuilder & setManagementFeeOutstanding(std::decay_t< typename SF_NUMBER::type::value_type > const &value)
Set sfManagementFeeOutstanding (soeDEFAULT)
Definition Loan.h:901
LoanBuilder & setNextPaymentDueDate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfNextPaymentDueDate (soeDEFAULT)
Definition Loan.h:846
LoanBuilder & setPaymentRemaining(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfPaymentRemaining (soeDEFAULT)
Definition Loan.h:857
LoanBuilder & setLateInterestRate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfLateInterestRate (soeDEFAULT)
Definition Loan.h:769
Ledger Entry: Loan.
Definition Loan.h:28
static constexpr LedgerEntryType entryType
Definition Loan.h:30
Builder for Ticket ledger entries.
Definition Ticket.h:112
T is_same_v
TEST(AccountRootTests, BuilderSettersRoundTrip)
void expectEqualField(T const &expected, T const &actual, char const *fieldName)