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