1#include <test/app/invariants/InvariantsBase.h>
2#include <test/jtx/Account.h>
3#include <test/jtx/amount.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/unit_test/suite.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/InnerObjectFormats.h>
11#include <xrpl/protocol/Issue.h>
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/MPTIssue.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/SOTemplate.h>
16#include <xrpl/protocol/STAmount.h>
17#include <xrpl/protocol/STArray.h>
18#include <xrpl/protocol/STLedgerEntry.h>
19#include <xrpl/protocol/STObject.h>
20#include <xrpl/protocol/SeqProxy.h>
21#include <xrpl/protocol/SystemParameters.h>
22#include <xrpl/protocol/UintTypes.h>
23#include <xrpl/tx/ApplyContext.h>
45 {
"XRP net change of -1000000 doesn't match fee 0"},
46 {
"escrow specifies invalid amount"},
55 sleNew->setFieldAmount(sfAmount,
XRP(-1));
56 ac.view().insert(sleNew);
62 {
"XRP net change was positive: 100000000000000001"},
63 {
"escrow specifies invalid amount"},
75 ac.view().insert(sleNew);
81 {{
"escrow specifies invalid amount"}},
92 sleNew->setFieldAmount(sfAmount, amt);
93 ac.view().insert(sleNew);
99 {{
"escrow specifies invalid amount"}},
110 sleNew->setFieldAmount(sfAmount, amt);
111 ac.view().insert(sleNew);
117 {{
"escrow specifies invalid amount"}},
128 sleNew->setFieldAmount(sfAmount, amt);
129 ac.view().insert(sleNew);
135 {{
"escrow specifies invalid amount"}},
145 ac.view().insert(sleNew);
151 {{
"escrow specifies invalid amount"}},
161 ac.view().insert(sleNew);
167 {{
"escrow specifies invalid amount"}},
176 sleNew->setFieldU64(sfOutstandingAmount, 1);
177 sleNew->setFieldU64(sfLockedAmount, 10);
178 ac.view().insert(sleNew);
184 {{
"escrow specifies invalid amount"}},
194 ac.view().insert(sleNew);
200 {{
"escrow specifies invalid amount"}},
210 ac.view().insert(sleNew);
223 "0000000000000000000000000000000000000001FFFFFFFFFFFFFFFF00000000");
224 auto makeNFTokenIDs = [&firstNFTID](
unsigned int nftCount) {
230 for (
int i = 0; i < nftCount; ++i)
232 STObject newNFToken(*nfTokenTemplate, sfNFToken, [&nftID](
STObject&
object) {
233 object.setFieldH256(sfNFTokenID, nftID);
235 ret.
pushBack(std::move(newNFToken));
242 {{
"NFT page has invalid size"}},
245 nftPage->setFieldArray(sfNFTokens, makeNFTokenIDs(0));
247 ac.view().insert(nftPage);
252 {{
"NFT page has invalid size"}},
255 nftPage->setFieldArray(sfNFTokens, makeNFTokenIDs(33));
257 ac.view().insert(nftPage);
262 {{
"NFTs on page are not sorted"}},
264 STArray nfTokens = makeNFTokenIDs(2);
268 nftPage->setFieldArray(sfNFTokens, nfTokens);
270 ac.view().insert(nftPage);
275 {{
"NFT contains empty URI"}},
277 STArray nfTokens = makeNFTokenIDs(1);
278 nfTokens[0].setFieldVL(sfURI,
Blob{});
281 nftPage->setFieldArray(sfNFTokens, nfTokens);
283 ac.view().insert(nftPage);
288 {{
"NFT page is improperly linked"}},
291 nftPage->setFieldArray(sfNFTokens, makeNFTokenIDs(1));
294 ac.view().insert(nftPage);
299 {{
"NFT page is improperly linked"}},
302 nftPage->setFieldArray(sfNFTokens, makeNFTokenIDs(1));
305 ac.view().insert(nftPage);
310 {{
"NFT page is improperly linked"}},
313 nftPage->setFieldArray(sfNFTokens, makeNFTokenIDs(1));
314 nftPage->setFieldH256(sfNextPageMin, nftPage->key());
316 ac.view().insert(nftPage);
321 {{
"NFT page is improperly linked"}},
323 STArray nfTokens = makeNFTokenIDs(1);
326 nftPage->setFieldArray(sfNFTokens, nfTokens);
329 ac.view().insert(nftPage);
334 {{
"NFT found in incorrect page"}},
336 STArray nfTokens = makeNFTokenIDs(2);
339 nftPage->setFieldArray(sfNFTokens, nfTokens);
341 ac.view().insert(nftPage);
TestcaseT testcase
Memberspace for declaring test cases.
State information when applying a tx.
A currency issued by an account.
constexpr MPTID const & getMptID() const
Defines the fields and their attributes within a STObject.
void pushBack(STObject const &object)
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
void doInvariantCheck(std::vector< std::string > const &expectLogs, Precheck const &precheck, XRPAmount fee=XRPAmount{}, STTx tx=STTx{ttACCOUNT_SET, [](STObject &) {}}, std::initializer_list< TER > ters={tecINVARIANT_FAILED, tefINVARIANT_FAILED}, Preclose const &preclose={}, TxAccount setTxAccount=TxAccount::None, std::source_location const &loc=std::source_location::current(), TER initialResult=tesSUCCESS)
Run a specific test case to put the ledger into a state that will be detected by an invariant.
void testNFTokenPageInvariants()
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Keylet nftokenPage(Keylet const &k, UInt256 const &token)
Keylet nftokenPageMin(AccountID const &owner)
NFT page keylets.
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
XrpT const XRP
Converts to XRP Issue or STAmount.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
std::vector< unsigned char > Blob
Storage for linear binary data.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
constexpr XRPAmount kInitialXrp
Configure the native currency.