xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
protocol_autogen
transactions
AMMBidTests.cpp
1
// Auto-generated unit tests for transaction AMMBid
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/AMMBid.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
(TransactionsAMMBidTests, BuilderSettersRoundTrip)
21
{
22
// Generate a deterministic keypair for signing
23
auto
const
[publicKey, secretKey] =
24
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testAMMBid"
));
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
assetValue =
canonical_ISSUE
();
33
auto
const
asset2Value =
canonical_ISSUE
();
34
auto
const
bidMinValue =
canonical_AMOUNT
();
35
auto
const
bidMaxValue =
canonical_AMOUNT
();
36
auto
const
authAccountsValue =
canonical_ARRAY
();
37
38
AMMBidBuilder
builder{
39
accountValue,
40
assetValue,
41
asset2Value,
42
sequenceValue,
43
feeValue
44
};
45
46
// Set optional fields
47
builder.
setBidMin
(bidMinValue);
48
builder.
setBidMax
(bidMaxValue);
49
builder.
setAuthAccounts
(authAccountsValue);
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 = assetValue;
68
auto
const
actual = tx.getAsset();
69
expectEqualField
(expected, actual,
"sfAsset"
);
70
}
71
72
{
73
auto
const
& expected = asset2Value;
74
auto
const
actual = tx.getAsset2();
75
expectEqualField
(expected, actual,
"sfAsset2"
);
76
}
77
78
// Verify optional fields
79
{
80
auto
const
& expected = bidMinValue;
81
auto
const
actualOpt = tx.getBidMin();
82
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfBidMin should be present"
;
83
expectEqualField
(expected, *actualOpt,
"sfBidMin"
);
84
EXPECT_TRUE(tx.hasBidMin());
85
}
86
87
{
88
auto
const
& expected = bidMaxValue;
89
auto
const
actualOpt = tx.getBidMax();
90
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfBidMax should be present"
;
91
expectEqualField
(expected, *actualOpt,
"sfBidMax"
);
92
EXPECT_TRUE(tx.hasBidMax());
93
}
94
95
{
96
auto
const
& expected = authAccountsValue;
97
auto
const
actualOpt = tx.getAuthAccounts();
98
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfAuthAccounts should be present"
;
99
expectEqualField
(expected, *actualOpt,
"sfAuthAccounts"
);
100
EXPECT_TRUE(tx.hasAuthAccounts());
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.
107
TEST
(TransactionsAMMBidTests, BuilderFromStTxRoundTrip)
108
{
109
// Generate a deterministic keypair for signing
110
auto
const
[publicKey, secretKey] =
111
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testAMMBidFromTx"
));
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
assetValue =
canonical_ISSUE
();
120
auto
const
asset2Value =
canonical_ISSUE
();
121
auto
const
bidMinValue =
canonical_AMOUNT
();
122
auto
const
bidMaxValue =
canonical_AMOUNT
();
123
auto
const
authAccountsValue =
canonical_ARRAY
();
124
125
// Build an initial transaction
126
AMMBidBuilder
initialBuilder{
127
accountValue,
128
assetValue,
129
asset2Value,
130
sequenceValue,
131
feeValue
132
};
133
134
initialBuilder.
setBidMin
(bidMinValue);
135
initialBuilder.
setBidMax
(bidMaxValue);
136
initialBuilder.
setAuthAccounts
(authAccountsValue);
137
138
auto
initialTx = initialBuilder.
build
(publicKey, secretKey);
139
140
// Create builder from existing STTx
141
AMMBidBuilder
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 = assetValue;
156
auto
const
actual = rebuiltTx.getAsset();
157
expectEqualField
(expected, actual,
"sfAsset"
);
158
}
159
160
{
161
auto
const
& expected = asset2Value;
162
auto
const
actual = rebuiltTx.getAsset2();
163
expectEqualField
(expected, actual,
"sfAsset2"
);
164
}
165
166
// Verify optional fields
167
{
168
auto
const
& expected = bidMinValue;
169
auto
const
actualOpt = rebuiltTx.getBidMin();
170
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfBidMin should be present"
;
171
expectEqualField
(expected, *actualOpt,
"sfBidMin"
);
172
}
173
174
{
175
auto
const
& expected = bidMaxValue;
176
auto
const
actualOpt = rebuiltTx.getBidMax();
177
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfBidMax should be present"
;
178
expectEqualField
(expected, *actualOpt,
"sfBidMax"
);
179
}
180
181
{
182
auto
const
& expected = authAccountsValue;
183
auto
const
actualOpt = rebuiltTx.getAuthAccounts();
184
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfAuthAccounts should be present"
;
185
expectEqualField
(expected, *actualOpt,
"sfAuthAccounts"
);
186
}
187
188
}
189
190
// 3) Verify wrapper throws when constructed from wrong transaction type.
191
TEST
(TransactionsAMMBidTests, WrapperThrowsOnWrongTxType)
192
{
193
// Build a valid transaction of a different type
194
auto
const
[pk, sk] =
195
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongType"
));
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(
AMMBid
{wrongTx.getSTTx()},
std::runtime_error
);
202
}
203
204
// 4) Verify builder throws when constructed from wrong transaction type.
205
TEST
(TransactionsAMMBidTests, 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(
AMMBidBuilder
{wrongTx.getSTTx()},
std::runtime_error
);
216
}
217
218
// 5) Build with only required fields and verify optional fields return nullopt.
219
TEST
(TransactionsAMMBidTests, OptionalFieldsReturnNullopt)
220
{
221
// Generate a deterministic keypair for signing
222
auto
const
[publicKey, secretKey] =
223
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testAMMBidNullopt"
));
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
assetValue =
canonical_ISSUE
();
232
auto
const
asset2Value =
canonical_ISSUE
();
233
234
AMMBidBuilder
builder{
235
accountValue,
236
assetValue,
237
asset2Value,
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.hasBidMin());
248
EXPECT_FALSE(tx.getBidMin().has_value());
249
EXPECT_FALSE(tx.hasBidMax());
250
EXPECT_FALSE(tx.getBidMax().has_value());
251
EXPECT_FALSE(tx.hasAuthAccounts());
252
EXPECT_FALSE(tx.getAuthAccounts().has_value());
253
}
254
255
}
std::string
xrpl::transactions::AMMBidBuilder
Builder for AMMBid transactions.
Definition
protocol_autogen/transactions/AMMBid.h:159
xrpl::transactions::AMMBidBuilder::setBidMax
AMMBidBuilder & setBidMax(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfBidMax (SoeOptional).
Definition
protocol_autogen/transactions/AMMBid.h:237
xrpl::transactions::AMMBidBuilder::setAuthAccounts
AMMBidBuilder & setAuthAccounts(STArray const &value)
Set sfAuthAccounts (SoeOptional).
Definition
protocol_autogen/transactions/AMMBid.h:248
xrpl::transactions::AMMBidBuilder::setBidMin
AMMBidBuilder & setBidMin(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfBidMin (SoeOptional).
Definition
protocol_autogen/transactions/AMMBid.h:226
xrpl::transactions::AMMBidBuilder::build
AMMBid build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the AMMBid wrapper.
Definition
protocol_autogen/transactions/AMMBid.h:261
xrpl::transactions::AMMBid
Transaction: AMMBid.
Definition
protocol_autogen/transactions/AMMBid.h:30
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
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::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition
Seed.cpp:58
xrpl::canonical_ISSUE
IssueValue canonical_ISSUE()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:125
xrpl::generateKeyPair
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
Definition
SecretKey.cpp:338
xrpl::canonical_ARRAY
STArray canonical_ARRAY()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:155
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