rippled
Loading...
Searching...
No Matches
Memo_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/basics/strHex.h>
4
5namespace ripple {
6
8{
9public:
10 void
12 {
13 testcase("Test memos");
14
15 using namespace test::jtx;
16 Account alice{"alice"};
17
18 Env env(*this);
19 env.fund(XRP(10000), alice);
20 env.close();
21
22 // Lambda that returns a valid JTx with a memo that we can hack up.
23 // This is the basis for building tests of invalid states.
24 auto makeJtxWithMemo = [&env, &alice]() {
25 JTx example = noop(alice);
26 memo const exampleMemo{"tic", "tac", "toe"};
27 exampleMemo(env, example);
28 return example;
29 };
30
31 // A valid memo.
32 env(makeJtxWithMemo());
33 env.close();
34
35 {
36 // Make sure that too big a memo is flagged as invalid.
37 JTx memoSize = makeJtxWithMemo();
38 memoSize.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
39 [sfMemoData.jsonName] = std::string(2020, '0');
40 env(memoSize,
41 rpc("invalidTransaction",
42 "fails local checks: The memo exceeds the maximum allowed "
43 "size."));
44
45 // This memo is just barely small enough.
46 memoSize.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
47 [sfMemoData.jsonName] = std::string(2018, '1');
48 env(memoSize);
49 }
50 {
51 // Put a non-Memo in the Memos array.
52 JTx memoNonMemo = noop(alice);
53 auto& jv = memoNonMemo.jv;
54 auto& ma = jv[sfMemos.jsonName];
55 auto& mi = ma[ma.size()];
56 auto& m = mi[sfCreatedNode.jsonName]; // CreatedNode in Memos
57 m[sfMemoData.jsonName] = "3030303030";
58
59 env(memoNonMemo,
60 rpc("invalidTransaction",
61 "fails local checks: A memo array may contain only Memo "
62 "objects."));
63 }
64 {
65 // Put an invalid field in a Memo object.
66 JTx memoExtra = makeJtxWithMemo();
67 memoExtra
68 .jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfFlags.jsonName] =
69 13;
70 env(memoExtra,
71 rpc("invalidTransaction",
72 "fails local checks: A memo may contain only MemoType, "
73 "MemoData or MemoFormat fields."));
74 }
75 {
76 // Put a character that is not allowed in a URL in a MemoType field.
77 JTx memoBadChar = makeJtxWithMemo();
78 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
79 [sfMemoType.jsonName] =
80 strHex(std::string_view("ONE<INFINITY"));
81 env(memoBadChar,
82 rpc("invalidTransaction",
83 "fails local checks: The MemoType and MemoFormat fields "
84 "may only contain characters that are allowed in URLs "
85 "under RFC 3986."));
86 }
87 {
88 // Put a character that is not allowed in a URL in a MemoData field.
89 // That's okay.
90 JTx memoLegitChar = makeJtxWithMemo();
91 memoLegitChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
92 [sfMemoData.jsonName] =
93 strHex(std::string_view("ONE<INFINITY"));
94 env(memoLegitChar);
95 }
96 {
97 // Put a character that is not allowed in a URL in a MemoFormat.
98 JTx memoBadChar = makeJtxWithMemo();
99 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
100 [sfMemoFormat.jsonName] =
101 strHex(std::string_view("NoBraces{}InURL"));
102 env(memoBadChar,
103 rpc("invalidTransaction",
104 "fails local checks: The MemoType and MemoFormat fields "
105 "may only contain characters that are allowed in URLs "
106 "under RFC 3986."));
107 }
108 }
109
110 //--------------------------------------------------------------------------
111
112 void
113 run() override
114 {
115 testMemos();
116 }
117};
118
119BEAST_DEFINE_TESTSUITE(Memo, protocol, ripple);
120
121} // namespace ripple
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:11