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