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 ripple {
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)),
28 delivermin(USD(10)),
30 env(pay("alice", "bob", USD(10)),
31 delivermin(USD(-5)),
34 env(pay("alice", "bob", USD(10)),
35 delivermin(XRP(5)),
38 env(pay("alice", "bob", USD(10)),
39 delivermin(Account("carol")["USD"](5)),
42 env(pay("alice", "bob", USD(10)),
43 delivermin(USD(15)),
46 env(pay(gw, "carol", USD(50)));
47 env(offer("carol", XRP(5), USD(5)));
48 env(pay("alice", "bob", USD(10)),
49 paths(XRP),
50 delivermin(USD(7)),
52 sendmax(XRP(5)),
54 env.require(balance(
55 "alice", XRP(10000) - drops(env.current()->fees().base)));
56 env.require(balance("bob", XRP(10000)));
57 }
58
59 {
60 Env env(*this, features);
61 env.fund(XRP(10000), "alice", "bob", gw);
62 env.close();
63 env.trust(USD(1000), "alice", "bob");
64 env.close();
65 env(pay(gw, "bob", USD(100)));
66 env(offer("bob", XRP(100), USD(100)));
67 env(pay("alice", "alice", USD(10000)),
68 paths(XRP),
69 delivermin(USD(100)),
71 sendmax(XRP(100)));
72 env.require(balance("alice", USD(100)));
73 }
74
75 {
76 Env env(*this, features);
77 env.fund(XRP(10000), "alice", "bob", "carol", gw);
78 env.close();
79 env.trust(USD(1000), "bob", "carol");
80 env.close();
81 env(pay(gw, "bob", USD(200)));
82 env(offer("bob", XRP(100), USD(100)));
83 env(offer("bob", XRP(1000), USD(100)));
84 env(offer("bob", XRP(10000), USD(100)));
85 env(pay("alice", "carol", USD(10000)),
86 paths(XRP),
87 delivermin(USD(200)),
89 sendmax(XRP(1000)),
91 env(pay("alice", "carol", USD(10000)),
92 paths(XRP),
93 delivermin(USD(200)),
95 sendmax(XRP(1100)));
96 env.require(balance("bob", USD(0)));
97 env.require(balance("carol", USD(200)));
98 }
99
100 {
101 Env env(*this, features);
102 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
103 env.close();
104 env.trust(USD(1000), "bob", "carol", "dan");
105 env.close();
106 env(pay(gw, "bob", USD(100)));
107 env(pay(gw, "dan", USD(100)));
108 env(offer("bob", XRP(100), USD(100)));
109 env(offer("bob", XRP(1000), USD(100)));
110 env(offer("dan", XRP(100), USD(100)));
111 env(pay("alice", "carol", USD(10000)),
112 paths(XRP),
113 delivermin(USD(200)),
115 sendmax(XRP(200)));
116 env.require(balance("bob", USD(0)));
117 env.require(balance("carol", USD(200)));
118 env.require(balance("dan", USD(0)));
119 }
120 }
121
122 void
123 run() override
124 {
125 using namespace jtx;
126 auto const sa = testable_amendments();
127 test_convert_all_of_an_asset(sa - featurePermissionedDEX);
129 }
130};
131
132BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple);
133
134} // namespace test
135} // namespace ripple
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void test_convert_all_of_an_asset(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:528
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:312
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:103
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:302
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:271
A balance matches.
Definition balance.h:20
Sets the DeliverMin on a JTx.
Definition delivermin.h:14
Set Paths, SendMax on a JTx.
Definition paths.h:16
Sets the SendMax on a JTx.
Definition sendmax.h:14
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:16
Set the flags on a JTx.
Definition txflags.h:12
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:11
FeatureBitset testable_amendments()
Definition Env.h:55
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:10
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
constexpr std::uint32_t tfPartialPayment
Definition TxFlags.h:89
@ tecPATH_PARTIAL
Definition TER.h:264
@ temBAD_AMOUNT
Definition TER.h:70