rippled
Loading...
Searching...
No Matches
Memo_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/basics/strHex.h>
4
5namespace xrpl {
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][sfMemoData.jsonName] = std::string(2020, '0');
39 env(memoSize,
40 rpc("invalidTransaction",
41 "fails local checks: The memo exceeds the maximum allowed "
42 "size."));
43
44 // This memo is just barely small enough.
45 memoSize.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoData.jsonName] = std::string(2018, '1');
46 env(memoSize);
47 }
48 {
49 // Put a non-Memo in the Memos array.
50 JTx memoNonMemo = noop(alice);
51 auto& jv = memoNonMemo.jv;
52 auto& ma = jv[sfMemos.jsonName];
53 auto& mi = ma[ma.size()];
54 auto& m = mi[sfCreatedNode.jsonName]; // CreatedNode in Memos
55 m[sfMemoData.jsonName] = "3030303030";
56
57 env(memoNonMemo,
58 rpc("invalidTransaction",
59 "fails local checks: A memo array may contain only Memo "
60 "objects."));
61 }
62 {
63 // Put an invalid field in a Memo object.
64 JTx memoExtra = makeJtxWithMemo();
65 memoExtra.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfFlags.jsonName] = 13;
66 env(memoExtra,
67 rpc("invalidTransaction",
68 "fails local checks: A memo may contain only MemoType, "
69 "MemoData or MemoFormat fields."));
70 }
71 {
72 // Put a character that is not allowed in a URL in a MemoType field.
73 JTx memoBadChar = makeJtxWithMemo();
74 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoType.jsonName] =
75 strHex(std::string_view("ONE<INFINITY"));
76 env(memoBadChar,
77 rpc("invalidTransaction",
78 "fails local checks: The MemoType and MemoFormat fields "
79 "may only contain characters that are allowed in URLs "
80 "under RFC 3986."));
81 }
82 {
83 // Put a character that is not allowed in a URL in a MemoData field.
84 // That's okay.
85 JTx memoLegitChar = makeJtxWithMemo();
86 memoLegitChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoData.jsonName] =
87 strHex(std::string_view("ONE<INFINITY"));
88 env(memoLegitChar);
89 }
90 {
91 // Put a character that is not allowed in a URL in a MemoFormat.
92 JTx memoBadChar = makeJtxWithMemo();
93 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoFormat.jsonName] =
94 strHex(std::string_view("NoBraces{}InURL"));
95 env(memoBadChar,
96 rpc("invalidTransaction",
97 "fails local checks: The MemoType and MemoFormat fields "
98 "may only contain characters that are allowed in URLs "
99 "under RFC 3986."));
100 }
101 }
102
103 //--------------------------------------------------------------------------
104
105 void
106 run() override
107 {
108 testMemos();
109 }
110};
111
112BEAST_DEFINE_TESTSUITE(Memo, protocol, xrpl);
113
114} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:147
void run() override
Runs the suite.
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