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] =
39 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][sfMemoData.jsonName] =
47 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.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfFlags.jsonName] = 13;
68 env(memoExtra,
69 rpc("invalidTransaction",
70 "fails local checks: A memo may contain only MemoType, "
71 "MemoData or MemoFormat fields."));
72 }
73 {
74 // Put a character that is not allowed in a URL in a MemoType field.
75 JTx memoBadChar = makeJtxWithMemo();
76 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoType.jsonName] =
77 strHex(std::string_view("ONE<INFINITY"));
78 env(memoBadChar,
79 rpc("invalidTransaction",
80 "fails local checks: The MemoType and MemoFormat fields "
81 "may only contain characters that are allowed in URLs "
82 "under RFC 3986."));
83 }
84 {
85 // Put a character that is not allowed in a URL in a MemoData field.
86 // That's okay.
87 JTx memoLegitChar = makeJtxWithMemo();
88 memoLegitChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoData.jsonName] =
89 strHex(std::string_view("ONE<INFINITY"));
90 env(memoLegitChar);
91 }
92 {
93 // Put a character that is not allowed in a URL in a MemoFormat.
94 JTx memoBadChar = makeJtxWithMemo();
95 memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfMemoFormat.jsonName] =
96 strHex(std::string_view("NoBraces{}InURL"));
97 env(memoBadChar,
98 rpc("invalidTransaction",
99 "fails local checks: The MemoType and MemoFormat fields "
100 "may only contain characters that are allowed in URLs "
101 "under RFC 3986."));
102 }
103 }
104
105 //--------------------------------------------------------------------------
106
107 void
108 run() override
109 {
110 testMemos();
111 }
112};
113
114BEAST_DEFINE_TESTSUITE(Memo, protocol, xrpl);
115
116} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:150
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