rippled
FeeVote_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2019 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/FeeVote.h>
21 #include <ripple/basics/BasicConfig.h>
22 #include <test/jtx.h>
23 
24 namespace ripple {
25 namespace test {
26 
27 class FeeVote_test : public beast::unit_test::suite
28 {
29  void
31  {
32  FeeSetup const defaultSetup;
33  {
34  // defaults
35  Section config;
36  auto setup = setup_FeeVote(config);
37  BEAST_EXPECT(setup.reference_fee == defaultSetup.reference_fee);
38  BEAST_EXPECT(setup.account_reserve == defaultSetup.account_reserve);
39  BEAST_EXPECT(setup.owner_reserve == defaultSetup.owner_reserve);
40  }
41  {
42  Section config;
43  config.append(
44  {"reference_fee = 50",
45  "account_reserve = 1234567",
46  "owner_reserve = 1234"});
47  auto setup = setup_FeeVote(config);
48  BEAST_EXPECT(setup.reference_fee == 50);
49  BEAST_EXPECT(setup.account_reserve == 1234567);
50  BEAST_EXPECT(setup.owner_reserve == 1234);
51  }
52  {
53  Section config;
54  config.append(
55  {"reference_fee = blah",
56  "account_reserve = yada",
57  "owner_reserve = foo"});
58  // Illegal values are ignored, and the defaults left unchanged
59  auto setup = setup_FeeVote(config);
60  BEAST_EXPECT(setup.reference_fee == defaultSetup.reference_fee);
61  BEAST_EXPECT(setup.account_reserve == defaultSetup.account_reserve);
62  BEAST_EXPECT(setup.owner_reserve == defaultSetup.owner_reserve);
63  }
64  {
65  Section config;
66  config.append(
67  {"reference_fee = -50",
68  "account_reserve = -1234567",
69  "owner_reserve = -1234"});
70  // Illegal values are ignored, and the defaults left unchanged
71  auto setup = setup_FeeVote(config);
72  BEAST_EXPECT(setup.reference_fee == defaultSetup.reference_fee);
73  BEAST_EXPECT(
74  setup.account_reserve == static_cast<std::uint32_t>(-1234567));
75  BEAST_EXPECT(
76  setup.owner_reserve == static_cast<std::uint32_t>(-1234));
77  }
78  {
79  const auto big64 = std::to_string(
80  static_cast<std::uint64_t>(
82  1);
83  Section config;
84  config.append(
85  {"reference_fee = " + big64,
86  "account_reserve = " + big64,
87  "owner_reserve = " + big64});
88  // Illegal values are ignored, and the defaults left unchanged
89  auto setup = setup_FeeVote(config);
90  BEAST_EXPECT(setup.reference_fee == defaultSetup.reference_fee);
91  BEAST_EXPECT(setup.account_reserve == defaultSetup.account_reserve);
92  BEAST_EXPECT(setup.owner_reserve == defaultSetup.owner_reserve);
93  }
94  }
95 
96  void
97  run() override
98  {
99  testSetup();
100  }
101 };
102 
104 
105 } // namespace test
106 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::FeeSetup::reference_fee
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition: Config.h:72
ripple::FeeVote
Manager to process fee votes.
Definition: FeeVote.h:32
ripple::test::FeeVote_test::testSetup
void testSetup()
Definition: FeeVote_test.cpp:30
ripple::Section::append
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
Definition: BasicConfig.cpp:38
std::to_string
T to_string(T... args)
ripple::setup_FeeVote
FeeSetup setup_FeeVote(Section const &section)
Definition: Config.cpp:1031
ripple::FeeSetup::account_reserve
XRPAmount account_reserve
The account reserve requirement in drops.
Definition: Config.h:75
std::uint32_t
ripple::test::FeeVote_test
Definition: FeeVote_test.cpp:27
ripple::test::FeeVote_test::run
void run() override
Definition: FeeVote_test.cpp:97
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::FeeSetup::owner_reserve
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition: Config.h:78
ripple::FeeSetup
Fee schedule for startup / standalone, and to vote for.
Definition: Config.h:69
std::numeric_limits
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)