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,
122 env(
pay(gw,
"alice", usd(1000)));
123 env(
pay(gw,
"carol", usd(1)));
124 env(
pay(gw,
"evita", usd(evitaOfferCount + 1)));
128 int const carolOfferCount{700};
130 nOffers(env, carolOfferCount,
"carol",
XRP(1), usd(1));
131 nOffers(env, evitaOfferCount,
"evita",
XRP(1), usd(1));
136 env(
offer(
"bob", usd(1000),
XRP(1000)));
148 env(
offer(
"dan", usd(maxConsumed + 50),
XRP(maxConsumed + 50)));
174 auto const gw =
Account(
"gateway");
175 auto const alice =
Account(
"alice");
176 auto const bob =
Account(
"bob");
177 auto const carol =
Account(
"carol");
192 auto const test = [&](
auto&& issue1,
auto&& issue2) {
193 Env env(*
this, features);
195 env.
fund(
XRP(100'000'000), gw, alice, bob, carol);
197 auto const usd = issue1({
201 .holders = {alice, carol},
204 auto const eur = issue2({
212 env(
pay(gw, alice, usd(4'000)));
213 env(
pay(gw, carol, usd(3)));
223 nOffers(env, 1, alice, eur(500), usd(500));
264 env(
pay(gw, bob, eur(2'000)));
266 env(
offer(bob, usd(4'000), eur(4'000)));
276 auto const numAOffers = 2'000 + 100 + 1'000 + 1 - ((2 * 100) + (2 * 199) + 1 + 1);
285 auto const test = [&](
auto&& issue1,
auto&& issue2) {
286 Env env(*
this, features);
288 env.
fund(
XRP(100'000'000), gw, alice, bob, carol);
290 auto const usd = issue1({
294 .holders = {alice, carol},
297 auto const eur = issue2({
305 env(
pay(gw, alice, usd(4'000)));
306 env(
pay(gw, carol, usd(3)));
310 nOffers(env, 1, alice, eur(1), usd(10));
317 nOffers(env, 1, alice, eur(499), usd(499));
353 env(
pay(gw, bob, eur(2'000)));
355 env(
offer(bob, usd(4'000), eur(4'000)));
365 auto const numAOffers =
366 1 + 2'000 + 100 + 1'000 + 1 - (1 + (2 * 100) + (2 * 199) + 1 + 1);
383 auto const gw =
Account(
"gateway");
384 auto const alice =
Account(
"alice");
385 auto const bob =
Account(
"bob");
387 Env env(*
this, features);
389 env.
fund(
XRP(100'000'000), gw, alice, bob);
391 MPT const usd =
MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}});
393 env(
pay(gw, alice, usd(8'000)));
424 env(
offer(bob, usd(8'000),
XRP(8'000)),
Ter(expectedTER));
427 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()
OwnerCount< ltOFFER > Offers
Match the number of offers in the account's owner directory.
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
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.