rippled
Loading...
Searching...
No Matches
RPCHelpers_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted, provided that the above
7 copyright notice and this permission notice appear in all copies.
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16//==============================================================================
17
18#include <xrpld/rpc/detail/RPCHelpers.h>
19
20#include <xrpl/beast/unit_test.h>
21#include <xrpl/protocol/jss.h>
22
23namespace ripple {
24namespace test {
25
27{
28public:
29 void
31 {
32 testcase("ChooseLedgerEntryType");
33
34 // Test no type.
36 auto result = RPC::chooseLedgerEntryType(tx);
37 BEAST_EXPECT(result.first == RPC::Status::OK);
38 BEAST_EXPECT(result.second == 0);
39
40 // Test empty type.
41 tx[jss::type] = "";
42 result = RPC::chooseLedgerEntryType(tx);
43 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
44 BEAST_EXPECT(result.second == 0);
45
46 // Test type using canonical name in mixedcase.
47 tx[jss::type] = "MPTokenIssuance";
48 result = RPC::chooseLedgerEntryType(tx);
49 BEAST_EXPECT(result.first == RPC::Status::OK);
50 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
51
52 // Test type using canonical name in lowercase.
53 tx[jss::type] = "mptokenissuance";
54 result = RPC::chooseLedgerEntryType(tx);
55 BEAST_EXPECT(result.first == RPC::Status::OK);
56 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
57
58 // Test type using RPC name with exact match.
59 tx[jss::type] = "mpt_issuance";
60 result = RPC::chooseLedgerEntryType(tx);
61 BEAST_EXPECT(result.first == RPC::Status::OK);
62 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
63
64 // Test type using RPC name with inexact match.
65 tx[jss::type] = "MPT_Issuance";
66 result = RPC::chooseLedgerEntryType(tx);
67 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
68 BEAST_EXPECT(result.second == 0);
69
70 // Test invalid type.
71 tx[jss::type] = 1234;
72 result = RPC::chooseLedgerEntryType(tx);
73 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
74 BEAST_EXPECT(result.second == 0);
75
76 // Test unknown type.
77 tx[jss::type] = "unknown";
78 result = RPC::chooseLedgerEntryType(tx);
79 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
80 BEAST_EXPECT(result.second == 0);
81 }
82
83 void
84 run() override
85 {
87 }
88};
89
90BEAST_DEFINE_TESTSUITE(RPCHelpers, app, ripple);
91
92} // namespace test
93} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
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.
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:46
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:931
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Status represents the results of an operation that might fail.
Definition: Status.h:40
static constexpr Code OK
Definition: Status.h:46