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  {
33  // defaults
34  Section config;
35  auto setup = setup_FeeVote(config);
36  BEAST_EXPECT(setup.reference_fee == 10);
37  BEAST_EXPECT(setup.account_reserve == 20 * DROPS_PER_XRP);
38  BEAST_EXPECT(setup.owner_reserve == 5 * DROPS_PER_XRP);
39  }
40  {
41  Section config;
42  config.append(
43  {"reference_fee = 50",
44  "account_reserve = 1234567",
45  "owner_reserve = 1234"});
46  auto setup = setup_FeeVote(config);
47  BEAST_EXPECT(setup.reference_fee == 50);
48  BEAST_EXPECT(setup.account_reserve == 1234567);
49  BEAST_EXPECT(setup.owner_reserve == 1234);
50  }
51  {
52  Section config;
53  config.append(
54  {"reference_fee = blah",
55  "account_reserve = yada",
56  "owner_reserve = foo"});
57  // Illegal values are ignored, and the defaults left unchanged
58  auto setup = setup_FeeVote(config);
59  BEAST_EXPECT(setup.reference_fee == 10);
60  BEAST_EXPECT(setup.account_reserve == 20 * DROPS_PER_XRP);
61  BEAST_EXPECT(setup.owner_reserve == 5 * DROPS_PER_XRP);
62  }
63  {
64  Section config;
65  config.append(
66  {"reference_fee = -50",
67  "account_reserve = -1234567",
68  "owner_reserve = -1234"});
69  // Illegal values are ignored, and the defaults left unchanged
70  auto setup = setup_FeeVote(config);
71  BEAST_EXPECT(setup.reference_fee == 10);
72  BEAST_EXPECT(
73  setup.account_reserve == static_cast<std::uint32_t>(-1234567));
74  BEAST_EXPECT(
75  setup.owner_reserve == static_cast<std::uint32_t>(-1234));
76  }
77  {
78  const auto big64 = std::to_string(
79  static_cast<std::uint64_t>(
81  1);
82  Section config;
83  config.append(
84  {"reference_fee = " + big64,
85  "account_reserve = " + big64,
86  "owner_reserve = " + big64});
87  // Illegal values are ignored, and the defaults left unchanged
88  auto setup = setup_FeeVote(config);
89  BEAST_EXPECT(setup.reference_fee == 10);
90  BEAST_EXPECT(setup.account_reserve == 20 * DROPS_PER_XRP);
91  BEAST_EXPECT(setup.owner_reserve == 5 * DROPS_PER_XRP);
92  }
93  }
94 
95  void
96  run() override
97  {
98  testSetup();
99  }
100 };
101 
103 
104 } // namespace test
105 } // namespace ripple
ripple::setup_FeeVote
FeeVote::Setup setup_FeeVote(Section const &section)
Build FeeVote::Setup from a config section.
Definition: FeeVoteImpl.cpp:259
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
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:40
std::to_string
T to_string(T... args)
std::uint32_t
ripple::test::FeeVote_test
Definition: FeeVote_test.cpp:27
ripple::DROPS_PER_XRP
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
Definition: XRPAmount.h:250
ripple::test::FeeVote_test::run
void run() override
Definition: FeeVote_test.cpp:96
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::numeric_limits