rippled
Loading...
Searching...
No Matches
LoanBrokerCoverDepositTests.cpp
1// Auto-generated unit tests for transaction LoanBrokerCoverDeposit
2
3
4#include <gtest/gtest.h>
5
6#include <protocol_autogen/TestHelpers.h>
7
8#include <xrpl/protocol/SecretKey.h>
9#include <xrpl/protocol/Seed.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol_autogen/transactions/LoanBrokerCoverDeposit.h>
12#include <xrpl/protocol_autogen/transactions/AccountSet.h>
13
14#include <string>
15
16namespace xrpl::transactions {
17
18// 1 & 4) Set fields via builder setters, build, then read them back via
19// wrapper getters. After build(), validate() should succeed.
20TEST(TransactionsLoanBrokerCoverDepositTests, BuilderSettersRoundTrip)
21{
22 // Generate a deterministic keypair for signing
23 auto const [publicKey, secretKey] =
24 generateKeyPair(KeyType::secp256k1, generateSeed("testLoanBrokerCoverDeposit"));
25
26 // Common transaction fields
27 auto const accountValue = calcAccountID(publicKey);
28 std::uint32_t const sequenceValue = 1;
29 auto const feeValue = canonical_AMOUNT();
30
31 // Transaction-specific field values
32 auto const loanBrokerIDValue = canonical_UINT256();
33 auto const amountValue = canonical_AMOUNT();
34
36 accountValue,
37 loanBrokerIDValue,
38 amountValue,
39 sequenceValue,
40 feeValue
41 };
42
43 // Set optional fields
44
45 auto tx = builder.build(publicKey, secretKey);
46
47 std::string reason;
48 EXPECT_TRUE(tx.validate(reason)) << reason;
49
50 // Verify signing was applied
51 EXPECT_FALSE(tx.getSigningPubKey().empty());
52 EXPECT_TRUE(tx.hasTxnSignature());
53
54 // Verify common fields
55 EXPECT_EQ(tx.getAccount(), accountValue);
56 EXPECT_EQ(tx.getSequence(), sequenceValue);
57 EXPECT_EQ(tx.getFee(), feeValue);
58
59 // Verify required fields
60 {
61 auto const& expected = loanBrokerIDValue;
62 auto const actual = tx.getLoanBrokerID();
63 expectEqualField(expected, actual, "sfLoanBrokerID");
64 }
65
66 {
67 auto const& expected = amountValue;
68 auto const actual = tx.getAmount();
69 expectEqualField(expected, actual, "sfAmount");
70 }
71
72 // Verify optional fields
73}
74
75// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
76// and verify all fields match.
77TEST(TransactionsLoanBrokerCoverDepositTests, BuilderFromStTxRoundTrip)
78{
79 // Generate a deterministic keypair for signing
80 auto const [publicKey, secretKey] =
81 generateKeyPair(KeyType::secp256k1, generateSeed("testLoanBrokerCoverDepositFromTx"));
82
83 // Common transaction fields
84 auto const accountValue = calcAccountID(publicKey);
85 std::uint32_t const sequenceValue = 2;
86 auto const feeValue = canonical_AMOUNT();
87
88 // Transaction-specific field values
89 auto const loanBrokerIDValue = canonical_UINT256();
90 auto const amountValue = canonical_AMOUNT();
91
92 // Build an initial transaction
93 LoanBrokerCoverDepositBuilder initialBuilder{
94 accountValue,
95 loanBrokerIDValue,
96 amountValue,
97 sequenceValue,
98 feeValue
99 };
100
101
102 auto initialTx = initialBuilder.build(publicKey, secretKey);
103
104 // Create builder from existing STTx
105 LoanBrokerCoverDepositBuilder builderFromTx{initialTx.getSTTx()};
106
107 auto rebuiltTx = builderFromTx.build(publicKey, secretKey);
108
109 std::string reason;
110 EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
111
112 // Verify common fields
113 EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
114 EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
115 EXPECT_EQ(rebuiltTx.getFee(), feeValue);
116
117 // Verify required fields
118 {
119 auto const& expected = loanBrokerIDValue;
120 auto const actual = rebuiltTx.getLoanBrokerID();
121 expectEqualField(expected, actual, "sfLoanBrokerID");
122 }
123
124 {
125 auto const& expected = amountValue;
126 auto const actual = rebuiltTx.getAmount();
127 expectEqualField(expected, actual, "sfAmount");
128 }
129
130 // Verify optional fields
131}
132
133// 3) Verify wrapper throws when constructed from wrong transaction type.
134TEST(TransactionsLoanBrokerCoverDepositTests, WrapperThrowsOnWrongTxType)
135{
136 // Build a valid transaction of a different type
137 auto const [pk, sk] =
139 auto const account = calcAccountID(pk);
140
141 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
142 auto wrongTx = wrongBuilder.build(pk, sk);
143
144 EXPECT_THROW(LoanBrokerCoverDeposit{wrongTx.getSTTx()}, std::runtime_error);
145}
146
147// 4) Verify builder throws when constructed from wrong transaction type.
148TEST(TransactionsLoanBrokerCoverDepositTests, BuilderThrowsOnWrongTxType)
149{
150 // Build a valid transaction of a different type
151 auto const [pk, sk] =
152 generateKeyPair(KeyType::secp256k1, generateSeed("testWrongTypeBuilder"));
153 auto const account = calcAccountID(pk);
154
155 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
156 auto wrongTx = wrongBuilder.build(pk, sk);
157
158 EXPECT_THROW(LoanBrokerCoverDepositBuilder{wrongTx.getSTTx()}, std::runtime_error);
159}
160
161
162}
LoanBrokerCoverDeposit build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the LoanBrokerCoverDeposit wrapper.
std::shared_ptr< STTx const > getSTTx() const
Get the underlying STTx object.
TEST(TransactionsAccountDeleteTests, BuilderSettersRoundTrip)
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:57
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
AccountID calcAccountID(PublicKey const &pk)
void expectEqualField(T const &expected, T const &actual, char const *fieldName)