rippled
ValidatorInfo_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Dev Null Productions, LLC
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/beast/unit_test.h>
21 #include <ripple/core/ConfigSections.h>
22 #include <ripple/protocol/jss.h>
23 #include <test/jtx.h>
24 
25 #include <string>
26 #include <vector>
27 
28 namespace ripple {
29 namespace test {
30 
31 class ValidatorInfo_test : public beast::unit_test::suite
32 {
33 public:
34  void
36  {
37  testcase("Errors");
38 
39  using namespace jtx;
40  {
41  Env env(*this);
42  auto const info = env.rpc("validator_info");
43  BEAST_EXPECT(
44  info[jss::result][jss::error_message] == "not a validator");
45  }
46  }
47 
48  void
50  {
51  using namespace test::jtx;
52  Env env{*this, envconfig(no_admin)};
53  auto const info = env.rpc("validator_info")[jss::result];
54  BEAST_EXPECT(info.isNull());
55  }
56 
57  void
59  {
60  testcase("Lookup");
61 
62  using namespace jtx;
63  const std::vector<std::string> tokenBlob = {
64  " "
65  "eyJ2YWxpZGF0aW9uX3NlY3JldF9rZXkiOiI5ZWQ0NWY4NjYyNDFjYzE4YTI3NDdiNT"
66  "\n",
67  " \tQzODdjMDYyNTkwNzk3MmY0ZTcxOTAyMzFmYWE5Mzc0NTdmYTlkYWY2IiwibWFua"
68  "WZl "
69  " \n",
70  "\tc3QiOiJKQUFBQUFGeEllMUZ0d21pbXZHdEgyaUNjTUpxQzlnVkZLaWxHZncxL3ZD"
71  "eE"
72  "\n",
73  "\t "
74  "hYWExwbGMyR25NaEFrRTFhZ3FYeEJ3RHdEYklENk9NU1l1TTBGREFscEFnTms4U0tG"
75  "\t "
76  "\t\n",
77  "bjdNTzJmZGtjd1JRSWhBT25ndTlzQUtxWFlvdUorbDJWMFcrc0FPa1ZCK1pSUzZQU2"
78  "\n",
79  "hsSkFmVXNYZkFpQnNWSkdlc2FhZE9KYy9hQVpva1MxdnltR21WcmxIUEtXWDNZeXd1"
80  "\n",
81  "NmluOEhBU1FLUHVnQkQ2N2tNYVJGR3ZtcEFUSGxHS0pkdkRGbFdQWXk1QXFEZWRGdj"
82  "\n",
83  "VUSmEydzBpMjFlcTNNWXl3TFZKWm5GT3I3QzBrdzJBaVR6U0NqSXpkaXRROD0ifQ=="
84  "\n"};
85 
86  std::string const master_key =
87  "nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
88  std::string const ephemeral_key =
89  "n9KsDYGKhABVc4wK5u3MnVhgPinyJimyKGpr9VJYuBaY8EnJXR2x";
90  std::string const manifest =
91  "JAAAAAFxIe1FtwmimvGtH2iCcMJqC9gVFKilGfw1/"
92  "vCxHXXLplc2GnMhAkE1agqXxBwDwDbID6OMSYuM0FDAlpAgNk8SKFn7MO2fdkcwRQI"
93  "hAOngu9sAKqXYouJ+l2V0W+sAOkVB+ZRS6PShlJAfUsXfAiBsVJGesaadOJc/"
94  "aAZokS1vymGmVrlHPKWX3Yywu6in8HASQKPugBD67kMaRFGvmpATHlGKJdvDFlWPYy"
95  "5AqDedFv5TJa2w0i21eq3MYywLVJZnFOr7C0kw2AiTzSCjIzditQ8=";
96 
97  Env env{*this, envconfig([&tokenBlob](std::unique_ptr<Config> cfg) {
98  cfg->section(SECTION_VALIDATOR_TOKEN).append(tokenBlob);
99  return cfg;
100  })};
101  {
102  auto const info = env.rpc("validator_info");
103  BEAST_EXPECT(info[jss::result][jss::status] == "success");
104  BEAST_EXPECT(info[jss::result][jss::seq] == 1);
105  BEAST_EXPECT(info[jss::result][jss::master_key] == master_key);
106  BEAST_EXPECT(info[jss::result][jss::manifest] == manifest);
107  BEAST_EXPECT(
108  info[jss::result][jss::ephemeral_key] == ephemeral_key);
109  }
110  }
111 
112  void
113  run() override
114  {
115  testErrors();
116  testPrivileges();
117  testLookup();
118  }
119 };
120 
121 BEAST_DEFINE_TESTSUITE(ValidatorInfo, rpc, ripple);
122 } // namespace test
123 } // namespace ripple
ripple::test::ValidatorInfo_test::testLookup
void testLookup()
Definition: ValidatorInfo_test.cpp:58
ripple::test::ValidatorInfo_test
Definition: ValidatorInfo_test.cpp:31
std::string
STL class.
ripple::HashPrefix::manifest
@ manifest
Manifest.
vector
ripple::test::jtx::envconfig
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:49
ripple::test::jtx::no_admin
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition: envconfig.cpp:79
ripple::test::ValidatorInfo_test::testPrivileges
void testPrivileges()
Definition: ValidatorInfo_test.cpp:49
ripple::test::ValidatorInfo_test::run
void run() override
Definition: ValidatorInfo_test.cpp:113
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::unique_ptr
STL class.
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
ripple::test::ValidatorInfo_test::testErrors
void testErrors()
Definition: ValidatorInfo_test.cpp:35
ripple::test::jtx::Env::rpc
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition: Env.h:687
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)
string