xrpld
Loading...
Searching...
No Matches
DeliverMin_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/balance.h>
6#include <test/jtx/delivermin.h>
7#include <test/jtx/offer.h>
8#include <test/jtx/paths.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/sendmax.h>
11#include <test/jtx/ter.h>
12#include <test/jtx/txflags.h>
13
14#include <xrpl/beast/unit_test/suite.h>
15#include <xrpl/protocol/Feature.h>
16#include <xrpl/protocol/TER.h>
17#include <xrpl/protocol/TxFlags.h>
18
19namespace xrpl::test {
20
22{
23public:
24 void
26 {
27 testcase("Convert all of an asset using DeliverMin");
28
29 using namespace jtx;
30 auto const gw = Account("gateway");
31 auto const usd = gw["USD"];
32
33 {
34 Env env(*this, features);
35 env.fund(XRP(10000), "alice", "bob", "carol", gw);
36 env.close();
37 env.trust(usd(100), "alice", "bob", "carol");
38 env.close();
39 env(pay("alice", "bob", usd(10)), DeliverMin(usd(10)), Ter(temBAD_AMOUNT));
40 env(pay("alice", "bob", usd(10)),
41 DeliverMin(usd(-5)),
42 Txflags(tfPartialPayment),
44 env(pay("alice", "bob", usd(10)),
45 DeliverMin(XRP(5)),
46 Txflags(tfPartialPayment),
48 env(pay("alice", "bob", usd(10)),
49 DeliverMin(Account("carol")["USD"](5)),
50 Txflags(tfPartialPayment),
52 env(pay("alice", "bob", usd(10)),
53 DeliverMin(usd(15)),
54 Txflags(tfPartialPayment),
56 env(pay(gw, "carol", usd(50)));
57 env(offer("carol", XRP(5), usd(5)));
58 env(pay("alice", "bob", usd(10)),
59 Paths(XRP),
60 DeliverMin(usd(7)),
61 Txflags(tfPartialPayment),
62 Sendmax(XRP(5)),
64 env.require(Balance("alice", XRP(10000) - drops(env.current()->fees().base)));
65 env.require(Balance("bob", XRP(10000)));
66 }
67
68 {
69 Env env(*this, features);
70 env.fund(XRP(10000), "alice", "bob", gw);
71 env.close();
72 env.trust(usd(1000), "alice", "bob");
73 env.close();
74 env(pay(gw, "bob", usd(100)));
75 env(offer("bob", XRP(100), usd(100)));
76 env(pay("alice", "alice", usd(10000)),
77 Paths(XRP),
78 DeliverMin(usd(100)),
79 Txflags(tfPartialPayment),
80 Sendmax(XRP(100)));
81 env.require(Balance("alice", usd(100)));
82 }
83
84 {
85 Env env(*this, features);
86 env.fund(XRP(10000), "alice", "bob", "carol", gw);
87 env.close();
88 env.trust(usd(1000), "bob", "carol");
89 env.close();
90 env(pay(gw, "bob", usd(200)));
91 env(offer("bob", XRP(100), usd(100)));
92 env(offer("bob", XRP(1000), usd(100)));
93 env(offer("bob", XRP(10000), usd(100)));
94 env(pay("alice", "carol", usd(10000)),
95 Paths(XRP),
96 DeliverMin(usd(200)),
97 Txflags(tfPartialPayment),
98 Sendmax(XRP(1000)),
100 env(pay("alice", "carol", usd(10000)),
101 Paths(XRP),
102 DeliverMin(usd(200)),
103 Txflags(tfPartialPayment),
104 Sendmax(XRP(1100)));
105 env.require(Balance("bob", usd(0)));
106 env.require(Balance("carol", usd(200)));
107 }
108
109 {
110 Env env(*this, features);
111 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
112 env.close();
113 env.trust(usd(1000), "bob", "carol", "dan");
114 env.close();
115 env(pay(gw, "bob", usd(100)));
116 env(pay(gw, "dan", usd(100)));
117 env(offer("bob", XRP(100), usd(100)));
118 env(offer("bob", XRP(1000), usd(100)));
119 env(offer("dan", XRP(100), usd(100)));
120 env(pay("alice", "carol", usd(10000)),
121 Paths(XRP),
122 DeliverMin(usd(200)),
123 Txflags(tfPartialPayment),
124 Sendmax(XRP(200)));
125 env.require(Balance("bob", usd(0)));
126 env.require(Balance("carol", usd(200)));
127 env.require(Balance("dan", usd(0)));
128 }
129 }
130
131 void
132 run() override
133 {
134 using namespace jtx;
135 auto const sa = testableAmendments();
136 testConvertAllOfAnAsset(sa - featurePermissionedDEX);
138 }
139};
140
142
143} // namespace xrpl::test
A testsuite class.
Definition suite.h:50
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
void testConvertAllOfAnAsset(FeatureBitset features)
void run() override
Runs the suite.
Sets the DeliverMin on a JTx.
Definition delivermin.h:13
A transaction testing environment.
Definition Env.h:143
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:327
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:605
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:353
Set Paths, SendMax on a JTx.
Definition paths.h:16
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:13
Set the flags on a JTx.
Definition txflags.h:9
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
FeatureBitset testableAmendments()
Definition Env.h:76
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ temBAD_AMOUNT
Definition TER.h:75
@ tecPATH_PARTIAL
Definition TER.h:280