rippled
Loading...
Searching...
No Matches
DeliverMin_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/beast/unit_test.h>
4#include <xrpl/protocol/Feature.h>
5
6namespace xrpl {
7namespace test {
8
10{
11public:
12 void
14 {
15 testcase("Convert all of an asset using DeliverMin");
16
17 using namespace jtx;
18 auto const gw = Account("gateway");
19 auto const USD = gw["USD"];
20
21 {
22 Env env(*this, features);
23 env.fund(XRP(10000), "alice", "bob", "carol", gw);
24 env.close();
25 env.trust(USD(100), "alice", "bob", "carol");
26 env.close();
27 env(pay("alice", "bob", USD(10)), deliver_min(USD(10)), ter(temBAD_AMOUNT));
28 env(pay("alice", "bob", USD(10)), deliver_min(USD(-5)), txflags(tfPartialPayment), ter(temBAD_AMOUNT));
29 env(pay("alice", "bob", USD(10)), deliver_min(XRP(5)), txflags(tfPartialPayment), ter(temBAD_AMOUNT));
30 env(pay("alice", "bob", USD(10)),
31 deliver_min(Account("carol")["USD"](5)),
34 env(pay("alice", "bob", USD(10)), deliver_min(USD(15)), txflags(tfPartialPayment), ter(temBAD_AMOUNT));
35 env(pay(gw, "carol", USD(50)));
36 env(offer("carol", XRP(5), USD(5)));
37 env(pay("alice", "bob", USD(10)),
38 paths(XRP),
39 deliver_min(USD(7)),
41 sendmax(XRP(5)),
43 env.require(balance("alice", XRP(10000) - drops(env.current()->fees().base)));
44 env.require(balance("bob", XRP(10000)));
45 }
46
47 {
48 Env env(*this, features);
49 env.fund(XRP(10000), "alice", "bob", gw);
50 env.close();
51 env.trust(USD(1000), "alice", "bob");
52 env.close();
53 env(pay(gw, "bob", USD(100)));
54 env(offer("bob", XRP(100), USD(100)));
55 env(pay("alice", "alice", USD(10000)),
56 paths(XRP),
57 deliver_min(USD(100)),
59 sendmax(XRP(100)));
60 env.require(balance("alice", USD(100)));
61 }
62
63 {
64 Env env(*this, features);
65 env.fund(XRP(10000), "alice", "bob", "carol", gw);
66 env.close();
67 env.trust(USD(1000), "bob", "carol");
68 env.close();
69 env(pay(gw, "bob", USD(200)));
70 env(offer("bob", XRP(100), USD(100)));
71 env(offer("bob", XRP(1000), USD(100)));
72 env(offer("bob", XRP(10000), USD(100)));
73 env(pay("alice", "carol", USD(10000)),
74 paths(XRP),
75 deliver_min(USD(200)),
77 sendmax(XRP(1000)),
79 env(pay("alice", "carol", USD(10000)),
80 paths(XRP),
81 deliver_min(USD(200)),
83 sendmax(XRP(1100)));
84 env.require(balance("bob", USD(0)));
85 env.require(balance("carol", USD(200)));
86 }
87
88 {
89 Env env(*this, features);
90 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
91 env.close();
92 env.trust(USD(1000), "bob", "carol", "dan");
93 env.close();
94 env(pay(gw, "bob", USD(100)));
95 env(pay(gw, "dan", USD(100)));
96 env(offer("bob", XRP(100), USD(100)));
97 env(offer("bob", XRP(1000), USD(100)));
98 env(offer("dan", XRP(100), USD(100)));
99 env(pay("alice", "carol", USD(10000)),
100 paths(XRP),
101 deliver_min(USD(200)),
103 sendmax(XRP(200)));
104 env.require(balance("bob", USD(0)));
105 env.require(balance("carol", USD(200)));
106 env.require(balance("dan", USD(0)));
107 }
108 }
109
110 void
111 run() override
112 {
113 using namespace jtx;
114 auto const sa = testable_amendments();
115 test_convert_all_of_an_asset(sa - featurePermissionedDEX);
117 }
118};
119
120BEAST_DEFINE_TESTSUITE(DeliverMin, app, xrpl);
121
122} // namespace test
123} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:147
void test_convert_all_of_an_asset(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:97
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:97
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:260
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:283
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:511
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:297
A balance matches.
Definition balance.h:19
Sets the DeliverMin on a JTx.
Definition delivermin.h:13
Set Paths, SendMax on a JTx.
Definition paths.h:15
Sets the SendMax on a JTx.
Definition sendmax.h:13
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:15
Set the flags on a JTx.
Definition txflags.h:11
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:90
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:11
FeatureBitset testable_amendments()
Definition Env.h:54
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:10
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ temBAD_AMOUNT
Definition TER.h:69
@ tecPATH_PARTIAL
Definition TER.h:263
constexpr std::uint32_t tfPartialPayment
Definition TxFlags.h:88