rippled
Loading...
Searching...
No Matches
ManifestRPC_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 <xrpld/core/ConfigSections.h>
22#include <xrpl/beast/unit_test.h>
23#include <xrpl/protocol/jss.h>
24
25#include <string>
26
27namespace ripple {
28namespace test {
29
31{
32public:
33 void
35 {
36 testcase("Errors");
37
38 using namespace jtx;
39 Env env(*this);
40 {
41 // manifest with no public key
42 auto const info = env.rpc("json", "manifest", "{ }");
43 BEAST_EXPECT(
44 info[jss::result][jss::error_message] ==
45 "Missing field 'public_key'.");
46 }
47 {
48 // manifest with manlformed public key
49 auto const info = env.rpc(
50 "json",
51 "manifest",
52 "{ \"public_key\": "
53 "\"abcdef12345\"}");
54 BEAST_EXPECT(
55 info[jss::result][jss::error_message] == "Invalid parameters.");
56 }
57 }
58
59 void
61 {
62 testcase("Lookup");
63
64 using namespace jtx;
65 std::string const key =
66 "n949f75evCHwgyP4fPVgaHqNHxUVN15PsJEZ3B3HnXPcPjcZAoy7";
67 Env env{*this, envconfig([&key](std::unique_ptr<Config> cfg) {
68 cfg->section(SECTION_VALIDATORS).append(key);
69 return cfg;
70 })};
71 {
72 auto const info = env.rpc(
73 "json",
74 "manifest",
75 "{ \"public_key\": "
76 "\"" +
77 key + "\"}");
78 BEAST_EXPECT(info[jss::result][jss::requested] == key);
79 BEAST_EXPECT(info[jss::result][jss::status] == "success");
80 }
81 }
82
83 void
84 run() override
85 {
86 testErrors();
87 testLookup();
88 }
89};
90
91BEAST_DEFINE_TESTSUITE(ManifestRPC, rpc, ripple);
92} // namespace test
93} // namespace ripple
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
void run() override
Runs the suite.
A transaction testing environment.
Definition: Env.h:117
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition: Env.h:764
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: rpc.h:34
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:54
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26