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.FEE_DEFAULT;
40  f.reserve = 200 * DROPS_PER_XRP;
41  f.increment = 50 * DROPS_PER_XRP;
42  return f;
43  }();
44 
45  BEAST_EXPECT(
46  scaleFeeLoad(FeeUnit64{0}, l, fees, false) == XRPAmount{0});
47  BEAST_EXPECT(
48  scaleFeeLoad(FeeUnit64{10000}, l, fees, false) ==
49  XRPAmount{10000});
50  BEAST_EXPECT(
51  scaleFeeLoad(FeeUnit64{1}, l, fees, false) == XRPAmount{1});
52  }
53  {
54  Fees const fees = [&]() {
55  Fees f;
56  f.base = d.FEE_DEFAULT * 10;
58  f.reserve = 200 * DROPS_PER_XRP;
59  f.increment = 50 * DROPS_PER_XRP;
60  return f;
61  }();
62 
63  BEAST_EXPECT(
64  scaleFeeLoad(FeeUnit64{0}, l, fees, false) == XRPAmount{0});
65  BEAST_EXPECT(
66  scaleFeeLoad(FeeUnit64{10000}, l, fees, false) ==
67  XRPAmount{100000});
68  BEAST_EXPECT(
69  scaleFeeLoad(FeeUnit64{1}, l, fees, false) == XRPAmount{10});
70  }
71  {
72  Fees const fees = [&]() {
73  Fees f;
74  f.base = d.FEE_DEFAULT;
75  f.units = d.TRANSACTION_FEE_BASE * 10;
76  f.reserve = 200 * DROPS_PER_XRP;
77  f.increment = 50 * DROPS_PER_XRP;
78  return f;
79  }();
80 
81  BEAST_EXPECT(
82  scaleFeeLoad(FeeUnit64{0}, l, fees, false) == XRPAmount{0});
83  BEAST_EXPECT(
84  scaleFeeLoad(FeeUnit64{10000}, l, fees, false) ==
85  XRPAmount{1000});
86  BEAST_EXPECT(
87  scaleFeeLoad(FeeUnit64{1}, l, fees, false) == XRPAmount{0});
88  }
89  }
90 };
91 
92 BEAST_DEFINE_TESTSUITE(LoadFeeTrack, ripple_core, ripple);
93 
94 } // namespace ripple
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
ripple::LoadFeeTrack_test
Definition: LoadFeeTrack_test.cpp:27
ripple::scaleFeeLoad
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Definition: LoadFeeTrack.cpp:89
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:48
ripple::Config
Definition: Config.h:69
ripple::Config::TRANSACTION_FEE_BASE
static constexpr FeeUnit32 TRANSACTION_FEE_BASE
Definition: Config.h:134
ripple::LoadFeeTrack
Manages the current fee schedule.
Definition: LoadFeeTrack.h:43
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:70
ripple::DROPS_PER_XRP
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
Definition: XRPAmount.h:244
ripple::Config::FEE_DEFAULT
XRPAmount FEE_DEFAULT
Definition: Config.h:167
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Fees::units
FeeUnit32 units
Definition: ReadView.h:51
ripple::Fees::base
XRPAmount base
Definition: ReadView.h:50
ripple::XRPAmount
Definition: XRPAmount.h:46