rippled
Loading...
Searching...
No Matches
DIDDeleteTests.cpp
1// Auto-generated unit tests for transaction DIDDelete
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/DIDDelete.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(TransactionsDIDDeleteTests, BuilderSettersRoundTrip)
21{
22 // Generate a deterministic keypair for signing
23 auto const [publicKey, secretKey] =
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
33 DIDDeleteBuilder builder{
34 accountValue,
35 sequenceValue,
36 feeValue
37 };
38
39 // Set optional fields
40
41 auto tx = builder.build(publicKey, secretKey);
42
43 std::string reason;
44 EXPECT_TRUE(tx.validate(reason)) << reason;
45
46 // Verify signing was applied
47 EXPECT_FALSE(tx.getSigningPubKey().empty());
48 EXPECT_TRUE(tx.hasTxnSignature());
49
50 // Verify common fields
51 EXPECT_EQ(tx.getAccount(), accountValue);
52 EXPECT_EQ(tx.getSequence(), sequenceValue);
53 EXPECT_EQ(tx.getFee(), feeValue);
54
55 // Verify required fields
56 // Verify optional fields
57}
58
59// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
60// and verify all fields match.
61TEST(TransactionsDIDDeleteTests, BuilderFromStTxRoundTrip)
62{
63 // Generate a deterministic keypair for signing
64 auto const [publicKey, secretKey] =
65 generateKeyPair(KeyType::secp256k1, generateSeed("testDIDDeleteFromTx"));
66
67 // Common transaction fields
68 auto const accountValue = calcAccountID(publicKey);
69 std::uint32_t const sequenceValue = 2;
70 auto const feeValue = canonical_AMOUNT();
71
72 // Transaction-specific field values
73
74 // Build an initial transaction
75 DIDDeleteBuilder initialBuilder{
76 accountValue,
77 sequenceValue,
78 feeValue
79 };
80
81
82 auto initialTx = initialBuilder.build(publicKey, secretKey);
83
84 // Create builder from existing STTx
85 DIDDeleteBuilder builderFromTx{initialTx.getSTTx()};
86
87 auto rebuiltTx = builderFromTx.build(publicKey, secretKey);
88
89 std::string reason;
90 EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
91
92 // Verify common fields
93 EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
94 EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
95 EXPECT_EQ(rebuiltTx.getFee(), feeValue);
96
97 // Verify required fields
98 // Verify optional fields
99}
100
101// 3) Verify wrapper throws when constructed from wrong transaction type.
102TEST(TransactionsDIDDeleteTests, WrapperThrowsOnWrongTxType)
103{
104 // Build a valid transaction of a different type
105 auto const [pk, sk] =
107 auto const account = calcAccountID(pk);
108
109 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
110 auto wrongTx = wrongBuilder.build(pk, sk);
111
112 EXPECT_THROW(DIDDelete{wrongTx.getSTTx()}, std::runtime_error);
113}
114
115// 4) Verify builder throws when constructed from wrong transaction type.
116TEST(TransactionsDIDDeleteTests, BuilderThrowsOnWrongTxType)
117{
118 // Build a valid transaction of a different type
119 auto const [pk, sk] =
120 generateKeyPair(KeyType::secp256k1, generateSeed("testWrongTypeBuilder"));
121 auto const account = calcAccountID(pk);
122
123 AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
124 auto wrongTx = wrongBuilder.build(pk, sk);
125
126 EXPECT_THROW(DIDDeleteBuilder{wrongTx.getSTTx()}, std::runtime_error);
127}
128
129
130}
DIDDelete build(PublicKey const &publicKey, SecretKey const &secretKey)
Transaction-specific field setters.
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)