xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
protocol
STInteger_test.cpp
1
#include <xrpl/beast/unit_test/suite.h>
2
#include <xrpl/protocol/LedgerFormats.h>
3
#include <xrpl/protocol/Permissions.h>
4
#include <xrpl/protocol/SField.h>
5
#include <xrpl/protocol/STInteger.h>
6
#include <xrpl/protocol/TxFormats.h>
7
8
namespace
xrpl
{
9
10
struct
STInteger_test
:
public
beast::unit_test::Suite
11
{
12
void
13
testUInt8
()
14
{
15
testcase
(
"UInt8"
);
16
STUInt8
const
u8(255);
17
BEAST_EXPECT(u8.
value
() == 255);
18
BEAST_EXPECT(u8.
getText
() ==
"255"
);
19
BEAST_EXPECT(u8.
getSType
() == STI_UINT8);
20
BEAST_EXPECT(u8.
getJson
(
JsonOptions::Values::None
) == 255);
21
22
// there is some special handling for sfTransactionResult
23
STUInt8
const
tr(sfTransactionResult, 0);
24
BEAST_EXPECT(tr.
value
() == 0);
25
BEAST_EXPECT(
26
tr.
getText
() ==
"The transaction was applied. Only final in a validated ledger."
);
27
BEAST_EXPECT(tr.
getSType
() == STI_UINT8);
28
BEAST_EXPECT(tr.
getJson
(
JsonOptions::Values::None
) ==
"tesSUCCESS"
);
29
30
// invalid transaction result
31
STUInt8
const
tr2(sfTransactionResult, 255);
32
BEAST_EXPECT(tr2.
value
() == 255);
33
BEAST_EXPECT(tr2.
getText
() ==
"255"
);
34
BEAST_EXPECT(tr2.
getSType
() == STI_UINT8);
35
BEAST_EXPECT(tr2.
getJson
(
JsonOptions::Values::None
) == 255);
36
}
37
38
void
39
testUInt16
()
40
{
41
testcase
(
"UInt16"
);
42
STUInt16
const
u16(65535);
43
BEAST_EXPECT(u16.
value
() == 65535);
44
BEAST_EXPECT(u16.
getText
() ==
"65535"
);
45
BEAST_EXPECT(u16.
getSType
() == STI_UINT16);
46
BEAST_EXPECT(u16.
getJson
(
JsonOptions::Values::None
) == 65535);
47
48
// there is some special handling for sfLedgerEntryType
49
STUInt16
const
let(sfLedgerEntryType, ltACCOUNT_ROOT);
50
BEAST_EXPECT(let.
value
() == ltACCOUNT_ROOT);
51
BEAST_EXPECT(let.
getText
() ==
"AccountRoot"
);
52
BEAST_EXPECT(let.
getSType
() == STI_UINT16);
53
BEAST_EXPECT(let.
getJson
(
JsonOptions::Values::None
) ==
"AccountRoot"
);
54
55
// there is some special handling for sfTransactionType
56
STUInt16
const
tlt(sfTransactionType, ttPAYMENT);
57
BEAST_EXPECT(tlt.
value
() == ttPAYMENT);
58
BEAST_EXPECT(tlt.
getText
() ==
"Payment"
);
59
BEAST_EXPECT(tlt.
getSType
() == STI_UINT16);
60
BEAST_EXPECT(tlt.
getJson
(
JsonOptions::Values::None
) ==
"Payment"
);
61
}
62
63
void
64
testUInt32
()
65
{
66
testcase
(
"UInt32"
);
67
STUInt32
const
u32(4'294'967'295u);
68
BEAST_EXPECT(u32.
value
() == 4'294'967'295u);
69
BEAST_EXPECT(u32.
getText
() ==
"4294967295"
);
70
BEAST_EXPECT(u32.
getSType
() == STI_UINT32);
71
BEAST_EXPECT(u32.
getJson
(
JsonOptions::Values::None
) == 4'294'967'295u);
72
73
// there is some special handling for sfPermissionValue
74
STUInt32
const
pv(sfPermissionValue, ttPAYMENT + 1);
75
BEAST_EXPECT(pv.
value
() == ttPAYMENT + 1);
76
BEAST_EXPECT(pv.
getText
() ==
"Payment"
);
77
BEAST_EXPECT(pv.
getSType
() == STI_UINT32);
78
BEAST_EXPECT(pv.
getJson
(
JsonOptions::Values::None
) ==
"Payment"
);
79
STUInt32
const
pv2(sfPermissionValue, PaymentMint);
80
BEAST_EXPECT(pv2.
value
() == PaymentMint);
81
BEAST_EXPECT(pv2.
getText
() ==
"PaymentMint"
);
82
BEAST_EXPECT(pv2.
getSType
() == STI_UINT32);
83
BEAST_EXPECT(pv2.
getJson
(
JsonOptions::Values::None
) ==
"PaymentMint"
);
84
}
85
86
void
87
testUInt64
()
88
{
89
testcase
(
"UInt64"
);
90
STUInt64
const
u64(0xFFFFFFFFFFFFFFFFull);
91
BEAST_EXPECT(u64.
value
() == 0xFFFFFFFFFFFFFFFFull);
92
BEAST_EXPECT(u64.
getText
() ==
"18446744073709551615"
);
93
BEAST_EXPECT(u64.
getSType
() == STI_UINT64);
94
95
// By default, getJson returns hex string
96
auto
jsonVal = u64.
getJson
(
JsonOptions::Values::None
);
97
BEAST_EXPECT(jsonVal.isString());
98
BEAST_EXPECT(jsonVal.asString() ==
"ffffffffffffffff"
);
99
100
STUInt64
const
u642(sfMaximumAmount, 0xFFFFFFFFFFFFFFFFull);
101
BEAST_EXPECT(u642.
value
() == 0xFFFFFFFFFFFFFFFFull);
102
BEAST_EXPECT(u642.
getText
() ==
"18446744073709551615"
);
103
BEAST_EXPECT(u642.
getSType
() == STI_UINT64);
104
BEAST_EXPECT(u642.
getJson
(
JsonOptions::Values::None
) ==
"18446744073709551615"
);
105
}
106
107
void
108
testInt32
()
109
{
110
testcase
(
"Int32"
);
111
{
112
int
const
minInt32 = -2147483648;
113
STInt32
const
i32(minInt32);
114
BEAST_EXPECT(i32.
value
() == minInt32);
115
BEAST_EXPECT(i32.
getText
() ==
"-2147483648"
);
116
BEAST_EXPECT(i32.
getSType
() == STI_INT32);
117
BEAST_EXPECT(i32.
getJson
(
JsonOptions::Values::None
) == minInt32);
118
}
119
120
{
121
int
const
maxInt32 = 2147483647;
122
STInt32
const
i32(maxInt32);
123
BEAST_EXPECT(i32.
value
() == maxInt32);
124
BEAST_EXPECT(i32.
getText
() ==
"2147483647"
);
125
BEAST_EXPECT(i32.
getSType
() == STI_INT32);
126
BEAST_EXPECT(i32.
getJson
(
JsonOptions::Values::None
) == maxInt32);
127
}
128
}
129
130
void
131
run
()
override
132
{
133
testUInt8
();
134
testUInt16
();
135
testUInt32
();
136
testUInt64
();
137
testInt32
();
138
}
139
};
140
141
BEAST_DEFINE_TESTSUITE
(
STInteger
,
protocol
,
xrpl
);
142
143
}
// namespace xrpl
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::STInteger
Definition
STInteger.h:18
xrpl::STInteger::value
value_type value() const noexcept
Definition
STInteger.h:132
xrpl::STInteger::getSType
SerializedTypeID getSType() const override
xrpl::STInteger::getJson
json::Value getJson(JsonOptions) const override
xrpl::STInteger::getText
std::string getText() const override
protocol
Definition
LedgerNodeHelpers.h:9
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::STUInt64
STInteger< std::uint64_t > STUInt64
Definition
STInteger.h:70
xrpl::STUInt16
STInteger< std::uint16_t > STUInt16
Definition
STInteger.h:68
xrpl::STInt32
STInteger< std::int32_t > STInt32
Definition
STInteger.h:72
xrpl::STUInt8
STInteger< unsigned char > STUInt8
Definition
STInteger.h:67
xrpl::STUInt32
STInteger< std::uint32_t > STUInt32
Definition
STInteger.h:69
xrpl::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
xrpl::JsonOptions::Values::None
@ None
Definition
STBase.h:27
xrpl::STInteger_test
Definition
STInteger_test.cpp:11
xrpl::STInteger_test::testInt32
void testInt32()
Definition
STInteger_test.cpp:108
xrpl::STInteger_test::testUInt64
void testUInt64()
Definition
STInteger_test.cpp:87
xrpl::STInteger_test::testUInt8
void testUInt8()
Definition
STInteger_test.cpp:13
xrpl::STInteger_test::testUInt32
void testUInt32()
Definition
STInteger_test.cpp:64
xrpl::STInteger_test::run
void run() override
Runs the suite.
Definition
STInteger_test.cpp:131
xrpl::STInteger_test::testUInt16
void testUInt16()
Definition
STInteger_test.cpp:39
Generated by
1.17.0