xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
protocol_autogen
transactions
AMMCreateTests.cpp
1
// Auto-generated unit tests for transaction AMMCreate
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/AMMCreate.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
(TransactionsAMMCreateTests, BuilderSettersRoundTrip)
21
{
22
// Generate a deterministic keypair for signing
23
auto
const
[publicKey, secretKey] =
24
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testAMMCreate"
));
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
amountValue =
canonical_AMOUNT
();
33
auto
const
amount2Value =
canonical_AMOUNT
();
34
auto
const
tradingFeeValue =
canonical_UINT16
();
35
36
AMMCreateBuilder
builder{
37
accountValue,
38
amountValue,
39
amount2Value,
40
tradingFeeValue,
41
sequenceValue,
42
feeValue
43
};
44
45
// Set optional fields
46
47
auto
tx = builder.
build
(publicKey, secretKey);
48
49
std::string
reason;
50
EXPECT_TRUE(tx.validate(reason)) << reason;
51
52
// Verify signing was applied
53
EXPECT_FALSE(tx.getSigningPubKey().empty());
54
EXPECT_TRUE(tx.hasTxnSignature());
55
56
// Verify common fields
57
EXPECT_EQ(tx.getAccount(), accountValue);
58
EXPECT_EQ(tx.getSequence(), sequenceValue);
59
EXPECT_EQ(tx.getFee(), feeValue);
60
61
// Verify required fields
62
{
63
auto
const
& expected = amountValue;
64
auto
const
actual = tx.getAmount();
65
expectEqualField
(expected, actual,
"sfAmount"
);
66
}
67
68
{
69
auto
const
& expected = amount2Value;
70
auto
const
actual = tx.getAmount2();
71
expectEqualField
(expected, actual,
"sfAmount2"
);
72
}
73
74
{
75
auto
const
& expected = tradingFeeValue;
76
auto
const
actual = tx.getTradingFee();
77
expectEqualField
(expected, actual,
"sfTradingFee"
);
78
}
79
80
// Verify optional fields
81
}
82
83
// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
84
// and verify all fields match.
85
TEST
(TransactionsAMMCreateTests, BuilderFromStTxRoundTrip)
86
{
87
// Generate a deterministic keypair for signing
88
auto
const
[publicKey, secretKey] =
89
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testAMMCreateFromTx"
));
90
91
// Common transaction fields
92
auto
const
accountValue =
calcAccountID
(publicKey);
93
std::uint32_t
const
sequenceValue = 2;
94
auto
const
feeValue =
canonical_AMOUNT
();
95
96
// Transaction-specific field values
97
auto
const
amountValue =
canonical_AMOUNT
();
98
auto
const
amount2Value =
canonical_AMOUNT
();
99
auto
const
tradingFeeValue =
canonical_UINT16
();
100
101
// Build an initial transaction
102
AMMCreateBuilder
initialBuilder{
103
accountValue,
104
amountValue,
105
amount2Value,
106
tradingFeeValue,
107
sequenceValue,
108
feeValue
109
};
110
111
112
auto
initialTx = initialBuilder.
build
(publicKey, secretKey);
113
114
// Create builder from existing STTx
115
AMMCreateBuilder
builderFromTx{initialTx.getSTTx()};
116
117
auto
rebuiltTx = builderFromTx.
build
(publicKey, secretKey);
118
119
std::string
reason;
120
EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
121
122
// Verify common fields
123
EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
124
EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
125
EXPECT_EQ(rebuiltTx.getFee(), feeValue);
126
127
// Verify required fields
128
{
129
auto
const
& expected = amountValue;
130
auto
const
actual = rebuiltTx.getAmount();
131
expectEqualField
(expected, actual,
"sfAmount"
);
132
}
133
134
{
135
auto
const
& expected = amount2Value;
136
auto
const
actual = rebuiltTx.getAmount2();
137
expectEqualField
(expected, actual,
"sfAmount2"
);
138
}
139
140
{
141
auto
const
& expected = tradingFeeValue;
142
auto
const
actual = rebuiltTx.getTradingFee();
143
expectEqualField
(expected, actual,
"sfTradingFee"
);
144
}
145
146
// Verify optional fields
147
}
148
149
// 3) Verify wrapper throws when constructed from wrong transaction type.
150
TEST
(TransactionsAMMCreateTests, WrapperThrowsOnWrongTxType)
151
{
152
// Build a valid transaction of a different type
153
auto
const
[pk, sk] =
154
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongType"
));
155
auto
const
account =
calcAccountID
(pk);
156
157
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
158
auto
wrongTx = wrongBuilder.
build
(pk, sk);
159
160
EXPECT_THROW(
AMMCreate
{wrongTx.getSTTx()},
std::runtime_error
);
161
}
162
163
// 4) Verify builder throws when constructed from wrong transaction type.
164
TEST
(TransactionsAMMCreateTests, BuilderThrowsOnWrongTxType)
165
{
166
// Build a valid transaction of a different type
167
auto
const
[pk, sk] =
168
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongTypeBuilder"
));
169
auto
const
account =
calcAccountID
(pk);
170
171
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
172
auto
wrongTx = wrongBuilder.
build
(pk, sk);
173
174
EXPECT_THROW(
AMMCreateBuilder
{wrongTx.getSTTx()},
std::runtime_error
);
175
}
176
177
178
}
std::string
xrpl::transactions::AMMCreateBuilder
Builder for AMMCreate transactions.
Definition
protocol_autogen/transactions/AMMCreate.h:94
xrpl::transactions::AMMCreateBuilder::build
AMMCreate build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the AMMCreate wrapper.
Definition
protocol_autogen/transactions/AMMCreate.h:176
xrpl::transactions::AMMCreate
Transaction: AMMCreate.
Definition
protocol_autogen/transactions/AMMCreate.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::canonical_UINT16
UInt16Value canonical_UINT16()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:41
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