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)),
29 deliver_min(USD(-5)),
30 txflags(tfPartialPayment),
32 env(pay("alice", "bob", USD(10)),
33 deliver_min(XRP(5)),
34 txflags(tfPartialPayment),
36 env(pay("alice", "bob", USD(10)),
37 deliver_min(Account("carol")["USD"](5)),
38 txflags(tfPartialPayment),
40 env(pay("alice", "bob", USD(10)),
41 deliver_min(USD(15)),
42 txflags(tfPartialPayment),
44 env(pay(gw, "carol", USD(50)));
45 env(offer("carol", XRP(5), USD(5)));
46 env(pay("alice", "bob", USD(10)),
47 paths(XRP),
48 deliver_min(USD(7)),
49 txflags(tfPartialPayment),
50 sendmax(XRP(5)),
52 env.require(balance("alice", XRP(10000) - drops(env.current()->fees().base)));
53 env.require(balance("bob", XRP(10000)));
54 }
55
56 {
57 Env env(*this, features);
58 env.fund(XRP(10000), "alice", "bob", gw);
59 env.close();
60 env.trust(USD(1000), "alice", "bob");
61 env.close();
62 env(pay(gw, "bob", USD(100)));
63 env(offer("bob", XRP(100), USD(100)));
64 env(pay("alice", "alice", USD(10000)),
65 paths(XRP),
66 deliver_min(USD(100)),
67 txflags(tfPartialPayment),
68 sendmax(XRP(100)));
69 env.require(balance("alice", USD(100)));
70 }
71
72 {
73 Env env(*this, features);
74 env.fund(XRP(10000), "alice", "bob", "carol", gw);
75 env.close();
76 env.trust(USD(1000), "bob", "carol");
77 env.close();
78 env(pay(gw, "bob", USD(200)));
79 env(offer("bob", XRP(100), USD(100)));
80 env(offer("bob", XRP(1000), USD(100)));
81 env(offer("bob", XRP(10000), USD(100)));
82 env(pay("alice", "carol", USD(10000)),
83 paths(XRP),
84 deliver_min(USD(200)),
85 txflags(tfPartialPayment),
86 sendmax(XRP(1000)),
88 env(pay("alice", "carol", USD(10000)),
89 paths(XRP),
90 deliver_min(USD(200)),
91 txflags(tfPartialPayment),
92 sendmax(XRP(1100)));
93 env.require(balance("bob", USD(0)));
94 env.require(balance("carol", USD(200)));
95 }
96
97 {
98 Env env(*this, features);
99 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
100 env.close();
101 env.trust(USD(1000), "bob", "carol", "dan");
102 env.close();
103 env(pay(gw, "bob", USD(100)));
104 env(pay(gw, "dan", USD(100)));
105 env(offer("bob", XRP(100), USD(100)));
106 env(offer("bob", XRP(1000), USD(100)));
107 env(offer("dan", XRP(100), USD(100)));
108 env(pay("alice", "carol", USD(10000)),
109 paths(XRP),
110 deliver_min(USD(200)),
111 txflags(tfPartialPayment),
112 sendmax(XRP(200)));
113 env.require(balance("bob", USD(0)));
114 env.require(balance("carol", USD(200)));
115 env.require(balance("dan", USD(0)));
116 }
117 }
118
119 void
120 run() override
121 {
122 using namespace jtx;
123 auto const sa = testable_amendments();
124 test_convert_all_of_an_asset(sa - featurePermissionedDEX);
126 }
127};
128
129BEAST_DEFINE_TESTSUITE(DeliverMin, app, xrpl);
130
131} // namespace test
132} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:150
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:122
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:100
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:270
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:301
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:588
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:329
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:95
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:11
FeatureBitset testable_amendments()
Definition Env.h:78
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