xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
protocol_autogen
transactions
VaultDeleteTests.cpp
1
// Auto-generated unit tests for transaction VaultDelete
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/VaultDelete.h>
12
#include <xrpl/protocol_autogen/transactions/AccountSet.h>
13
14
#include <
string
>
15
16
namespace
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.
20
TEST
(TransactionsVaultDeleteTests, BuilderSettersRoundTrip)
21
{
22
// Generate a deterministic keypair for signing
23
auto
const
[publicKey, secretKey] =
24
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testVaultDelete"
));
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
vaultIDValue =
canonical_UINT256
();
33
auto
const
memoDataValue =
canonical_VL
();
34
35
VaultDeleteBuilder
builder{
36
accountValue,
37
vaultIDValue,
38
sequenceValue,
39
feeValue
40
};
41
42
// Set optional fields
43
builder.
setMemoData
(memoDataValue);
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 = vaultIDValue;
62
auto
const
actual = tx.getVaultID();
63
expectEqualField
(expected, actual,
"sfVaultID"
);
64
}
65
66
// Verify optional fields
67
{
68
auto
const
& expected = memoDataValue;
69
auto
const
actualOpt = tx.getMemoData();
70
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfMemoData should be present"
;
71
expectEqualField
(expected, *actualOpt,
"sfMemoData"
);
72
EXPECT_TRUE(tx.hasMemoData());
73
}
74
75
}
76
77
// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
78
// and verify all fields match.
79
TEST
(TransactionsVaultDeleteTests, BuilderFromStTxRoundTrip)
80
{
81
// Generate a deterministic keypair for signing
82
auto
const
[publicKey, secretKey] =
83
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testVaultDeleteFromTx"
));
84
85
// Common transaction fields
86
auto
const
accountValue =
calcAccountID
(publicKey);
87
std::uint32_t
const
sequenceValue = 2;
88
auto
const
feeValue =
canonical_AMOUNT
();
89
90
// Transaction-specific field values
91
auto
const
vaultIDValue =
canonical_UINT256
();
92
auto
const
memoDataValue =
canonical_VL
();
93
94
// Build an initial transaction
95
VaultDeleteBuilder
initialBuilder{
96
accountValue,
97
vaultIDValue,
98
sequenceValue,
99
feeValue
100
};
101
102
initialBuilder.
setMemoData
(memoDataValue);
103
104
auto
initialTx = initialBuilder.
build
(publicKey, secretKey);
105
106
// Create builder from existing STTx
107
VaultDeleteBuilder
builderFromTx{initialTx.getSTTx()};
108
109
auto
rebuiltTx = builderFromTx.
build
(publicKey, secretKey);
110
111
std::string
reason;
112
EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
113
114
// Verify common fields
115
EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
116
EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
117
EXPECT_EQ(rebuiltTx.getFee(), feeValue);
118
119
// Verify required fields
120
{
121
auto
const
& expected = vaultIDValue;
122
auto
const
actual = rebuiltTx.getVaultID();
123
expectEqualField
(expected, actual,
"sfVaultID"
);
124
}
125
126
// Verify optional fields
127
{
128
auto
const
& expected = memoDataValue;
129
auto
const
actualOpt = rebuiltTx.getMemoData();
130
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfMemoData should be present"
;
131
expectEqualField
(expected, *actualOpt,
"sfMemoData"
);
132
}
133
134
}
135
136
// 3) Verify wrapper throws when constructed from wrong transaction type.
137
TEST
(TransactionsVaultDeleteTests, WrapperThrowsOnWrongTxType)
138
{
139
// Build a valid transaction of a different type
140
auto
const
[pk, sk] =
141
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongType"
));
142
auto
const
account =
calcAccountID
(pk);
143
144
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
145
auto
wrongTx = wrongBuilder.
build
(pk, sk);
146
147
EXPECT_THROW(
VaultDelete
{wrongTx.getSTTx()},
std::runtime_error
);
148
}
149
150
// 4) Verify builder throws when constructed from wrong transaction type.
151
TEST
(TransactionsVaultDeleteTests, BuilderThrowsOnWrongTxType)
152
{
153
// Build a valid transaction of a different type
154
auto
const
[pk, sk] =
155
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongTypeBuilder"
));
156
auto
const
account =
calcAccountID
(pk);
157
158
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
159
auto
wrongTx = wrongBuilder.
build
(pk, sk);
160
161
EXPECT_THROW(
VaultDeleteBuilder
{wrongTx.getSTTx()},
std::runtime_error
);
162
}
163
164
// 5) Build with only required fields and verify optional fields return nullopt.
165
TEST
(TransactionsVaultDeleteTests, OptionalFieldsReturnNullopt)
166
{
167
// Generate a deterministic keypair for signing
168
auto
const
[publicKey, secretKey] =
169
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testVaultDeleteNullopt"
));
170
171
// Common transaction fields
172
auto
const
accountValue =
calcAccountID
(publicKey);
173
std::uint32_t
const
sequenceValue = 3;
174
auto
const
feeValue =
canonical_AMOUNT
();
175
176
// Transaction-specific required field values
177
auto
const
vaultIDValue =
canonical_UINT256
();
178
179
VaultDeleteBuilder
builder{
180
accountValue,
181
vaultIDValue,
182
sequenceValue,
183
feeValue
184
};
185
186
// Do NOT set optional fields
187
188
auto
tx = builder.
build
(publicKey, secretKey);
189
190
// Verify optional fields are not present
191
EXPECT_FALSE(tx.hasMemoData());
192
EXPECT_FALSE(tx.getMemoData().has_value());
193
}
194
195
}
std::string
xrpl::transactions::AccountSetBuilder
Builder for AccountSet transactions.
Definition
protocol_autogen/transactions/AccountSet.h:319
xrpl::transactions::AccountSetBuilder::build
AccountSet build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the AccountSet wrapper.
Definition
protocol_autogen/transactions/AccountSet.h:470
xrpl::transactions::VaultDeleteBuilder
Builder for VaultDelete transactions.
Definition
protocol_autogen/transactions/VaultDelete.h:96
xrpl::transactions::VaultDeleteBuilder::build
VaultDelete build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the VaultDelete wrapper.
Definition
protocol_autogen/transactions/VaultDelete.h:161
xrpl::transactions::VaultDeleteBuilder::setMemoData
VaultDeleteBuilder & setMemoData(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfMemoData (SoeOptional).
Definition
protocol_autogen/transactions/VaultDelete.h:148
xrpl::transactions::VaultDelete
Transaction: VaultDelete.
Definition
protocol_autogen/transactions/VaultDelete.h:30
std::uint32_t
xrpl::transactions
Definition
TransactionBase.h:15
xrpl::transactions::TEST
TEST(TransactionsAccountDeleteTests, BuilderSettersRoundTrip)
Definition
AccountDeleteTests.cpp:20
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::canonical_VL
BlobValue canonical_VL()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:139
xrpl::canonical_UINT256
UInt256Value canonical_UINT256()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:83
xrpl::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition
Seed.cpp:58
xrpl::generateKeyPair
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
Definition
SecretKey.cpp:338
xrpl::canonical_AMOUNT
AmountValue canonical_AMOUNT()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:104
xrpl::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition
AccountID.cpp:149
xrpl::expectEqualField
void expectEqualField(T const &expected, T const &actual, char const *fieldName)
Definition
/libxrpl/protocol_autogen/TestHelpers.h:178
std::runtime_error
string
Generated by
1.17.0