fix: MPT test object producing ASAN error (#2406)

Plus some driveby cleanup of incorrect placement of `constexpr`
This commit is contained in:
Alex Kremer
2025-08-07 18:57:26 +01:00
committed by GitHub
parent e4d0c1ca48
commit 87565b685a
5 changed files with 22 additions and 11 deletions

View File

@@ -18,6 +18,7 @@
//============================================================================== //==============================================================================
#include "data/DBHelpers.hpp" #include "data/DBHelpers.hpp"
#include "util/Assert.hpp"
#include <ripple/protocol/STBase.h> #include <ripple/protocol/STBase.h>
#include <ripple/protocol/STTx.h> #include <ripple/protocol/STTx.h>
@@ -71,6 +72,9 @@ getMPTHolderFromTx(ripple::TxMeta const& txMeta, ripple::STTx const& sttx)
std::optional<MPTHolderData> std::optional<MPTHolderData>
getMPTHolderFromObj(std::string const& key, std::string const& blob) getMPTHolderFromObj(std::string const& key, std::string const& blob)
{ {
// https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0033-multi-purpose-tokens#2121-mptoken-ledger-identifier
ASSERT(key.size() == ripple::uint256::size(), "The size of the key is expected to fit uint256 exactly");
ripple::STLedgerEntry const sle = ripple::STLedgerEntry const sle =
ripple::STLedgerEntry(ripple::SerialIter{blob.data(), blob.size()}, ripple::uint256::fromVoid(key.data())); ripple::STLedgerEntry(ripple::SerialIter{blob.data(), blob.size()}, ripple::uint256::fromVoid(key.data()));

View File

@@ -37,6 +37,7 @@
#include <xrpl/protocol/Serializer.h> #include <xrpl/protocol/Serializer.h>
#include <xrpl/protocol/TxFormats.h> #include <xrpl/protocol/TxFormats.h>
#include <xrpl/protocol/TxMeta.h> #include <xrpl/protocol/TxMeta.h>
#include <xrpl/protocol/digest.h>
#include <optional> #include <optional>
#include <string> #include <string>
@@ -152,7 +153,7 @@ createObjectWithTwoNFTs()
// key is a token made up from owner's account ID followed by unused (in Clio) value described here: // key is a token made up from owner's account ID followed by unused (in Clio) value described here:
// https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0020-non-fungible-tokens#tokenpage-id-format // https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0020-non-fungible-tokens#tokenpage-id-format
auto constexpr kEXTRA_BYTES = "000000000000"; constexpr auto kEXTRA_BYTES = "000000000000";
auto const key = std::string(std::begin(account), std::end(account)) + kEXTRA_BYTES; auto const key = std::string(std::begin(account), std::end(account)) + kEXTRA_BYTES;
return { return {
@@ -173,11 +174,17 @@ createObjectWithMPT()
constexpr auto kACCOUNT = "rM2AGCCCRb373FRuD8wHyUwUsh2dV4BW5Q"; constexpr auto kACCOUNT = "rM2AGCCCRb373FRuD8wHyUwUsh2dV4BW5Q";
auto const account = getAccountIdWithString(kACCOUNT); auto const account = getAccountIdWithString(kACCOUNT);
auto const mptokenObject = createMpTokenObject(kACCOUNT, ripple::makeMptID(2, getAccountIdWithString(kACCOUNT))); auto const mptID = ripple::makeMptID(2, getAccountIdWithString(kACCOUNT));
auto const mptokenObject = createMpTokenObject(kACCOUNT, mptID);
// key is a token made up from several fields described here:
// https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0033-multi-purpose-tokens#2121-mptoken-ledger-identifier
constexpr auto kSPACE_KEY = 0x007F;
auto const keySha512Half = ripple::sha512Half(kSPACE_KEY, mptID, account);
return { return {
.key = {}, .key = {},
.keyRaw = std::string(reinterpret_cast<char const*>(account.data()), ripple::AccountID::size()), .keyRaw = std::string(std::begin(keySha512Half), std::end(keySha512Half)),
.data = {}, .data = {},
.dataRaw = std::string( .dataRaw = std::string(
static_cast<char const*>(mptokenObject.getSerializer().getDataPtr()), static_cast<char const*>(mptokenObject.getSerializer().getDataPtr()),

View File

@@ -223,7 +223,7 @@ class MigrationCassandraManagerTxTableTest : public MigrationCassandraSimpleTest
TEST_F(MigrationCassandraManagerTxTableTest, MigrateExampleTransactionsMigrator) TEST_F(MigrationCassandraManagerTxTableTest, MigrateExampleTransactionsMigrator)
{ {
auto constexpr kTRANSACTIONS_MIGRATOR_NAME = "ExampleTransactionsMigrator"; constexpr auto kTRANSACTIONS_MIGRATOR_NAME = "ExampleTransactionsMigrator";
EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kTRANSACTIONS_MIGRATOR_NAME), MigratorStatus::NotMigrated); EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kTRANSACTIONS_MIGRATOR_NAME), MigratorStatus::NotMigrated);
ExampleTransactionsMigrator::count = 0; ExampleTransactionsMigrator::count = 0;
@@ -274,7 +274,7 @@ class MigrationCassandraManagerObjectsTableTest : public MigrationCassandraSimpl
TEST_F(MigrationCassandraManagerObjectsTableTest, MigrateExampleObjectsMigrator) TEST_F(MigrationCassandraManagerObjectsTableTest, MigrateExampleObjectsMigrator)
{ {
auto constexpr kOBJECTS_MIGRATOR_NAME = "ExampleObjectsMigrator"; constexpr auto kOBJECTS_MIGRATOR_NAME = "ExampleObjectsMigrator";
EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kOBJECTS_MIGRATOR_NAME), MigratorStatus::NotMigrated); EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kOBJECTS_MIGRATOR_NAME), MigratorStatus::NotMigrated);
testMigrationManager_->runMigration(kOBJECTS_MIGRATOR_NAME); testMigrationManager_->runMigration(kOBJECTS_MIGRATOR_NAME);
@@ -302,7 +302,7 @@ class MigrationCassandraManagerLedgerTableTest : public MigrationCassandraSimple
TEST_F(MigrationCassandraManagerLedgerTableTest, MigrateExampleLedgerMigrator) TEST_F(MigrationCassandraManagerLedgerTableTest, MigrateExampleLedgerMigrator)
{ {
auto constexpr kHEADER_MIGRATOR_NAME = "ExampleLedgerMigrator"; constexpr auto kHEADER_MIGRATOR_NAME = "ExampleLedgerMigrator";
EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kHEADER_MIGRATOR_NAME), MigratorStatus::NotMigrated); EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kHEADER_MIGRATOR_NAME), MigratorStatus::NotMigrated);
testMigrationManager_->runMigration(kHEADER_MIGRATOR_NAME); testMigrationManager_->runMigration(kHEADER_MIGRATOR_NAME);
@@ -334,7 +334,7 @@ class MigrationCassandraManagerDropTableTest : public MigrationCassandraSimpleTe
TEST_F(MigrationCassandraManagerDropTableTest, MigrateDropTableMigrator) TEST_F(MigrationCassandraManagerDropTableTest, MigrateDropTableMigrator)
{ {
auto constexpr kDROP_TABLE_MIGRATOR_NAME = "ExampleDropTableMigrator"; constexpr auto kDROP_TABLE_MIGRATOR_NAME = "ExampleDropTableMigrator";
EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kDROP_TABLE_MIGRATOR_NAME), MigratorStatus::NotMigrated); EXPECT_EQ(testMigrationManager_->getMigratorStatusByName(kDROP_TABLE_MIGRATOR_NAME), MigratorStatus::NotMigrated);
auto const beforeDropSize = auto const beforeDropSize =

View File

@@ -478,7 +478,7 @@ TEST_F(NFTHelpersTest, NFTDataFromLedgerObject)
// key is a token made up from owner's account ID followed by unused (in Clio) value described here: // key is a token made up from owner's account ID followed by unused (in Clio) value described here:
// https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0020-non-fungible-tokens#tokenpage-id-format // https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0020-non-fungible-tokens#tokenpage-id-format
auto constexpr kEXTRA_BYTES = "000000000000"; constexpr auto kEXTRA_BYTES = "000000000000";
auto const key = std::string(std::begin(account), std::end(account)) + kEXTRA_BYTES; auto const key = std::string(std::begin(account), std::end(account)) + kEXTRA_BYTES;
uint32_t constexpr kSEQ{5}; uint32_t constexpr kSEQ{5};

View File

@@ -419,7 +419,7 @@ TEST_F(RPCHelpersTest, DeliverMaxAliasV1)
TEST_F(RPCHelpersTest, DeliverMaxAliasV2) TEST_F(RPCHelpersTest, DeliverMaxAliasV2)
{ {
auto constexpr kJSON = R"JSON({ constexpr auto kJSON = R"JSON({
"TransactionType": "Payment", "TransactionType": "Payment",
"Amount": { "Amount": {
"test": "test" "test": "test"
@@ -522,7 +522,7 @@ TEST_F(RPCHelpersTest, TransactionAndMetadataBinaryJsonV2)
TEST_F(RPCHelpersTest, ParseIssue) TEST_F(RPCHelpersTest, ParseIssue)
{ {
auto constexpr kJSON = R"JSON({ constexpr auto kJSON = R"JSON({
"issuer": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "issuer": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
"currency": "JPY" "currency": "JPY"
})JSON"; })JSON";
@@ -536,7 +536,7 @@ TEST_F(RPCHelpersTest, ParseIssue)
EXPECT_THROW(parseIssue(boost::json::parse(R"JSON({"currency": "XRP2"})JSON").as_object()), std::runtime_error); EXPECT_THROW(parseIssue(boost::json::parse(R"JSON({"currency": "XRP2"})JSON").as_object()), std::runtime_error);
auto constexpr kJSON2 = R"JSON({ constexpr auto kJSON2 = R"JSON({
"issuer": "abcd", "issuer": "abcd",
"currency": "JPY" "currency": "JPY"
})JSON"; })JSON";