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 <test/jtx.h>
21 #include <ripple/beast/unit_test.h>
22 #include <ripple/core/ConfigSections.h>
23 #include <ripple/protocol/jss.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 testErrors()
35  {
36  testcase ("Errors");
37 
38  using namespace jtx;
39  {
40  Env env(*this);
41  auto const info = env.rpc ("validator_info");
42  BEAST_EXPECT(info[jss::result][jss::error_message] ==
43  "not a validator");
44  }
45  }
46 
47  void
49  {
50  using namespace test::jtx;
51  Env env{*this, envconfig(no_admin)};
52  auto const info = env.rpc ("validator_info")[jss::result];
53  BEAST_EXPECT(info.isNull());
54  }
55 
56  void testLookup()
57  {
58  testcase ("Lookup");
59 
60  using namespace jtx;
61  const std::vector<std::string> tokenBlob = {
62  " "
63  "eyJ2YWxpZGF0aW9uX3NlY3JldF9rZXkiOiI5ZWQ0NWY4NjYyNDFjYzE4YTI3NDdiNT\n",
64  " \tQzODdjMDYyNTkwNzk3MmY0ZTcxOTAyMzFmYWE5Mzc0NTdmYTlkYWY2IiwibWFuaWZl "
65  " \n",
66  "\tc3QiOiJKQUFBQUFGeEllMUZ0d21pbXZHdEgyaUNjTUpxQzlnVkZLaWxHZncxL3ZDeE"
67  "\n",
68  "\t "
69  "hYWExwbGMyR25NaEFrRTFhZ3FYeEJ3RHdEYklENk9NU1l1TTBGREFscEFnTms4U0tG\t "
70  "\t\n",
71  "bjdNTzJmZGtjd1JRSWhBT25ndTlzQUtxWFlvdUorbDJWMFcrc0FPa1ZCK1pSUzZQU2\n",
72  "hsSkFmVXNYZkFpQnNWSkdlc2FhZE9KYy9hQVpva1MxdnltR21WcmxIUEtXWDNZeXd1\n",
73  "NmluOEhBU1FLUHVnQkQ2N2tNYVJGR3ZtcEFUSGxHS0pkdkRGbFdQWXk1QXFEZWRGdj\n",
74  "VUSmEydzBpMjFlcTNNWXl3TFZKWm5GT3I3QzBrdzJBaVR6U0NqSXpkaXRROD0ifQ==\n"};
75 
76  std::string const master_key = "nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
77  std::string const ephemeral_key = "n9KsDYGKhABVc4wK5u3MnVhgPinyJimyKGpr9VJYuBaY8EnJXR2x";
78  std::string const manifest = "JAAAAAFxIe1FtwmimvGtH2iCcMJqC9gVFKilGfw1/vCxHXXLplc2GnMhAkE1agqXxBwDwDbID6OMSYuM0FDAlpAgNk8SKFn7MO2fdkcwRQIhAOngu9sAKqXYouJ+l2V0W+sAOkVB+ZRS6PShlJAfUsXfAiBsVJGesaadOJc/aAZokS1vymGmVrlHPKWX3Yywu6in8HASQKPugBD67kMaRFGvmpATHlGKJdvDFlWPYy5AqDedFv5TJa2w0i21eq3MYywLVJZnFOr7C0kw2AiTzSCjIzditQ8=";
79 
80  Env env{
81  *this,
82  envconfig([&tokenBlob](std::unique_ptr<Config> cfg) {
83  cfg->section(SECTION_VALIDATOR_TOKEN).append(tokenBlob);
84  return cfg;
85  })
86  };
87  {
88  auto const info = env.rpc ("validator_info");
89  BEAST_EXPECT(info[jss::result][jss::status] == "success");
90  BEAST_EXPECT(info[jss::result][jss::seq] == 1);
91  BEAST_EXPECT(info[jss::result][jss::master_key] == master_key);
92  BEAST_EXPECT(info[jss::result][jss::manifest] == manifest);
93  BEAST_EXPECT(info[jss::result][jss::ephemeral_key] == ephemeral_key);
94  BEAST_EXPECT(info[jss::result][jss::domain] == "");
95  }
96  }
97 
98  void run() override
99  {
100  testErrors();
101  testPrivileges();
102  testLookup();
103  }
104 };
105 
106 BEAST_DEFINE_TESTSUITE(ValidatorInfo,rpc,ripple);
107 }
108 }
ripple::test::ValidatorInfo_test::testLookup
void testLookup()
Definition: ValidatorInfo_test.cpp:56
ripple::test::ValidatorInfo_test
Definition: ValidatorInfo_test.cpp:31
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
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:52
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:69
ripple::test::ValidatorInfo_test::testPrivileges
void testPrivileges()
Definition: ValidatorInfo_test.cpp:48
ripple::test::ValidatorInfo_test::run
void run() override
Definition: ValidatorInfo_test.cpp:98
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:117
ripple::test::ValidatorInfo_test::testErrors
void testErrors()
Definition: ValidatorInfo_test.cpp:34
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:688
string