mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-08 11:16:51 +00:00
feat: Add MPT support to DEX (#5285)
This commit is contained in:
committed by
GitHub
parent
6d1a5be8d2
commit
dfcad69155
@@ -17,18 +17,6 @@
|
||||
namespace xrpl {
|
||||
namespace test {
|
||||
|
||||
struct DirectStepInfo
|
||||
{
|
||||
AccountID src;
|
||||
AccountID dst;
|
||||
Currency currency;
|
||||
};
|
||||
|
||||
struct XRPEndpointStepInfo
|
||||
{
|
||||
AccountID acc;
|
||||
};
|
||||
|
||||
enum class TrustFlag { freeze, auth, noripple };
|
||||
|
||||
/*constexpr*/ std::uint32_t
|
||||
@@ -69,82 +57,6 @@ getTrustFlag(
|
||||
return false; // silence warning
|
||||
}
|
||||
|
||||
bool
|
||||
equal(std::unique_ptr<Step> const& s1, DirectStepInfo const& dsi)
|
||||
{
|
||||
if (!s1)
|
||||
return false;
|
||||
return test::directStepEqual(*s1, dsi.src, dsi.dst, dsi.currency);
|
||||
}
|
||||
|
||||
bool
|
||||
equal(std::unique_ptr<Step> const& s1, XRPEndpointStepInfo const& xrpStepInfo)
|
||||
{
|
||||
if (!s1)
|
||||
return false;
|
||||
return test::xrpEndpointStepEqual(*s1, xrpStepInfo.acc);
|
||||
}
|
||||
|
||||
bool
|
||||
equal(std::unique_ptr<Step> const& s1, xrpl::Book const& bsi)
|
||||
{
|
||||
if (!s1)
|
||||
return false;
|
||||
return bookStepEqual(*s1, bsi);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
bool
|
||||
strandEqualHelper(Iter i)
|
||||
{
|
||||
// base case. all args processed and found equal.
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Iter, class StepInfo, class... Args>
|
||||
bool
|
||||
strandEqualHelper(Iter i, StepInfo&& si, Args&&... args)
|
||||
{
|
||||
if (!equal(*i, std::forward<StepInfo>(si)))
|
||||
return false;
|
||||
return strandEqualHelper(++i, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
bool
|
||||
equal(Strand const& strand, Args&&... args)
|
||||
{
|
||||
if (strand.size() != sizeof...(Args))
|
||||
return false;
|
||||
if (strand.empty())
|
||||
return true;
|
||||
return strandEqualHelper(strand.begin(), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
STPathElement
|
||||
ape(AccountID const& a)
|
||||
{
|
||||
return STPathElement(STPathElement::typeAccount, a, xrpCurrency(), xrpAccount());
|
||||
};
|
||||
|
||||
// Issue path element
|
||||
STPathElement
|
||||
ipe(Issue const& iss)
|
||||
{
|
||||
return STPathElement(
|
||||
STPathElement::typeCurrency | STPathElement::typeIssuer,
|
||||
xrpAccount(),
|
||||
iss.currency,
|
||||
iss.account);
|
||||
};
|
||||
|
||||
// Issuer path element
|
||||
STPathElement
|
||||
iape(AccountID const& account)
|
||||
{
|
||||
return STPathElement(STPathElement::typeIssuer, xrpAccount(), xrpCurrency(), account);
|
||||
};
|
||||
|
||||
class ElementComboIter
|
||||
{
|
||||
enum class SB /*state bit*/
|
||||
@@ -644,7 +556,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
alice,
|
||||
/*deliver*/ xrpIssue(),
|
||||
/*limitQuality*/ std::nullopt,
|
||||
/*sendMaxIssue*/ EUR.issue(),
|
||||
/*sendMaxIssue*/ EUR,
|
||||
path,
|
||||
true,
|
||||
OfferCrossing::no,
|
||||
@@ -662,7 +574,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
alice,
|
||||
/*deliver*/ xrpIssue(),
|
||||
/*limitQuality*/ std::nullopt,
|
||||
/*sendMaxIssue*/ EUR.issue(),
|
||||
/*sendMaxIssue*/ EUR,
|
||||
path,
|
||||
true,
|
||||
OfferCrossing::no,
|
||||
@@ -695,7 +607,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(
|
||||
env,
|
||||
EUR,
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath(),
|
||||
tesSUCCESS,
|
||||
D{alice, gw, usdC},
|
||||
@@ -706,7 +618,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(
|
||||
env,
|
||||
EUR,
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath({ipe(EUR)}),
|
||||
tesSUCCESS,
|
||||
D{alice, gw, usdC},
|
||||
@@ -718,7 +630,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(
|
||||
env,
|
||||
carol["USD"],
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath({iape(carol)}),
|
||||
tesSUCCESS,
|
||||
D{alice, gw, usdC},
|
||||
@@ -740,7 +652,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(
|
||||
env,
|
||||
xrpIssue(),
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath({STPathElement{
|
||||
STPathElement::typeCurrency, xrpAccount(), xrpCurrency(), xrpAccount()}}),
|
||||
tesSUCCESS,
|
||||
@@ -752,7 +664,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(
|
||||
env,
|
||||
EUR,
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath({cpe(xrpCurrency())}),
|
||||
tesSUCCESS,
|
||||
D{alice, gw, usdC},
|
||||
@@ -774,7 +686,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
xrpAccount(),
|
||||
XRP,
|
||||
std::nullopt,
|
||||
USD.issue(),
|
||||
USD,
|
||||
STPath(),
|
||||
true,
|
||||
OfferCrossing::no,
|
||||
@@ -820,7 +732,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
}
|
||||
|
||||
// Create an offer with the same in/out issue
|
||||
test(env, EUR, USD.issue(), STPath({ipe(USD), ipe(EUR)}), temBAD_PATH);
|
||||
test(env, EUR, USD, STPath({ipe(USD), ipe(EUR)}), temBAD_PATH);
|
||||
|
||||
// Path element with type zero
|
||||
test(
|
||||
@@ -836,7 +748,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
test(env, USD, std::nullopt, STPath({ape(gw), ape(carol)}), temBAD_PATH_LOOP);
|
||||
|
||||
// The same offer can't appear more than once on a path
|
||||
test(env, EUR, USD.issue(), STPath({ipe(EUR), ipe(USD), ipe(EUR)}), temBAD_PATH_LOOP);
|
||||
test(env, EUR, USD, STPath({ipe(EUR), ipe(USD), ipe(EUR)}), temBAD_PATH_LOOP);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -958,7 +870,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
bob,
|
||||
XRP,
|
||||
std::nullopt,
|
||||
USD.issue(),
|
||||
USD,
|
||||
path,
|
||||
false,
|
||||
OfferCrossing::no,
|
||||
@@ -966,8 +878,8 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
std::nullopt,
|
||||
env.app().getJournal("Flow"));
|
||||
BEAST_EXPECT(isTesSuccess(ter));
|
||||
BEAST_EXPECT(equal(
|
||||
strand, D{alice, gw, usdC}, B{USD.issue(), xrpIssue(), std::nullopt}, XRPS{bob}));
|
||||
BEAST_EXPECT(
|
||||
equal(strand, D{alice, gw, usdC}, B{USD, xrpIssue(), std::nullopt}, XRPS{bob}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,7 +1037,7 @@ struct PayStrand_test : public beast::unit_test::suite
|
||||
Env env(*this, features);
|
||||
env.fund(XRP(10000), alice, bob, gw);
|
||||
|
||||
STAmount const sendMax{USD.issue(), 100, 1};
|
||||
STAmount const sendMax{USD, 100, 1};
|
||||
STAmount const noAccountAmount{Issue{USD.currency, noAccount()}, 100, 1};
|
||||
STAmount const deliver;
|
||||
AccountID const srcAcc = alice.id();
|
||||
|
||||
Reference in New Issue
Block a user