mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-08 03:07:13 +00:00
196 lines
6.0 KiB
C++
196 lines
6.0 KiB
C++
// Auto-generated unit tests for transaction NFTokenBurn
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <protocol_autogen/TestHelpers.h>
|
|
|
|
#include <xrpl/protocol/SecretKey.h>
|
|
#include <xrpl/protocol/Seed.h>
|
|
#include <xrpl/protocol/STTx.h>
|
|
#include <xrpl/protocol_autogen/transactions/NFTokenBurn.h>
|
|
#include <xrpl/protocol_autogen/transactions/AccountSet.h>
|
|
|
|
#include <string>
|
|
|
|
namespace xrpl::transactions {
|
|
|
|
// 1 & 4) Set fields via builder setters, build, then read them back via
|
|
// wrapper getters. After build(), validate() should succeed.
|
|
TEST(TransactionsNFTokenBurnTests, BuilderSettersRoundTrip)
|
|
{
|
|
// Generate a deterministic keypair for signing
|
|
auto const [publicKey, secretKey] =
|
|
generateKeyPair(KeyType::Secp256k1, generateSeed("testNFTokenBurn"));
|
|
|
|
// Common transaction fields
|
|
auto const accountValue = calcAccountID(publicKey);
|
|
std::uint32_t const sequenceValue = 1;
|
|
auto const feeValue = canonical_AMOUNT();
|
|
|
|
// Transaction-specific field values
|
|
auto const nFTokenIDValue = canonical_UINT256();
|
|
auto const ownerValue = canonical_ACCOUNT();
|
|
|
|
NFTokenBurnBuilder builder{
|
|
accountValue,
|
|
nFTokenIDValue,
|
|
sequenceValue,
|
|
feeValue
|
|
};
|
|
|
|
// Set optional fields
|
|
builder.setOwner(ownerValue);
|
|
|
|
auto tx = builder.build(publicKey, secretKey);
|
|
|
|
std::string reason;
|
|
EXPECT_TRUE(tx.validate(reason)) << reason;
|
|
|
|
// Verify signing was applied
|
|
EXPECT_FALSE(tx.getSigningPubKey().empty());
|
|
EXPECT_TRUE(tx.hasTxnSignature());
|
|
|
|
// Verify common fields
|
|
EXPECT_EQ(tx.getAccount(), accountValue);
|
|
EXPECT_EQ(tx.getSequence(), sequenceValue);
|
|
EXPECT_EQ(tx.getFee(), feeValue);
|
|
|
|
// Verify required fields
|
|
{
|
|
auto const& expected = nFTokenIDValue;
|
|
auto const actual = tx.getNFTokenID();
|
|
expectEqualField(expected, actual, "sfNFTokenID");
|
|
}
|
|
|
|
// Verify optional fields
|
|
{
|
|
auto const& expected = ownerValue;
|
|
auto const actualOpt = tx.getOwner();
|
|
ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfOwner should be present";
|
|
expectEqualField(expected, *actualOpt, "sfOwner");
|
|
EXPECT_TRUE(tx.hasOwner());
|
|
}
|
|
|
|
}
|
|
|
|
// 2 & 4) Start from an STTx, construct a builder from it, build a new wrapper,
|
|
// and verify all fields match.
|
|
TEST(TransactionsNFTokenBurnTests, BuilderFromStTxRoundTrip)
|
|
{
|
|
// Generate a deterministic keypair for signing
|
|
auto const [publicKey, secretKey] =
|
|
generateKeyPair(KeyType::Secp256k1, generateSeed("testNFTokenBurnFromTx"));
|
|
|
|
// Common transaction fields
|
|
auto const accountValue = calcAccountID(publicKey);
|
|
std::uint32_t const sequenceValue = 2;
|
|
auto const feeValue = canonical_AMOUNT();
|
|
|
|
// Transaction-specific field values
|
|
auto const nFTokenIDValue = canonical_UINT256();
|
|
auto const ownerValue = canonical_ACCOUNT();
|
|
|
|
// Build an initial transaction
|
|
NFTokenBurnBuilder initialBuilder{
|
|
accountValue,
|
|
nFTokenIDValue,
|
|
sequenceValue,
|
|
feeValue
|
|
};
|
|
|
|
initialBuilder.setOwner(ownerValue);
|
|
|
|
auto initialTx = initialBuilder.build(publicKey, secretKey);
|
|
|
|
// Create builder from existing STTx
|
|
NFTokenBurnBuilder builderFromTx{initialTx.getSTTx()};
|
|
|
|
auto rebuiltTx = builderFromTx.build(publicKey, secretKey);
|
|
|
|
std::string reason;
|
|
EXPECT_TRUE(rebuiltTx.validate(reason)) << reason;
|
|
|
|
// Verify common fields
|
|
EXPECT_EQ(rebuiltTx.getAccount(), accountValue);
|
|
EXPECT_EQ(rebuiltTx.getSequence(), sequenceValue);
|
|
EXPECT_EQ(rebuiltTx.getFee(), feeValue);
|
|
|
|
// Verify required fields
|
|
{
|
|
auto const& expected = nFTokenIDValue;
|
|
auto const actual = rebuiltTx.getNFTokenID();
|
|
expectEqualField(expected, actual, "sfNFTokenID");
|
|
}
|
|
|
|
// Verify optional fields
|
|
{
|
|
auto const& expected = ownerValue;
|
|
auto const actualOpt = rebuiltTx.getOwner();
|
|
ASSERT_TRUE(actualOpt.has_value()) << "Optional field sfOwner should be present";
|
|
expectEqualField(expected, *actualOpt, "sfOwner");
|
|
}
|
|
|
|
}
|
|
|
|
// 3) Verify wrapper throws when constructed from wrong transaction type.
|
|
TEST(TransactionsNFTokenBurnTests, WrapperThrowsOnWrongTxType)
|
|
{
|
|
// Build a valid transaction of a different type
|
|
auto const [pk, sk] =
|
|
generateKeyPair(KeyType::Secp256k1, generateSeed("testWrongType"));
|
|
auto const account = calcAccountID(pk);
|
|
|
|
AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
|
|
auto wrongTx = wrongBuilder.build(pk, sk);
|
|
|
|
EXPECT_THROW(NFTokenBurn{wrongTx.getSTTx()}, std::runtime_error);
|
|
}
|
|
|
|
// 4) Verify builder throws when constructed from wrong transaction type.
|
|
TEST(TransactionsNFTokenBurnTests, BuilderThrowsOnWrongTxType)
|
|
{
|
|
// Build a valid transaction of a different type
|
|
auto const [pk, sk] =
|
|
generateKeyPair(KeyType::Secp256k1, generateSeed("testWrongTypeBuilder"));
|
|
auto const account = calcAccountID(pk);
|
|
|
|
AccountSetBuilder wrongBuilder{account, 1, canonical_AMOUNT()};
|
|
auto wrongTx = wrongBuilder.build(pk, sk);
|
|
|
|
EXPECT_THROW(NFTokenBurnBuilder{wrongTx.getSTTx()}, std::runtime_error);
|
|
}
|
|
|
|
// 5) Build with only required fields and verify optional fields return nullopt.
|
|
TEST(TransactionsNFTokenBurnTests, OptionalFieldsReturnNullopt)
|
|
{
|
|
// Generate a deterministic keypair for signing
|
|
auto const [publicKey, secretKey] =
|
|
generateKeyPair(KeyType::Secp256k1, generateSeed("testNFTokenBurnNullopt"));
|
|
|
|
// Common transaction fields
|
|
auto const accountValue = calcAccountID(publicKey);
|
|
std::uint32_t const sequenceValue = 3;
|
|
auto const feeValue = canonical_AMOUNT();
|
|
|
|
// Transaction-specific required field values
|
|
auto const nFTokenIDValue = canonical_UINT256();
|
|
|
|
NFTokenBurnBuilder builder{
|
|
accountValue,
|
|
nFTokenIDValue,
|
|
sequenceValue,
|
|
feeValue
|
|
};
|
|
|
|
// Do NOT set optional fields
|
|
|
|
auto tx = builder.build(publicKey, secretKey);
|
|
|
|
// Verify optional fields are not present
|
|
EXPECT_FALSE(tx.hasOwner());
|
|
EXPECT_FALSE(tx.getOwner().has_value());
|
|
}
|
|
|
|
}
|