rippled
LoadFeeTrack_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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/app/misc/LoadFeeTrack.h>
21 #include <ripple/beast/unit_test.h>
22 #include <ripple/core/Config.h>
23 #include <ripple/ledger/ReadView.h>
24 
25 namespace ripple {
26 
27 class LoadFeeTrack_test : public beast::unit_test::suite
28 {
29 public:
30  void
31  run() override
32  {
33  Config d; // get a default configuration object
34  LoadFeeTrack l;
35  {
36  Fees const fees = [&]() {
37  Fees f;
38  f.base = d.FEES.reference_fee;
39  f.reserve = 200 * DROPS_PER_XRP;
40  f.increment = 50 * DROPS_PER_XRP;
41  return f;
42  }();
43 
44  BEAST_EXPECT(
45  scaleFeeLoad(XRPAmount{0}, l, fees, false) == XRPAmount{0});
46  BEAST_EXPECT(
47  scaleFeeLoad(XRPAmount{10000}, l, fees, false) ==
48  XRPAmount{10000});
49  BEAST_EXPECT(
50  scaleFeeLoad(XRPAmount{1}, l, fees, false) == XRPAmount{1});
51  }
52  {
53  Fees const fees = [&]() {
54  Fees f;
55  f.base = d.FEES.reference_fee * 10;
56  f.reserve = 200 * DROPS_PER_XRP;
57  f.increment = 50 * DROPS_PER_XRP;
58  return f;
59  }();
60 
61  BEAST_EXPECT(
62  scaleFeeLoad(XRPAmount{0}, l, fees, false) == XRPAmount{0});
63  BEAST_EXPECT(
64  scaleFeeLoad(XRPAmount{10000}, l, fees, false) ==
65  XRPAmount{10000});
66  BEAST_EXPECT(
67  scaleFeeLoad(XRPAmount{1}, l, fees, false) == XRPAmount{1});
68  }
69  {
70  Fees const fees = [&]() {
71  Fees f;
72  f.base = d.FEES.reference_fee;
73  f.reserve = 200 * DROPS_PER_XRP;
74  f.increment = 50 * DROPS_PER_XRP;
75  return f;
76  }();
77 
78  BEAST_EXPECT(
79  scaleFeeLoad(XRPAmount{0}, l, fees, false) == XRPAmount{0});
80  BEAST_EXPECT(
81  scaleFeeLoad(XRPAmount{10000}, l, fees, false) ==
82  XRPAmount{10000});
83  BEAST_EXPECT(
84  scaleFeeLoad(XRPAmount{1}, l, fees, false) == XRPAmount{1});
85  }
86  }
87 };
88 
89 BEAST_DEFINE_TESTSUITE(LoadFeeTrack, ripple_core, ripple);
90 
91 } // namespace ripple
ripple::FeeSetup::reference_fee
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition: Config.h:72
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
ripple::LoadFeeTrack_test
Definition: LoadFeeTrack_test.cpp:27
ripple::Fees::reserve
XRPAmount reserve
Definition: ReadView.h:52
ripple::Fees::increment
XRPAmount increment
Definition: ReadView.h:53
ripple::LoadFeeTrack_test::run
void run() override
Definition: LoadFeeTrack_test.cpp:31
ripple::Fees
Reflects the fee settings for a particular ledger.
Definition: ReadView.h:49
ripple::Config
Definition: Config.h:89
ripple::LoadFeeTrack
Manages the current fee schedule.
Definition: LoadFeeTrack.h:44
ripple::DROPS_PER_XRP
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
Definition: XRPAmount.h:250
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::scaleFeeLoad
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Definition: LoadFeeTrack.cpp:89
ripple::Config::FEES
FeeSetup FEES
Definition: Config.h:209
ripple::Fees::base
XRPAmount base
Definition: ReadView.h:51
ripple::XRPAmount
Definition: XRPAmount.h:46