Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyyan317 committed Jul 19, 2024
1 parent 7ff19a6 commit d35becd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/etl/NFTHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//==============================================================================

#include "data/DBHelpers.hpp"
#include "data/Types.hpp"

#include <fmt/core.h>
#include <xrpl/basics/base_uint.h>
Expand Down Expand Up @@ -55,7 +54,7 @@ getNFTsURIChanges(ripple::TxMeta const& txMeta, ripple::STTx const& sttx)

auto const tokenID = sttx.getFieldH256(ripple::sfNFTokenID);
// note: sfURI is optional, if it is absent, we will update the uri as empty string
return {{std::move(tx)}, NFTsData(tokenID, txMeta, sttx.getFieldVL(ripple::sfURI))};
return {{tx}, NFTsData(tokenID, txMeta, sttx.getFieldVL(ripple::sfURI))};
}

std::pair<std::vector<NFTTransactionsData>, std::optional<NFTsData>>
Expand Down
6 changes: 3 additions & 3 deletions src/etl/NFTHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
namespace etl {

/**
* @brief Get the NFT URI change data from a transaction
* @brief Get the NFT URI change data from a NFToken Modify transaction
*
* @param txMeta Transaction metadata
* @param sttx The transaction
* @return NFT URI change data as an optional NFTsData
* @return NFT URI change data as a pair of transactions and optional NFTsData
*/
std::optional<NFTsData>
std::pair<std::vector<NFTTransactionsData>, std::optional<NFTsData>>
getNFTsURIChanges(ripple::TxMeta const& txMeta, ripple::STTx const& sttx);

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/etl/NFTHelpersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ TEST_F(NFTHelpersTest, NFTAcceptSellerOfferCheckFail)
);
}

TEST_F(NFTHelpersTest, NFTAcceptSellerOfferNotInMeta)
{
auto const tx = CreateAcceptNFTSellerOfferTxWithMetadata(ACCOUNT, 1, 2, NFTID, OFFER_ID, PAGE_INDEX, true);
ripple::TxMeta txMeta(ripple::uint256(TX), 1, tx.metadata);
// inject a different offer id
txMeta.getNodes()[0].setFieldH256(ripple::sfLedgerIndex, ripple::uint256(PAGE_INDEX));

EXPECT_THROW(
etl::getNFTDataFromTx(txMeta, ripple::STTx(ripple::SerialIter{tx.transaction.data(), tx.transaction.size()})),
std::runtime_error
);
}

TEST_F(NFTHelpersTest, NFTAcceptSellerOfferZeroMetaNode)
{
auto const tx = CreateAcceptNFTSellerOfferTxWithMetadata(ACCOUNT2, 1, 2, NFTID, OFFER_ID, PAGE_INDEX, true);
Expand Down

0 comments on commit d35becd

Please sign in to comment.