xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
protocol_autogen
transactions
DIDDeleteTests.cpp
1
// Auto-generated unit tests for transaction DIDDelete
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/DIDDelete.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
(TransactionsDIDDeleteTests, BuilderSettersRoundTrip)
21
{
22
// Generate a deterministic keypair for signing
23
auto
const
[publicKey, secretKey] =
24
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testDIDDelete"
));
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
33
DIDDeleteBuilder
builder{
34
accountValue,
35
sequenceValue,
36
feeValue
37
};
38
39
// Set optional fields
40
41
auto
tx = builder.
build
(publicKey, secretKey);
42
43
std::string
reason;
44
EXPECT_TRUE(tx.validate(reason)) << reason;
45
46
// Verify signing was applied
47
EXPECT_FALSE(tx.getSigningPubKey().empty());
48
EXPECT_TRUE(tx.hasTxnSignature());
49
50
// Verify common fields
51
EXPECT_EQ(tx.getAccount(), accountValue);
52
EXPECT_EQ(tx.getSequence(), sequenceValue);
53
EXPECT_EQ(tx.getFee(), feeValue);
54
55
// Verify required fields
56
// Verify optional fields
57
}
58
59
// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
60
// and verify all fields match.
61
TEST
(TransactionsDIDDeleteTests, BuilderFromStTxRoundTrip)
62
{
63
// Generate a deterministic keypair for signing
64
auto
const
[publicKey, secretKey] =
65
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testDIDDeleteFromTx"
));
66
67
// Common transaction fields
68
auto
const
accountValue =
calcAccountID
(publicKey);
69
std::uint32_t
const
sequenceValue = 2;
70
auto
const
feeValue =
canonical_AMOUNT
();
71
72
// Transaction-specific field values
73
74
// Build an initial transaction
75
DIDDeleteBuilder
initialBuilder{
76
accountValue,
77
sequenceValue,
78
feeValue
79
};
80
81
82
auto
initialTx = initialBuilder.
build
(publicKey, secretKey);
83
84
// Create builder from existing STTx
85
DIDDeleteBuilder
builderFromTx{initialTx.getSTTx()};
86
87
auto
rebuiltTx = builderFromTx.
build
(publicKey, secretKey);
88
89
std::string
reason;
90
EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
91
92
// Verify common fields
93
EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
94
EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
95
EXPECT_EQ(rebuiltTx.getFee(), feeValue);
96
97
// Verify required fields
98
// Verify optional fields
99
}
100
101
// 3) Verify wrapper throws when constructed from wrong transaction type.
102
TEST
(TransactionsDIDDeleteTests, WrapperThrowsOnWrongTxType)
103
{
104
// Build a valid transaction of a different type
105
auto
const
[pk, sk] =
106
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongType"
));
107
auto
const
account =
calcAccountID
(pk);
108
109
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
110
auto
wrongTx = wrongBuilder.
build
(pk, sk);
111
112
EXPECT_THROW(
DIDDelete
{wrongTx.getSTTx()},
std::runtime_error
);
113
}
114
115
// 4) Verify builder throws when constructed from wrong transaction type.
116
TEST
(TransactionsDIDDeleteTests, BuilderThrowsOnWrongTxType)
117
{
118
// Build a valid transaction of a different type
119
auto
const
[pk, sk] =
120
generateKeyPair
(
KeyType::Secp256k1
,
generateSeed
(
"testWrongTypeBuilder"
));
121
auto
const
account =
calcAccountID
(pk);
122
123
AccountSetBuilder
wrongBuilder{account, 1,
canonical_AMOUNT
()};
124
auto
wrongTx = wrongBuilder.
build
(pk, sk);
125
126
EXPECT_THROW(
DIDDeleteBuilder
{wrongTx.getSTTx()},
std::runtime_error
);
127
}
128
129
130
}
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::DIDDeleteBuilder
Builder for DIDDelete transactions.
Definition
protocol_autogen/transactions/DIDDelete.h:59
xrpl::transactions::DIDDeleteBuilder::build
DIDDelete build(PublicKey const &publicKey, SecretKey const &secretKey)
Transaction-specific field setters.
Definition
protocol_autogen/transactions/DIDDelete.h:100
xrpl::transactions::DIDDelete
Transaction: DIDDelete.
Definition
protocol_autogen/transactions/DIDDelete.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::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
std::runtime_error
string
Generated by
1.17.0