4#include <gtest/gtest.h>
6#include <protocol_autogen/TestHelpers.h>
8#include <xrpl/protocol/SecretKey.h>
9#include <xrpl/protocol/Seed.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol_autogen/transactions/SetRegularKey.h>
12#include <xrpl/protocol_autogen/transactions/AccountSet.h>
20TEST(TransactionsSetRegularKeyTests, BuilderSettersRoundTrip)
23 auto const [publicKey, secretKey] =
41 builder.setRegularKey(regularKeyValue);
43 auto tx = builder.build(publicKey, secretKey);
46 EXPECT_TRUE(tx.validate(reason)) << reason;
49 EXPECT_FALSE(tx.getSigningPubKey().empty());
50 EXPECT_TRUE(tx.hasTxnSignature());
53 EXPECT_EQ(tx.getAccount(), accountValue);
54 EXPECT_EQ(tx.getSequence(), sequenceValue);
55 EXPECT_EQ(tx.getFee(), feeValue);
60 auto const& expected = regularKeyValue;
61 auto const actualOpt = tx.getRegularKey();
62 ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfRegularKey should be present";
64 EXPECT_TRUE(tx.hasRegularKey());
71TEST(TransactionsSetRegularKeyTests, BuilderFromStTxRoundTrip)
74 auto const [publicKey, secretKey] =
92 initialBuilder.setRegularKey(regularKeyValue);
94 auto initialTx = initialBuilder.build(publicKey, secretKey);
99 auto rebuiltTx = builderFromTx.
build(publicKey, secretKey);
102 EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
105 EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
106 EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
107 EXPECT_EQ(rebuiltTx.getFee(), feeValue);
112 auto const& expected = regularKeyValue;
113 auto const actualOpt = rebuiltTx.getRegularKey();
114 ASSERT_TRUE(actualOpt.has_value()) <<
"Optional field sfRegularKey should be present";
121TEST(TransactionsSetRegularKeyTests, WrapperThrowsOnWrongTxType)
124 auto const [pk, sk] =
129 auto wrongTx = wrongBuilder.build(pk, sk);
135TEST(TransactionsSetRegularKeyTests, BuilderThrowsOnWrongTxType)
138 auto const [pk, sk] =
143 auto wrongTx = wrongBuilder.build(pk, sk);
149TEST(TransactionsSetRegularKeyTests, OptionalFieldsReturnNullopt)
152 auto const [publicKey, secretKey] =
170 auto tx = builder.build(publicKey, secretKey);
173 EXPECT_FALSE(tx.hasRegularKey());
174 EXPECT_FALSE(tx.getRegularKey().has_value());
Builder for AccountSet transactions.
Builder for SetRegularKey transactions.
SetRegularKey build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the SetRegularKey wrapper.
Transaction: SetRegularKey.
std::shared_ptr< STTx const > getSTTx() const
Get the underlying STTx object.
TEST(TransactionsAccountDeleteTests, BuilderSettersRoundTrip)
AccountValue canonical_ACCOUNT()
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
AmountValue canonical_AMOUNT()
AccountID calcAccountID(PublicKey const &pk)
void expectEqualField(T const &expected, T const &actual, char const *fieldName)