rippled
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 <ripple/beast/unit_test.h>
21 #include <ripple/protocol/Feature.h>
22 #include <test/jtx.h>
23 
24 namespace ripple {
25 namespace test {
26 
27 class DeliverMin_test : public beast::unit_test::suite
28 {
29 public:
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();
138  }
139 };
140 
141 BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple);
142 
143 } // namespace test
144 } // namespace ripple
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
ripple::test::jtx::ter
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:33
ripple::test::jtx::Env::require
void require(Args const &... args)
Check a set of requirements.
Definition: Env.h:466
ripple::test::jtx::balance
A balance matches.
Definition: balance.h:38
ripple::test::jtx::Env::trust
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition: Env.cpp:259
ripple::test::DeliverMin_test::test_convert_all_of_an_asset
void test_convert_all_of_an_asset(FeatureBitset features)
Definition: DeliverMin_test.cpp:31
ripple::tfPartialPayment
constexpr std::uint32_t tfPartialPayment
Definition: TxFlags.h:102
ripple::test::jtx::sendmax
Sets the SendMax on a JTx.
Definition: sendmax.h:31
ripple::test::jtx::txflags
Set the flags on a JTx.
Definition: txflags.h:30
ripple::test::jtx::paths
Set Paths, SendMax on a JTx.
Definition: paths.h:32
ripple::temBAD_AMOUNT
@ temBAD_AMOUNT
Definition: TER.h:87
ripple::test::jtx::supported_amendments
FeatureBitset supported_amendments()
Definition: Env.h:70
ripple::tecPATH_PARTIAL
@ tecPATH_PARTIAL
Definition: TER.h:249
ripple::test::DeliverMin_test::run
void run() override
Definition: DeliverMin_test.cpp:132
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::pay
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
ripple::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:228
ripple::FeatureBitset
Definition: Feature.h:113
ripple::test::jtx::delivermin
Sets the DeliverMin on a JTx.
Definition: delivermin.h:31
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::test::DeliverMin_test
Definition: DeliverMin_test.cpp:27
ripple::featureFlowCross
const uint256 featureFlowCross
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)