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