#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace xrpl::test { class DeliverMin_test : public beast::unit_test::Suite { public: void testConvertAllOfAnAsset(FeatureBitset features) { testcase("Convert all of an asset using DeliverMin"); using namespace jtx; auto const gw = Account("gateway"); auto const usd = gw["USD"]; { Env env(*this, features); env.fund(XRP(10000), "alice", "bob", "carol", gw); env.close(); env.trust(usd(100), "alice", "bob", "carol"); env.close(); env(pay("alice", "bob", usd(10)), DeliverMin(usd(10)), Ter(temBAD_AMOUNT)); env(pay("alice", "bob", usd(10)), DeliverMin(usd(-5)), Txflags(tfPartialPayment), Ter(temBAD_AMOUNT)); env(pay("alice", "bob", usd(10)), DeliverMin(XRP(5)), Txflags(tfPartialPayment), Ter(temBAD_AMOUNT)); env(pay("alice", "bob", usd(10)), DeliverMin(Account("carol")["USD"](5)), Txflags(tfPartialPayment), Ter(temBAD_AMOUNT)); env(pay("alice", "bob", usd(10)), DeliverMin(usd(15)), Txflags(tfPartialPayment), Ter(temBAD_AMOUNT)); env(pay(gw, "carol", usd(50))); env(offer("carol", XRP(5), usd(5))); env(pay("alice", "bob", usd(10)), Paths(XRP), DeliverMin(usd(7)), Txflags(tfPartialPayment), Sendmax(XRP(5)), Ter(tecPATH_PARTIAL)); env.require(Balance("alice", XRP(10000) - drops(env.current()->fees().base))); env.require(Balance("bob", XRP(10000))); } { Env env(*this, features); env.fund(XRP(10000), "alice", "bob", gw); env.close(); env.trust(usd(1000), "alice", "bob"); env.close(); env(pay(gw, "bob", usd(100))); env(offer("bob", XRP(100), usd(100))); env(pay("alice", "alice", usd(10000)), Paths(XRP), DeliverMin(usd(100)), Txflags(tfPartialPayment), Sendmax(XRP(100))); env.require(Balance("alice", usd(100))); } { Env env(*this, features); env.fund(XRP(10000), "alice", "bob", "carol", gw); env.close(); env.trust(usd(1000), "bob", "carol"); env.close(); env(pay(gw, "bob", usd(200))); env(offer("bob", XRP(100), usd(100))); env(offer("bob", XRP(1000), usd(100))); env(offer("bob", XRP(10000), usd(100))); env(pay("alice", "carol", usd(10000)), Paths(XRP), DeliverMin(usd(200)), Txflags(tfPartialPayment), Sendmax(XRP(1000)), Ter(tecPATH_PARTIAL)); env(pay("alice", "carol", usd(10000)), Paths(XRP), DeliverMin(usd(200)), Txflags(tfPartialPayment), Sendmax(XRP(1100))); env.require(Balance("bob", usd(0))); env.require(Balance("carol", usd(200))); } { Env env(*this, features); env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw); env.close(); env.trust(usd(1000), "bob", "carol", "dan"); env.close(); env(pay(gw, "bob", usd(100))); env(pay(gw, "dan", usd(100))); env(offer("bob", XRP(100), usd(100))); env(offer("bob", XRP(1000), usd(100))); env(offer("dan", XRP(100), usd(100))); env(pay("alice", "carol", usd(10000)), Paths(XRP), DeliverMin(usd(200)), Txflags(tfPartialPayment), Sendmax(XRP(200))); env.require(Balance("bob", usd(0))); env.require(Balance("carol", usd(200))); env.require(Balance("dan", usd(0))); } } void run() override { using namespace jtx; auto const sa = testableAmendments(); testConvertAllOfAnAsset(sa - featurePermissionedDEX); testConvertAllOfAnAsset(sa); } }; BEAST_DEFINE_TESTSUITE(DeliverMin, app, xrpl); } // namespace xrpl::test