xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
protocol_autogen
transactions
NFTokenModifyTests.cpp
1
// Auto-generated unit tests for transaction NFTokenModify
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/NFTokenModify.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
(TransactionsNFTokenModifyTests, BuilderSettersRoundTrip)
21
{
22
// Generate a deterministic keypair for signing
23
auto
const
[publicKey, secretKey] =
24
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testNFTokenModify"
));
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
nFTokenIDValue =
canonical_UINT256
();
33
auto
const
ownerValue =
canonical_ACCOUNT
();
34
auto
const
uRIValue =
canonical_VL
();
35
36
NFTokenModifyBuilder
builder{
37
accountValue,
38
nFTokenIDValue,
39
sequenceValue,
40
feeValue
41
};
42
43
// Set optional fields
44
builder.
setOwner
(ownerValue);
45
builder.
setURI
(uRIValue);
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 = nFTokenIDValue;
64
auto
const
actual = tx.getNFTokenID();
65
expectEqualField
(expected, actual,
"sfNFTokenID"
);
66
}
67
68
// Verify optional fields
69
{
70
auto
const
& expected = ownerValue;
71
auto
const
actualOpt = tx.getOwner();
72
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfOwner should be present"
;
73
expectEqualField
(expected, *actualOpt,
"sfOwner"
);
74
EXPECT_TRUE(tx.hasOwner());
75
}
76
77
{
78
auto
const
& expected = uRIValue;
79
auto
const
actualOpt = tx.getURI();
80
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfURI should be present"
;
81
expectEqualField
(expected, *actualOpt,
"sfURI"
);
82
EXPECT_TRUE(tx.hasURI());
83
}
84
85
}
86
87
// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
88
// and verify all fields match.
89
TEST
(TransactionsNFTokenModifyTests, BuilderFromStTxRoundTrip)
90
{
91
// Generate a deterministic keypair for signing
92
auto
const
[publicKey, secretKey] =
93
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testNFTokenModifyFromTx"
));
94
95
// Common transaction fields
96
auto
const
accountValue =
calcAccountID
(publicKey);
97
std::uint32_t
const
sequenceValue = 2;
98
auto
const
feeValue =
canonical_AMOUNT
();
99
100
// Transaction-specific field values
101
auto
const
nFTokenIDValue =
canonical_UINT256
();
102
auto
const
ownerValue =
canonical_ACCOUNT
();
103
auto
const
uRIValue =
canonical_VL
();
104
105
// Build an initial transaction
106
NFTokenModifyBuilder
initialBuilder{
107
accountValue,
108
nFTokenIDValue,
109
sequenceValue,
110
feeValue
111
};
112
113
initialBuilder.
setOwner
(ownerValue);
114
initialBuilder.
setURI
(uRIValue);
115
116
auto
initialTx = initialBuilder.
build
(publicKey, secretKey);
117
118
// Create builder from existing STTx
119
NFTokenModifyBuilder
builderFromTx{initialTx.getSTTx()};
120
121
auto
rebuiltTx = builderFromTx.
build
(publicKey, secretKey);
122
123
std::string
reason;
124
EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
125
126
// Verify common fields
127
EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
128
EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
129
EXPECT_EQ(rebuiltTx.getFee(), feeValue);
130
131
// Verify required fields
132
{
133
auto
const
& expected = nFTokenIDValue;
134
auto
const
actual = rebuiltTx.getNFTokenID();
135
expectEqualField
(expected, actual,
"sfNFTokenID"
);
136
}
137
138
// Verify optional fields
139
{
140
auto
const
& expected = ownerValue;
141
auto
const
actualOpt = rebuiltTx.getOwner();
142
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfOwner should be present"
;
143
expectEqualField
(expected, *actualOpt,
"sfOwner"
);
144
}
145
146
{
147
auto
const
& expected = uRIValue;
148
auto
const
actualOpt = rebuiltTx.getURI();
149
ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfURI should be present"
;
150
expectEqualField
(expected, *actualOpt,
"sfURI"
);
151
}
152
153
}
154
155
// 3) Verify wrapper throws when constructed from wrong transaction type.
156
TEST
(TransactionsNFTokenModifyTests, WrapperThrowsOnWrongTxType)
157
{
158
// Build a valid transaction of a different type
159
auto
const
[pk, sk] =
160
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongType"
));
161
auto
const
account =
calcAccountID
(pk);
162
163
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
164
auto
wrongTx = wrongBuilder.
build
(pk, sk);
165
166
EXPECT_THROW(
NFTokenModify
{wrongTx.getSTTx()},
std::runtime_error
);
167
}
168
169
// 4) Verify builder throws when constructed from wrong transaction type.
170
TEST
(TransactionsNFTokenModifyTests, BuilderThrowsOnWrongTxType)
171
{
172
// Build a valid transaction of a different type
173
auto
const
[pk, sk] =
174
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongTypeBuilder"
));
175
auto
const
account =
calcAccountID
(pk);
176
177
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
178
auto
wrongTx = wrongBuilder.
build
(pk, sk);
179
180
EXPECT_THROW(
NFTokenModifyBuilder
{wrongTx.getSTTx()},
std::runtime_error
);
181
}
182
183
// 5) Build with only required fields and verify optional fields return nullopt.
184
TEST
(TransactionsNFTokenModifyTests, OptionalFieldsReturnNullopt)
185
{
186
// Generate a deterministic keypair for signing
187
auto
const
[publicKey, secretKey] =
188
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testNFTokenModifyNullopt"
));
189
190
// Common transaction fields
191
auto
const
accountValue =
calcAccountID
(publicKey);
192
std::uint32_t
const
sequenceValue = 3;
193
auto
const
feeValue =
canonical_AMOUNT
();
194
195
// Transaction-specific required field values
196
auto
const
nFTokenIDValue =
canonical_UINT256
();
197
198
NFTokenModifyBuilder
builder{
199
accountValue,
200
nFTokenIDValue,
201
sequenceValue,
202
feeValue
203
};
204
205
// Do NOT set optional fields
206
207
auto
tx = builder.
build
(publicKey, secretKey);
208
209
// Verify optional fields are not present
210
EXPECT_FALSE(tx.hasOwner());
211
EXPECT_FALSE(tx.getOwner().has_value());
212
EXPECT_FALSE(tx.hasURI());
213
EXPECT_FALSE(tx.getURI().has_value());
214
}
215
216
}
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::NFTokenModifyBuilder
Builder for NFTokenModify transactions.
Definition
protocol_autogen/transactions/NFTokenModify.h:122
xrpl::transactions::NFTokenModifyBuilder::setOwner
NFTokenModifyBuilder & setOwner(std::decay_t< typename SF_ACCOUNT::type::value_type > const &value)
Set sfOwner (SoeOptional).
Definition
protocol_autogen/transactions/NFTokenModify.h:174
xrpl::transactions::NFTokenModifyBuilder::setURI
NFTokenModifyBuilder & setURI(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfURI (SoeOptional).
Definition
protocol_autogen/transactions/NFTokenModify.h:185
xrpl::transactions::NFTokenModifyBuilder::build
NFTokenModify build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the NFTokenModify wrapper.
Definition
protocol_autogen/transactions/NFTokenModify.h:198
xrpl::transactions::NFTokenModify
Transaction: NFTokenModify.
Definition
protocol_autogen/transactions/NFTokenModify.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_ACCOUNT
AccountValue canonical_ACCOUNT()
Definition
/libxrpl/protocol_autogen/TestHelpers.h:111
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