xrpld
Loading...
Searching...
No Matches
Submit_test.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/JTx.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/pay.h>
6
7#include <xrpl/basics/strHex.h>
8#include <xrpl/beast/unit_test/suite.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/json/to_string.h>
11#include <xrpl/protocol/Seed.h>
12#include <xrpl/protocol/jss.h>
13
14namespace xrpl::test {
15
17{
18public:
19 void
21 {
22 testcase("fail_hard parameter validation");
23 using namespace jtx;
24 Env env(*this);
25 Account const alice{"alice"};
26 Account const bob{"bob"};
27 env.fund(XRP(10000), alice, bob);
28 env.close();
29
30 // Lambda to test invalid fail_hard parameter types
31 auto testInvalidFailHard = [&](auto const& param) {
32 // Test with tx_blob path
33 {
34 JTx const jt = env.jt(pay(alice, bob, XRP(1)));
35 auto const txBlob = strHex(jt.stx->getSerializer().slice());
36
37 json::Value params;
38 params[jss::tx_blob] = txBlob;
39 params[jss::fail_hard] = param;
40 auto const jrr = env.rpc("json", "submit", to_string(params))[jss::result];
41 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
42 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'fail_hard', not boolean.");
43 }
44
45 // Test with tx_json path (deprecated signing)
46 {
47 json::Value params;
48 params[jss::secret] = toBase58(generateSeed("alice"));
49 params[jss::tx_json] = pay("alice", "bob", XRP(1));
50 params[jss::fail_hard] = param;
51 auto const jrr = env.rpc("json", "submit", to_string(params))[jss::result];
52 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
53 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'fail_hard', not boolean.");
54 }
55 };
56
57 // Test all invalid types
58 testInvalidFailHard("true");
59 testInvalidFailHard("yes");
60 testInvalidFailHard(1);
61 testInvalidFailHard(0);
62 testInvalidFailHard(1.5);
63 testInvalidFailHard(json::Value(json::ValueType::Object));
64 testInvalidFailHard(json::Value(json::ValueType::Array));
65
66 // Valid boolean values should work (not return invalidParams)
67 {
68 JTx const jt = env.jt(pay(alice, bob, XRP(1)));
69 auto const txBlob = strHex(jt.stx->getSerializer().slice());
70
71 json::Value params;
72 params[jss::tx_blob] = txBlob;
73 params[jss::fail_hard] = true;
74 auto const jrr = env.rpc("json", "submit", to_string(params))[jss::result];
75 BEAST_EXPECT(!jrr.isMember(jss::error) || jrr[jss::error] != "invalidParams");
76 }
77 {
78 JTx const jt = env.jt(pay(alice, bob, XRP(1)));
79 auto const txBlob = strHex(jt.stx->getSerializer().slice());
80
81 json::Value params;
82 params[jss::tx_blob] = txBlob;
83 params[jss::fail_hard] = false;
84 auto const jrr = env.rpc("json", "submit", to_string(params))[jss::result];
85 BEAST_EXPECT(!jrr.isMember(jss::error) || jrr[jss::error] != "invalidParams");
86 }
87 }
88
89 void
90 run() override
91 {
93 }
94};
95
97
98} // 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.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
A transaction testing environment.
Definition Env.h:143
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
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:864
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:566
@ Array
array value (ordered list)
Definition json_value.h:25
@ Object
object value (collection of name/value pairs).
Definition json_value.h:26
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:58
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
Execution context for applying a JSON transaction.
Definition JTx.h:23
std::shared_ptr< STTx const > stx
Definition JTx.h:33