rippled
ServerInfo_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2016 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/beast/unit_test.h>
21 #include <ripple/protocol/jss.h>
22 #include <test/jtx.h>
23 
24 #include <boost/format.hpp>
25 
26 namespace ripple {
27 
28 namespace test {
29 
30 namespace validator_data {
31 static auto const public_key =
32  "nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
33 
34 static auto const token =
35  "eyJ2YWxpZGF0aW9uX3NlY3JldF9rZXkiOiI5ZWQ0NWY4NjYyNDFjYzE4YTI3NDdiNT\n"
36  "QzODdjMDYyNTkwNzk3MmY0ZTcxOTAyMzFmYWE5Mzc0NTdmYTlkYWY2IiwibWFuaWZl\n"
37  "c3QiOiJKQUFBQUFGeEllMUZ0d21pbXZHdEgyaUNjTUpxQzlnVkZLaWxHZncxL3ZDeE\n"
38  "hYWExwbGMyR25NaEFrRTFhZ3FYeEJ3RHdEYklENk9NU1l1TTBGREFscEFnTms4U0tG\n"
39  "bjdNTzJmZGtjd1JRSWhBT25ndTlzQUtxWFlvdUorbDJWMFcrc0FPa1ZCK1pSUzZQU2\n"
40  "hsSkFmVXNYZkFpQnNWSkdlc2FhZE9KYy9hQVpva1MxdnltR21WcmxIUEtXWDNZeXd1\n"
41  "NmluOEhBU1FLUHVnQkQ2N2tNYVJGR3ZtcEFUSGxHS0pkdkRGbFdQWXk1QXFEZWRGdj\n"
42  "VUSmEydzBpMjFlcTNNWXl3TFZKWm5GT3I3QzBrdzJBaVR6U0NqSXpkaXRROD0ifQ==\n";
43 } // namespace validator_data
44 
45 class ServerInfo_test : public beast::unit_test::suite
46 {
47 public:
50  {
51  auto p = std::make_unique<Config>();
52  boost::format toLoad(R"rippleConfig(
53 [validator_token]
54 %1%
55 
56 [validators]
57 %2%
58 )rippleConfig");
59 
60  p->loadFromString(boost::str(
62 
64 
65  return p;
66  }
67 
68  void
70  {
71  using namespace test::jtx;
72 
73  {
74  Env env(*this);
75  auto const result = env.rpc("server_info");
76  BEAST_EXPECT(!result[jss::result].isMember(jss::error));
77  BEAST_EXPECT(result[jss::result][jss::status] == "success");
78  BEAST_EXPECT(result[jss::result].isMember(jss::info));
79  }
80  {
81  Env env(*this, makeValidatorConfig());
82  auto const result = env.rpc("server_info");
83  BEAST_EXPECT(!result[jss::result].isMember(jss::error));
84  BEAST_EXPECT(result[jss::result][jss::status] == "success");
85  BEAST_EXPECT(result[jss::result].isMember(jss::info));
86  BEAST_EXPECT(
87  result[jss::result][jss::info][jss::pubkey_validator] ==
89  }
90  }
91 
92  void
93  run() override
94  {
96  }
97 };
98 
99 BEAST_DEFINE_TESTSUITE(ServerInfo, app, ripple);
100 
101 } // namespace test
102 } // namespace ripple
ripple::test::validator_data::public_key
static const auto public_key
Definition: ServerInfo_test.cpp:31
ripple::test::validator_data::token
static const auto token
Definition: ServerInfo_test.cpp:34
ripple::test::ServerInfo_test::makeValidatorConfig
static std::unique_ptr< Config > makeValidatorConfig()
Definition: ServerInfo_test.cpp:49
ripple::test::ServerInfo_test::run
void run() override
Definition: ServerInfo_test.cpp:93
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::ServerInfo_test
Definition: ServerInfo_test.cpp:45
std::unique_ptr
STL class.
ripple::test::setupConfigForUnitTests
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition: envconfig.cpp:39
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
ripple::test::ServerInfo_test::testServerInfo
void testServerInfo()
Definition: ServerInfo_test.cpp:69
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)