rippled
Loading...
Searching...
No Matches
RPCHelpers_test.cpp
1#include <xrpld/rpc/detail/RPCHelpers.h>
2
3#include <xrpl/beast/unit_test.h>
4#include <xrpl/protocol/jss.h>
5
6namespace ripple {
7namespace test {
8
10{
11public:
12 void
14 {
15 testcase("ChooseLedgerEntryType");
16
17 // Test no type.
19 auto result = RPC::chooseLedgerEntryType(tx);
20 BEAST_EXPECT(result.first == RPC::Status::OK);
21 BEAST_EXPECT(result.second == 0);
22
23 // Test empty type.
24 tx[jss::type] = "";
25 result = RPC::chooseLedgerEntryType(tx);
26 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
27 BEAST_EXPECT(result.second == 0);
28
29 // Test type using canonical name in mixedcase.
30 tx[jss::type] = "MPTokenIssuance";
31 result = RPC::chooseLedgerEntryType(tx);
32 BEAST_EXPECT(result.first == RPC::Status::OK);
33 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
34
35 // Test type using canonical name in lowercase.
36 tx[jss::type] = "mptokenissuance";
37 result = RPC::chooseLedgerEntryType(tx);
38 BEAST_EXPECT(result.first == RPC::Status::OK);
39 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
40
41 // Test type using RPC name with exact match.
42 tx[jss::type] = "mpt_issuance";
43 result = RPC::chooseLedgerEntryType(tx);
44 BEAST_EXPECT(result.first == RPC::Status::OK);
45 BEAST_EXPECT(result.second == ltMPTOKEN_ISSUANCE);
46
47 // Test type using RPC name with inexact match.
48 tx[jss::type] = "MPT_Issuance";
49 result = RPC::chooseLedgerEntryType(tx);
50 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
51 BEAST_EXPECT(result.second == 0);
52
53 // Test invalid type.
54 tx[jss::type] = 1234;
55 result = RPC::chooseLedgerEntryType(tx);
56 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
57 BEAST_EXPECT(result.second == 0);
58
59 // Test unknown type.
60 tx[jss::type] = "unknown";
61 result = RPC::chooseLedgerEntryType(tx);
62 BEAST_EXPECT(result.first == RPC::Status{rpcINVALID_PARAMS});
63 BEAST_EXPECT(result.second == 0);
64 }
65
66 void
67 run() override
68 {
70 }
71};
72
73BEAST_DEFINE_TESTSUITE(RPCHelpers, rpc, ripple);
74
75} // namespace test
76} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void run() override
Runs the suite.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:16
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Status represents the results of an operation that might fail.
Definition Status.h:21
static constexpr Code OK
Definition Status.h:27