xrpld
Loading...
Searching...
No Matches
ConfidentialMPTMirrorUpdateTests.cpp
1// Auto-generated unit tests for transaction ConfidentialMPTMirrorUpdate
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/ConfidentialMPTMirrorUpdate.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(TransactionsConfidentialMPTMirrorUpdateTests, BuilderSettersRoundTrip)
21{
22 // Generate a deterministic keypair for signing
23 auto const [publicKey, secretKey] =
24 generateKeyPair(KeyType::Secp256k1, generateSeed("testConfidentialMPTMirrorUpdate"));
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 mPTokenIssuanceIDValue = canonical_UINT192();
33 auto const holderValue = canonical_ACCOUNT();
34 auto const issuerEncryptedAmountValue = canonical_VL();
35 auto const auditorEncryptedAmountValue = canonical_VL();
36 auto const zKProofValue = canonical_VL();
37
39 accountValue,
40 mPTokenIssuanceIDValue,
41 zKProofValue,
42 sequenceValue,
43 feeValue
44 };
45
46 // Set optional fields
47 builder.setHolder(holderValue);
48 builder.setIssuerEncryptedAmount(issuerEncryptedAmountValue);
49 builder.setAuditorEncryptedAmount(auditorEncryptedAmountValue);
50
51 auto tx = builder.build(publicKey, secretKey);
52
53 std::string reason;
54 EXPECT_TRUE(tx.validate(reason)) << reason;
55
56 // Verify signing was applied
57 EXPECT_FALSE(tx.getSigningPubKey().empty());
58 EXPECT_TRUE(tx.hasTxnSignature());
59
60 // Verify common fields
61 EXPECT_EQ(tx.getAccount(), accountValue);
62 EXPECT_EQ(tx.getSequence(), sequenceValue);
63 EXPECT_EQ(tx.getFee(), feeValue);
64
65 // Verify required fields
66 {
67 auto const& expected = mPTokenIssuanceIDValue;
68 auto const actual = tx.getMPTokenIssuanceID();
69 expectEqualField(expected, actual, "sfMPTokenIssuanceID");
70 }
71
72 {
73 auto const& expected = zKProofValue;
74 auto const actual = tx.getZKProof();
75 expectEqualField(expected, actual, "sfZKProof");
76 }
77
78 // Verify optional fields
79 {
80 auto const& expected = holderValue;
81 auto const actualOpt = tx.getHolder();
82 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfHolder should be present";
83 expectEqualField(expected, *actualOpt, "sfHolder");
84 EXPECT_TRUE(tx.hasHolder());
85 }
86
87 {
88 auto const& expected = issuerEncryptedAmountValue;
89 auto const actualOpt = tx.getIssuerEncryptedAmount();
90 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfIssuerEncryptedAmount should be present";
91 expectEqualField(expected, *actualOpt, "sfIssuerEncryptedAmount");
92 EXPECT_TRUE(tx.hasIssuerEncryptedAmount());
93 }
94
95 {
96 auto const& expected = auditorEncryptedAmountValue;
97 auto const actualOpt = tx.getAuditorEncryptedAmount();
98 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfAuditorEncryptedAmount should be present";
99 expectEqualField(expected, *actualOpt, "sfAuditorEncryptedAmount");
100 EXPECT_TRUE(tx.hasAuditorEncryptedAmount());
101 }
102
103}
104
105// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
106// and verify all fields match.
107TEST(TransactionsConfidentialMPTMirrorUpdateTests, BuilderFromStTxRoundTrip)
108{
109 // Generate a deterministic keypair for signing
110 auto const [publicKey, secretKey] =
111 generateKeyPair(KeyType::Secp256k1, generateSeed("testConfidentialMPTMirrorUpdateFromTx"));
112
113 // Common transaction fields
114 auto const accountValue = calcAccountID(publicKey);
115 std::uint32_t const sequenceValue = 2;
116 auto const feeValue = canonical_AMOUNT();
117
118 // Transaction-specific field values
119 auto const mPTokenIssuanceIDValue = canonical_UINT192();
120 auto const holderValue = canonical_ACCOUNT();
121 auto const issuerEncryptedAmountValue = canonical_VL();
122 auto const auditorEncryptedAmountValue = canonical_VL();
123 auto const zKProofValue = canonical_VL();
124
125 // Build an initial transaction
127 accountValue,
128 mPTokenIssuanceIDValue,
129 zKProofValue,
130 sequenceValue,
131 feeValue
132 };
133
134 initialBuilder.setHolder(holderValue);
135 initialBuilder.setIssuerEncryptedAmount(issuerEncryptedAmountValue);
136 initialBuilder.setAuditorEncryptedAmount(auditorEncryptedAmountValue);
137
138 auto initialTx = initialBuilder.build(publicKey, secretKey);
139
140 // Create builder from existing STTx
141 ConfidentialMPTMirrorUpdateBuilder builderFromTx{initialTx.getSTTx()};
142
143 auto rebuiltTx = builderFromTx.build(publicKey, secretKey);
144
145 std::string reason;
146 EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
147
148 // Verify common fields
149 EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
150 EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
151 EXPECT_EQ(rebuiltTx.getFee(), feeValue);
152
153 // Verify required fields
154 {
155 auto const& expected = mPTokenIssuanceIDValue;
156 auto const actual = rebuiltTx.getMPTokenIssuanceID();
157 expectEqualField(expected, actual, "sfMPTokenIssuanceID");
158 }
159
160 {
161 auto const& expected = zKProofValue;
162 auto const actual = rebuiltTx.getZKProof();
163 expectEqualField(expected, actual, "sfZKProof");
164 }
165
166 // Verify optional fields
167 {
168 auto const& expected = holderValue;
169 auto const actualOpt = rebuiltTx.getHolder();
170 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfHolder should be present";
171 expectEqualField(expected, *actualOpt, "sfHolder");
172 }
173
174 {
175 auto const& expected = issuerEncryptedAmountValue;
176 auto const actualOpt = rebuiltTx.getIssuerEncryptedAmount();
177 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfIssuerEncryptedAmount should be present";
178 expectEqualField(expected, *actualOpt, "sfIssuerEncryptedAmount");
179 }
180
181 {
182 auto const& expected = auditorEncryptedAmountValue;
183 auto const actualOpt = rebuiltTx.getAuditorEncryptedAmount();
184 ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfAuditorEncryptedAmount should be present";
185 expectEqualField(expected, *actualOpt, "sfAuditorEncryptedAmount");
186 }
187
188}
189
190// 3) Verify wrapper throws when constructed from wrong transaction type.
191TEST(TransactionsConfidentialMPTMirrorUpdateTests, WrapperThrowsOnWrongTxType)
192{
193 // Build a valid transaction of a different type
194 auto const [pk, sk] =
196 auto const account = calcAccountID(pk);
197
198 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
199 auto wrongTx = wrongBuilder.build(pk, sk);
200
201 EXPECT_THROW(ConfidentialMPTMirrorUpdate{wrongTx.getSTTx()}, std::runtime_error);
202}
203
204// 4) Verify builder throws when constructed from wrong transaction type.
205TEST(TransactionsConfidentialMPTMirrorUpdateTests, BuilderThrowsOnWrongTxType)
206{
207 // Build a valid transaction of a different type
208 auto const [pk, sk] =
209 generateKeyPair(KeyType::Secp256k1, generateSeed("testWrongTypeBuilder"));
210 auto const account = calcAccountID(pk);
211
212 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
213 auto wrongTx = wrongBuilder.build(pk, sk);
214
215 EXPECT_THROW(ConfidentialMPTMirrorUpdateBuilder{wrongTx.getSTTx()}, std::runtime_error);
216}
217
218// 5) Build with only required fields and verify optional fields return nullopt.
219TEST(TransactionsConfidentialMPTMirrorUpdateTests, OptionalFieldsReturnNullopt)
220{
221 // Generate a deterministic keypair for signing
222 auto const [publicKey, secretKey] =
223 generateKeyPair(KeyType::Secp256k1, generateSeed("testConfidentialMPTMirrorUpdateNullopt"));
224
225 // Common transaction fields
226 auto const accountValue = calcAccountID(publicKey);
227 std::uint32_t const sequenceValue = 3;
228 auto const feeValue = canonical_AMOUNT();
229
230 // Transaction-specific required field values
231 auto const mPTokenIssuanceIDValue = canonical_UINT192();
232 auto const zKProofValue = canonical_VL();
233
235 accountValue,
236 mPTokenIssuanceIDValue,
237 zKProofValue,
238 sequenceValue,
239 feeValue
240 };
241
242 // Do NOT set optional fields
243
244 auto tx = builder.build(publicKey, secretKey);
245
246 // Verify optional fields are not present
247 EXPECT_FALSE(tx.hasHolder());
248 EXPECT_FALSE(tx.getHolder().has_value());
249 EXPECT_FALSE(tx.hasIssuerEncryptedAmount());
250 EXPECT_FALSE(tx.getIssuerEncryptedAmount().has_value());
251 EXPECT_FALSE(tx.hasAuditorEncryptedAmount());
252 EXPECT_FALSE(tx.getAuditorEncryptedAmount().has_value());
253}
254
255}
AccountSet build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the AccountSet wrapper.
ConfidentialMPTMirrorUpdate build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the ConfidentialMPTMirrorUpdate wrapper.
ConfidentialMPTMirrorUpdateBuilder & setAuditorEncryptedAmount(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfAuditorEncryptedAmount (SoeOptional).
ConfidentialMPTMirrorUpdateBuilder & setIssuerEncryptedAmount(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfIssuerEncryptedAmount (SoeOptional).
ConfidentialMPTMirrorUpdateBuilder & setHolder(std::decay_t< typename SF_ACCOUNT::type::value_type > const &value)
Set sfHolder (SoeOptional).
TEST(TransactionsAccountDeleteTests, BuilderSettersRoundTrip)
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:58
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)