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
22#include <xrpld/core/ConfigSections.h>
23
24#include <xrpl/beast/unit_test.h>
25#include <xrpl/protocol/jss.h>
26
27#include <string>
28
29namespace ripple {
30namespace test {
31
33{
34public:
35 void
37 {
38 testcase("Errors");
39
40 using namespace jtx;
41 Env env(*this);
42 {
43 // manifest with no public key
44 auto const info = env.rpc("json", "manifest", "{ }");
45 BEAST_EXPECT(
46 info[jss::result][jss::error_message] ==
47 "Missing field 'public_key'.");
48 }
49 {
50 // manifest with manlformed public key
51 auto const info = env.rpc(
52 "json",
53 "manifest",
54 "{ \"public_key\": "
55 "\"abcdef12345\"}");
56 BEAST_EXPECT(
57 info[jss::result][jss::error_message] == "Invalid parameters.");
58 }
59 }
60
61 void
63 {
64 testcase("Lookup");
65
66 using namespace jtx;
67 std::string const key =
68 "n949f75evCHwgyP4fPVgaHqNHxUVN15PsJEZ3B3HnXPcPjcZAoy7";
69 Env env{*this, envconfig([&key](std::unique_ptr<Config> cfg) {
70 cfg->section(SECTION_VALIDATORS).append(key);
71 return cfg;
72 })};
73 {
74 auto const info = env.rpc(
75 "json",
76 "manifest",
77 "{ \"public_key\": "
78 "\"" +
79 key + "\"}");
80 BEAST_EXPECT(info[jss::result][jss::requested] == key);
81 BEAST_EXPECT(info[jss::result][jss::status] == "success");
82 }
83 }
84
85 void
86 run() override
87 {
88 testErrors();
89 testLookup();
90 }
91};
92
93BEAST_DEFINE_TESTSUITE(ManifestRPC, rpc, ripple);
94} // namespace test
95} // namespace ripple
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
void run() override
Runs the suite.
A transaction testing environment.
Definition Env.h:121
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:791
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:35
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:25