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 <test/jtx.h>
21 #include <ripple/app/misc/FeeVote.h>
22 #include <ripple/basics/BasicConfig.h>
23 
24 namespace ripple {
25 namespace test {
26 
27 class FeeVote_test :
28  public beast::unit_test::suite
29 {
30  void testSetup()
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  });
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  });
59  // Illegal values are ignored, and the defaults left unchanged
60  auto setup = setup_FeeVote(config);
61  BEAST_EXPECT(setup.reference_fee == 10);
62  BEAST_EXPECT(setup.account_reserve == 20 * DROPS_PER_XRP);
63  BEAST_EXPECT(setup.owner_reserve == 5 * DROPS_PER_XRP);
64  }
65  {
66  Section config;
67  config.append({
68  "reference_fee = -50",
69  "account_reserve = -1234567",
70  "owner_reserve = -1234"
71  });
72  // Illegal values are ignored, and the defaults left unchanged
73  auto setup = setup_FeeVote(config);
74  BEAST_EXPECT(setup.reference_fee == 10);
75  BEAST_EXPECT(setup.account_reserve == static_cast<std::uint32_t>(-1234567));
76  BEAST_EXPECT(setup.owner_reserve == static_cast<std::uint32_t>(-1234));
77  }
78  {
79  const auto big64 = std::to_string(static_cast<std::uint64_t>(
81  Section config;
82  config.append({
83  "reference_fee = " + big64,
84  "account_reserve = " + big64,
85  "owner_reserve = " + big64
86  });
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 run() override
96  {
97  testSetup();
98  }
99 };
100 
102 
103 } // test
104 } // ripple
ripple::setup_FeeVote
FeeVote::Setup setup_FeeVote(Section const &section)
Build FeeVote::Setup from a config section.
Definition: FeeVoteImpl.cpp:265
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:41
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:263
ripple::test::FeeVote_test::run
void run() override
Definition: FeeVote_test.cpp:95
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::numeric_limits