2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h>
7#include <test/jtx/mpt.h>
8#include <test/jtx/offer.h>
9#include <test/jtx/owners.h>
10#include <test/jtx/pay.h>
11#include <test/jtx/tags.h>
12#include <test/jtx/ter.h>
14#include <xrpl/beast/unit_test/suite.h>
15#include <xrpl/protocol/Feature.h>
16#include <xrpl/protocol/Protocol.h>
17#include <xrpl/protocol/TER.h>
30 Env env(*
this, features);
32 auto const gw =
Account(
"gateway");
34 env.
fund(
XRP(100'000'000), gw,
"alice",
"bob",
"carol",
"dan");
36 MPTTester({.env = env, .issuer = gw, .holders = {
"bob",
"dan"}, .maxAmt = 2});
37 env(
pay(gw,
"bob", usd(1)));
38 env(
pay(gw,
"dan", usd(1)));
44 env(
offer(
"alice", usd(1'000),
XRP(1'000)));
54 env(
offer(
"carol", usd(1'000),
XRP(1'000)));
69 Env env(*
this, features);
71 auto const gw =
Account(
"gateway");
73 int const maxConsumed = 1'000;
75 env.
fund(
XRP(100'000'000), gw,
"alice",
"bob",
"carol");
76 int const bobsOfferCount = maxConsumed + 150;
78 MPTTester({.env = env, .issuer = gw, .holders = {
"bob"}, .maxAmt = bobsOfferCount});
79 env(
pay(gw,
"bob", usd(bobsOfferCount)));
81 nOffers(env, bobsOfferCount,
"bob",
XRP(1), usd(1));
85 env(
offer(
"alice", usd(bobsOfferCount),
XRP(bobsOfferCount)));
93 env(
offer(
"carol", usd(1'000),
XRP(1'000)));
103 testcase(
"Step And Crossing Limit");
106 Env env(*
this, features);
108 auto const gw =
Account(
"gateway");
110 env.
fund(
XRP(100'000'000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
112 int const maxConsumed = 1'000;
113 int const evitaOfferCount{maxConsumed + 49};
118 .holders = {
"bob",
"alice",
"carol",
"evita"},
119 .maxAmt = 2'000 + evitaOfferCount + 1});
121 env(
pay(gw,
"alice", usd(1000)));
122 env(
pay(gw,
"carol", usd(1)));
123 env(
pay(gw,
"evita", usd(evitaOfferCount + 1)));
127 int const carolOfferCount{700};
129 nOffers(env, carolOfferCount,
"carol",
XRP(1), usd(1));
130 nOffers(env, evitaOfferCount,
"evita",
XRP(1), usd(1));
135 env(
offer(
"bob", usd(1000),
XRP(1000)));
147 env(
offer(
"dan", usd(maxConsumed + 50),
XRP(maxConsumed + 50)));
173 auto const gw =
Account(
"gateway");
174 auto const alice =
Account(
"alice");
175 auto const bob =
Account(
"bob");
176 auto const carol =
Account(
"carol");
191 auto test = [&](
auto&& issue1,
auto&& issue2) {
192 Env env(*
this, features);
194 env.
fund(
XRP(100'000'000), gw, alice, bob, carol);
196 auto const usd = issue1(
200 .holders = {alice, carol},
202 auto const eur = issue2(
209 env(
pay(gw, alice, usd(4'000)));
210 env(
pay(gw, carol, usd(3)));
220 nOffers(env, 1, alice, eur(500), usd(500));
261 env(
pay(gw, bob, eur(2'000)));
263 env(
offer(bob, usd(4'000), eur(4'000)));
273 auto const numAOffers = 2'000 + 100 + 1'000 + 1 - ((2 * 100) + (2 * 199) + 1 + 1);
282 auto test = [&](
auto&& issue1,
auto&& issue2) {
283 Env env(*
this, features);
285 env.
fund(
XRP(100'000'000), gw, alice, bob, carol);
287 auto const usd = issue1(
291 .holders = {alice, carol},
293 auto const eur = issue2(
300 env(
pay(gw, alice, usd(4'000)));
301 env(
pay(gw, carol, usd(3)));
305 nOffers(env, 1, alice, eur(1), usd(10));
312 nOffers(env, 1, alice, eur(499), usd(499));
348 env(
pay(gw, bob, eur(2'000)));
350 env(
offer(bob, usd(4'000), eur(4'000)));
360 auto const numAOffers =
361 1 + 2'000 + 100 + 1'000 + 1 - (1 + (2 * 100) + (2 * 199) + 1 + 1);
378 auto const gw =
Account(
"gateway");
379 auto const alice =
Account(
"alice");
380 auto const bob =
Account(
"bob");
382 Env env(*
this, features);
384 env.
fund(
XRP(100'000'000), gw, alice, bob);
386 MPT const usd =
MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}});
388 env(
pay(gw, alice, usd(8'000)));
419 env(
offer(bob, usd(8'000),
XRP(8'000)),
Ter(expectedTER));
422 auto const expectedUSD = usd(1'996);
TestcaseT testcase
Memberspace for declaring test cases.
void testAutoBridgedLimits(FeatureBitset features)
void testStepLimit(FeatureBitset features)
void testStepAndCrossingLimit(FeatureBitset features)
void testCrossingLimit(FeatureBitset features)
void testOfferOverflow(FeatureBitset features)
void run() override
Runs the suite.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
PrettyAmount limit(Account const &account, Issue const &issue) const
Returns the IOU limit on an account.
void require(Args const &... args)
Check a set of requirements.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
Converts to MPT Issue or STAmount.
Match the number of items in the account's owner directory.
Set the expected result code for a JTx The test will fail if the code doesn't match.
void nOffers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
void testHelper2TokensMix(TTester &&tester)
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
OwnerCount< ltOFFER > offers
Match the number of offers in the account's owner directory.
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(CrossingLimits, app, xrpl, 10)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.