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#include <xrpl/beast/unit_test.h>
22#include <xrpl/protocol/Feature.h>
23
24namespace ripple {
25namespace test {
26
28{
29public:
30 void
32 {
33 testcase("Convert all of an asset using DeliverMin");
34
35 using namespace jtx;
36 auto const gw = Account("gateway");
37 auto const USD = gw["USD"];
38
39 {
40 Env env(*this, features);
41 env.fund(XRP(10000), "alice", "bob", "carol", gw);
42 env.trust(USD(100), "alice", "bob", "carol");
43 env(pay("alice", "bob", USD(10)),
44 delivermin(USD(10)),
46 env(pay("alice", "bob", USD(10)),
47 delivermin(USD(-5)),
50 env(pay("alice", "bob", USD(10)),
51 delivermin(XRP(5)),
54 env(pay("alice", "bob", USD(10)),
55 delivermin(Account("carol")["USD"](5)),
58 env(pay("alice", "bob", USD(10)),
59 delivermin(USD(15)),
62 env(pay(gw, "carol", USD(50)));
63 env(offer("carol", XRP(5), USD(5)));
64 env(pay("alice", "bob", USD(10)),
65 paths(XRP),
66 delivermin(USD(7)),
68 sendmax(XRP(5)),
70 env.require(balance("alice", XRP(9999.99999)));
71 env.require(balance("bob", XRP(10000)));
72 }
73
74 {
75 Env env(*this, features);
76 env.fund(XRP(10000), "alice", "bob", gw);
77 env.trust(USD(1000), "alice", "bob");
78 env(pay(gw, "bob", USD(100)));
79 env(offer("bob", XRP(100), USD(100)));
80 env(pay("alice", "alice", USD(10000)),
81 paths(XRP),
82 delivermin(USD(100)),
84 sendmax(XRP(100)));
85 env.require(balance("alice", USD(100)));
86 }
87
88 {
89 Env env(*this, features);
90 env.fund(XRP(10000), "alice", "bob", "carol", gw);
91 env.trust(USD(1000), "bob", "carol");
92 env(pay(gw, "bob", USD(200)));
93 env(offer("bob", XRP(100), USD(100)));
94 env(offer("bob", XRP(1000), USD(100)));
95 env(offer("bob", XRP(10000), USD(100)));
96 env(pay("alice", "carol", USD(10000)),
97 paths(XRP),
98 delivermin(USD(200)),
100 sendmax(XRP(1000)),
102 env(pay("alice", "carol", USD(10000)),
103 paths(XRP),
104 delivermin(USD(200)),
106 sendmax(XRP(1100)));
107 env.require(balance("bob", USD(0)));
108 env.require(balance("carol", USD(200)));
109 }
110
111 {
112 Env env(*this, features);
113 env.fund(XRP(10000), "alice", "bob", "carol", "dan", gw);
114 env.trust(USD(1000), "bob", "carol", "dan");
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)),
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 = supported_amendments();
136 test_convert_all_of_an_asset(sa - featureFlowCross);
138 }
139};
140
141BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple);
142
143} // namespace test
144} // namespace ripple
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
void test_convert_all_of_an_asset(FeatureBitset features)
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition: Account.h:38
A transaction testing environment.
Definition: Env.h:117
void require(Args const &... args)
Check a set of requirements.
Definition: Env.h:529
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition: Env.cpp:268
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:237
A balance matches.
Definition: balance.h:39
Sets the DeliverMin on a JTx.
Definition: delivermin.h:32
Set Paths, SendMax on a JTx.
Definition: paths.h:33
Sets the SendMax on a JTx.
Definition: sendmax.h:32
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:34
Set the flags on a JTx.
Definition: txflags.h:31
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition: offer.cpp:28
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:104
FeatureBitset supported_amendments()
Definition: Env.h:70
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr std::uint32_t tfPartialPayment
Definition: TxFlags.h:105
@ tecPATH_PARTIAL
Definition: TER.h:269
@ temBAD_AMOUNT
Definition: TER.h:89