Skip to content

Commit

Permalink
clang
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed Oct 16, 2023
1 parent 3669793 commit bb914ed
Showing 1 changed file with 83 additions and 67 deletions.
150 changes: 83 additions & 67 deletions src/test/app/NFToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6806,26 +6806,27 @@ class NFToken0_test : public beast::unit_test::suite
using namespace test::jtx;

// Lambda that mints an NFT and then creates a sell offer
auto mintAndCreateSellOffer = [](test::jtx::Env& env, test::jtx::Account const& act, STAmount const amt) -> std::tuple<uint256, uint256> {
auto mintAndCreateSellOffer =
[](test::jtx::Env& env,
test::jtx::Account const& act,
STAmount const amt) -> std::tuple<uint256, uint256> {
// act mints a NFT
uint256 const nftId{
token::getNextID(env, act, 0u, tfTransferable)};
uint256 const nftId{token::getNextID(env, act, 0u, tfTransferable)};
env(token::mint(act, 0u), txflags(tfTransferable));
env.close();
env.close();

// act sells NFT for 0 XRP
uint256 const sellOfferIndex =
keylet::nftoffer(act, env.seq(act)).key;
env(token::createOffer(act, nftId, amt),
txflags(tfSellNFToken));
env(token::createOffer(act, nftId, amt), txflags(tfSellNFToken));
env.close();

return {nftId, sellOfferIndex};
};

// Test the behavior when the seller accepts a buy offer
// The behavior should not change regardless whether fixNFTokenReserve
// is enabled, since the ledger is able to guard against
// is enabled, since the ledger is able to guard against
// free NFTokenPages when buy offer is accepted.
{
Account const alice{"alice"};
Expand All @@ -6851,18 +6852,18 @@ class NFToken0_test : public beast::unit_test::suite
env.close();

// Bob makes a buy offer for 1 XRP
auto const buyOfferIndex =
keylet::nftoffer(bob, env.seq(bob)).key;
auto const buyOfferIndex = keylet::nftoffer(bob, env.seq(bob)).key;
env(token::createOffer(bob, nftId, XRP(1)), token::owner(alice));
env.close();

// accept the buy offer fails because bob doesn't have the spendable 1XRP
// that he put up the offerfor
env(token::acceptBuyOffer(alice, buyOfferIndex), ter(tecINSUFFICIENT_FUNDS));
// accept the buy offer fails because bob doesn't have the spendable
// 1XRP that he put up the offerfor
env(token::acceptBuyOffer(alice, buyOfferIndex),
ter(tecINSUFFICIENT_FUNDS));
env.close();

// send Bob 1XRP
env(pay(env.master, bob, XRP(1)));
env(pay(env.master, bob, XRP(1)));
env.close();

// Now bob can buy the offer
Expand All @@ -6871,8 +6872,8 @@ class NFToken0_test : public beast::unit_test::suite
}

// Test the behaviors when the buyer makes an accept offer, both before
// and after enabling the amendment. Exercises the precise number of reserve in drops
// that's required to accept the offer
// and after enabling the amendment. Exercises the precise number of
// reserve in drops that's required to accept the offer
{
Account const alice{"alice"};
Account const bob{"bob"};
Expand All @@ -6889,7 +6890,8 @@ class NFToken0_test : public beast::unit_test::suite
env.close();

// alice mints an NFT and create a sell offer for 0 XRP
auto const [nftId, sellOfferIndex] = mintAndCreateSellOffer(env, alice, XRP(0));
auto const [nftId, sellOfferIndex] =
mintAndCreateSellOffer(env, alice, XRP(0));

// Bob owns no object
BEAST_EXPECT(ownerCount(env, bob) == 0);
Expand Down Expand Up @@ -6922,8 +6924,8 @@ class NFToken0_test : public beast::unit_test::suite
ter(tecINSUFFICIENT_RESERVE));
env.close();

// after prev transaction, Bob owns 199,999,990 drops due to burnt
// tx fee
// after prev transaction, Bob owns 199,999,990 drops due to
// burnt tx fee

BEAST_EXPECT(ownerCount(env, bob) == 0);

Expand Down Expand Up @@ -6971,21 +6973,27 @@ class NFToken0_test : public beast::unit_test::suite
if (!features[fixNFTokenReserve])
{
// Bob can accept many NFTs without having a single reserve!
for (size_t i = 0; i < 200; i++){
for (size_t i = 0; i < 200; i++)
{
// alice mints an NFT and creates a sell offer for 0 XRP
auto const [nftId, sellOfferIndex] = mintAndCreateSellOffer(env, alice, XRP(0));
auto const [nftId, sellOfferIndex] =
mintAndCreateSellOffer(env, alice, XRP(0));

// Bob is able to accept the offer
env(token::acceptSellOffer(bob, sellOfferIndex));
env.close();
}
}
else{
// alice mints the first NFT and creates a sell offer for 0 XRP
auto const [nftId1, sellOfferIndex1] = mintAndCreateSellOffer(env, alice, XRP(0));
else
{
// alice mints the first NFT and creates a sell offer for 0 XRP
auto const [nftId1, sellOfferIndex1] =
mintAndCreateSellOffer(env, alice, XRP(0));

// Bob cannot accept this offer because he doesn't have the reserve for the NFT
env(token::acceptSellOffer(bob, sellOfferIndex1), ter(tecINSUFFICIENT_RESERVE));
// Bob cannot accept this offer because he doesn't have the
// reserve for the NFT
env(token::acceptSellOffer(bob, sellOfferIndex1),
ter(tecINSUFFICIENT_RESERVE));
env.close();

// Give bob enough reserve
Expand All @@ -6997,30 +7005,38 @@ class NFToken0_test : public beast::unit_test::suite
env.close();
BEAST_EXPECT(ownerCount(env, bob) == 1);

// alice now mints 31 more NFTs and creates an offer for each NFT
for (size_t i = 0; i < 31; i++){
// alice now mints 31 more NFTs and creates an offer for each
// NFT
for (size_t i = 0; i < 31; i++)
{
// alice mints an NFT and creates a sell offer for 0 XRP
auto const [nftId, sellOfferIndex] = mintAndCreateSellOffer(env, alice, XRP(0));
auto const [nftId, sellOfferIndex] =
mintAndCreateSellOffer(env, alice, XRP(0));

// Bob can accept the offer because the new NFT is stored in an existing NFTokenPage
// so no new reserve is requried
// Bob can accept the offer because the new NFT is stored in
// an existing NFTokenPage so no new reserve is requried
env(token::acceptSellOffer(bob, sellOfferIndex));
env.close();
}
BEAST_EXPECT(ownerCount(env, bob) == 1);

// alice now mints the 33rd NFT and creates an sell offer for 0 XRP
auto const [nftId33, sellOfferIndex33] = mintAndCreateSellOffer(env, alice, XRP(0));
// alice now mints the 33rd NFT and creates an sell offer for 0
// XRP
auto const [nftId33, sellOfferIndex33] =
mintAndCreateSellOffer(env, alice, XRP(0));

// Bob fails to accept this NFT because he does not have enough reserve for a new NFTokenPage
env(token::acceptSellOffer(bob, sellOfferIndex33), ter(tecINSUFFICIENT_RESERVE));
// Bob fails to accept this NFT because he does not have enough
// reserve for a new NFTokenPage
env(token::acceptSellOffer(bob, sellOfferIndex33),
ter(tecINSUFFICIENT_RESERVE));
env.close();

// Send bob incremental reserve
env(pay(env.master, bob, drops(incReserve)));
env.close();

// Bob now has enough reserve to accept the offer which causes him to own one more NFTokenPage
// Bob now has enough reserve to accept the offer which causes
// him to own one more NFTokenPage
env(token::acceptSellOffer(bob, sellOfferIndex33));
env.close();
BEAST_EXPECT(ownerCount(env, bob) == 2);
Expand All @@ -7031,36 +7047,36 @@ class NFToken0_test : public beast::unit_test::suite
void
testWithFeats(FeatureBitset features)
{
// testEnabled(features);
// testMintReserve(features);
// testMintMaxTokens(features);
// testMintInvalid(features);
// testBurnInvalid(features);
// testCreateOfferInvalid(features);
// testCancelOfferInvalid(features);
// testAcceptOfferInvalid(features);
// testMintFlagBurnable(features);
// testMintFlagOnlyXRP(features);
// testMintFlagCreateTrustLine(features);
// testMintFlagTransferable(features);
// testMintTransferFee(features);
// testMintTaxon(features);
// testMintURI(features);
// testCreateOfferDestination(features);
// testCreateOfferDestinationDisallowIncoming(features);
// testCreateOfferExpiration(features);
// testCancelOffers(features);
// testCancelTooManyOffers(features);
// testBrokeredAccept(features);
// testNFTokenOfferOwner(features);
// testNFTokenWithTickets(features);
// testNFTokenDeleteAccount(features);
// testNftXxxOffers(features);
// testFixNFTokenNegOffer(features);
// testIOUWithTransferFee(features);
// testBrokeredSaleToSelf(features);
// testFixNFTokenRemint(features);
// testTxJsonMetaFields(features);
testEnabled(features);
testMintReserve(features);
testMintMaxTokens(features);
testMintInvalid(features);
testBurnInvalid(features);
testCreateOfferInvalid(features);
testCancelOfferInvalid(features);
testAcceptOfferInvalid(features);
testMintFlagBurnable(features);
testMintFlagOnlyXRP(features);
testMintFlagCreateTrustLine(features);
testMintFlagTransferable(features);
testMintTransferFee(features);
testMintTaxon(features);
testMintURI(features);
testCreateOfferDestination(features);
testCreateOfferDestinationDisallowIncoming(features);
testCreateOfferExpiration(features);
testCancelOffers(features);
testCancelTooManyOffers(features);
testBrokeredAccept(features);
testNFTokenOfferOwner(features);
testNFTokenWithTickets(features);
testNFTokenDeleteAccount(features);
testNftXxxOffers(features);
testFixNFTokenNegOffer(features);
testIOUWithTransferFee(features);
testBrokeredSaleToSelf(features);
testFixNFTokenRemint(features);
testTxJsonMetaFields(features);
testFixNFTokenBuyerReserve(features);
}

Expand Down

0 comments on commit bb914ed

Please sign in to comment.