rippled
Loading...
Searching...
No Matches
DeliverMin_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx.h>
21
22#include <xrpl/beast/unit_test.h>
23#include <xrpl/protocol/Feature.h>
24
25namespace ripple {
26namespace test {
27
29{
30public:
31 void
33 {
34 testcase("Convert all of an asset using DeliverMin");
35
36 using namespace jtx;
37 auto const gw = Account("gateway");
38 auto const USD = gw["USD"];
39
40 {
41 Env env(*this, features);
42 env.fund(XRP(10000), "alice", "bob", "carol", gw);
43 env.close();
44 env.trust(USD(100), "alice", "bob", "carol");
45 env.close();
46 env(pay("alice", "bob", USD(10)),
47 delivermin(USD(10)),
49 env(pay("alice", "bob", USD(10)),
50 delivermin(USD(-5)),
53 env(pay("alice", "bob", USD(10)),
54 delivermin(XRP(5)),
57 env(pay("alice", "bob", USD(10)),
58 delivermin(Account("carol")["USD"](5)),
61 env(pay("alice", "bob", USD(10)),
62 delivermin(USD(15)),
65 env(pay(gw, "carol", USD(50)));
66 env(offer("carol", XRP(5), USD(5)));
67 env(pay("alice", "bob", USD(10)),
68 paths(XRP),
69 delivermin(USD(7)),
71 sendmax(XRP(5)),
73 env.require(balance(
74 "alice", XRP(10000) - drops(env.current()->fees().base)));
75 env.require(balance("bob", XRP(10000)));
76 }
77
78 {
79 Env env(*this, features);
80 env.fund(XRP(10000), "alice", "bob", gw);
81 env.close();
82 env.trust(USD(1000), "alice", "bob");
83 env.close();
84 env(pay(gw, "bob", USD(100)));
85 env(offer("bob", XRP(100), USD(100)));
86 env(pay("alice", "alice", USD(10000)),
87 paths(XRP),
88 delivermin(USD(100)),
90 sendmax(XRP(100)));
91 env.require(balance("alice", USD(100)));
92 }
93
94 {
95 Env env(*this, features);
96 env.fund(XRP(10000), "alice", "bob", "carol", gw);
97 env.close();
98 env.trust(USD(1000), "bob", "carol");
99 env.close();
100 env(pay(gw, "bob", USD(200)));
101 env(offer("bob", XRP(100), USD(100)));
102 env(offer("bob", XRP(1000), USD(100)));
103 env(offer("bob", XRP(10000), USD(100)));
104 env(pay("alice", "carol", USD(10000)),
105 paths(XRP),
106 delivermin(USD(200)),
108 sendmax(XRP(1000)),
110 env(pay("alice", "carol", USD(10000)),
111 paths(XRP),
112 delivermin(USD(200)),
114 sendmax(XRP(1100)));
115 env.require(balance("bob", USD(0)));
116 env.require(balance("carol", USD(200)));
117 }
118
119 {
120 Env env(*this, features);
121 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
122 env.close();
123 env.trust(USD(1000), "bob", "carol", "dan");
124 env.close();
125 env(pay(gw, "bob", USD(100)));
126 env(pay(gw, "dan", USD(100)));
127 env(offer("bob", XRP(100), USD(100)));
128 env(offer("bob", XRP(1000), USD(100)));
129 env(offer("dan", XRP(100), USD(100)));
130 env(pay("alice", "carol", USD(10000)),
131 paths(XRP),
132 delivermin(USD(200)),
134 sendmax(XRP(200)));
135 env.require(balance("bob", USD(0)));
136 env.require(balance("carol", USD(200)));
137 env.require(balance("dan", USD(0)));
138 }
139 }
140
141 void
142 run() override
143 {
144 using namespace jtx;
145 auto const sa = testable_amendments();
146 test_convert_all_of_an_asset(sa - featurePermissionedDEX);
148 }
149};
150
151BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple);
152
153} // namespace test
154} // namespace ripple
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
void test_convert_all_of_an_asset(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:39
A transaction testing environment.
Definition Env.h:121
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:547
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:331
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:121
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:320
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:289
A balance matches.
Definition balance.h:39
Sets the DeliverMin on a JTx.
Definition delivermin.h:33
Set Paths, SendMax on a JTx.
Definition paths.h:35
Sets the SendMax on a JTx.
Definition sendmax.h:33
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:35
Set the flags on a JTx.
Definition txflags.h:31
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:30
FeatureBitset testable_amendments()
Definition Env.h:74
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:29
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:111
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr std::uint32_t tfPartialPayment
Definition TxFlags.h:108
@ tecPATH_PARTIAL
Definition TER.h:282
@ temBAD_AMOUNT
Definition TER.h:89