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