rippled
Loading...
Searching...
No Matches
STInteger_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2025 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/beast/unit_test.h>
21#include <xrpl/protocol/LedgerFormats.h>
22#include <xrpl/protocol/Permissions.h>
23#include <xrpl/protocol/STInteger.h>
24#include <xrpl/protocol/TxFormats.h>
25
26namespace ripple {
27
29{
30 void
32 {
33 STUInt8 u8(255);
34 BEAST_EXPECT(u8.value() == 255);
35 BEAST_EXPECT(u8.getText() == "255");
36 BEAST_EXPECT(u8.getSType() == STI_UINT8);
37 BEAST_EXPECT(u8.getJson(JsonOptions::none) == 255);
38
39 // there is some special handling for sfTransactionResult
40 STUInt8 tr(sfTransactionResult, 0);
41 BEAST_EXPECT(tr.value() == 0);
42 BEAST_EXPECT(
43 tr.getText() ==
44 "The transaction was applied. Only final in a validated ledger.");
45 BEAST_EXPECT(tr.getSType() == STI_UINT8);
46 BEAST_EXPECT(tr.getJson(JsonOptions::none) == "tesSUCCESS");
47
48 // invalid transaction result
49 STUInt8 tr2(sfTransactionResult, 255);
50 BEAST_EXPECT(tr2.value() == 255);
51 BEAST_EXPECT(tr2.getText() == "255");
52 BEAST_EXPECT(tr2.getSType() == STI_UINT8);
53 BEAST_EXPECT(tr2.getJson(JsonOptions::none) == 255);
54 }
55
56 void
58 {
59 STUInt16 u16(65535);
60 BEAST_EXPECT(u16.value() == 65535);
61 BEAST_EXPECT(u16.getText() == "65535");
62 BEAST_EXPECT(u16.getSType() == STI_UINT16);
63 BEAST_EXPECT(u16.getJson(JsonOptions::none) == 65535);
64
65 // there is some special handling for sfLedgerEntryType
66 STUInt16 let(sfLedgerEntryType, ltACCOUNT_ROOT);
67 BEAST_EXPECT(let.value() == ltACCOUNT_ROOT);
68 BEAST_EXPECT(let.getText() == "AccountRoot");
69 BEAST_EXPECT(let.getSType() == STI_UINT16);
70 BEAST_EXPECT(let.getJson(JsonOptions::none) == "AccountRoot");
71
72 // there is some special handling for sfTransactionType
73 STUInt16 tlt(sfTransactionType, ttPAYMENT);
74 BEAST_EXPECT(tlt.value() == ttPAYMENT);
75 BEAST_EXPECT(tlt.getText() == "Payment");
76 BEAST_EXPECT(tlt.getSType() == STI_UINT16);
77 BEAST_EXPECT(tlt.getJson(JsonOptions::none) == "Payment");
78 }
79
80 void
82 {
83 STUInt32 u32(4'294'967'295u);
84 BEAST_EXPECT(u32.value() == 4'294'967'295u);
85 BEAST_EXPECT(u32.getText() == "4294967295");
86 BEAST_EXPECT(u32.getSType() == STI_UINT32);
87 BEAST_EXPECT(u32.getJson(JsonOptions::none) == 4'294'967'295u);
88
89 // there is some special handling for sfPermissionValue
90 STUInt32 pv(sfPermissionValue, ttPAYMENT + 1);
91 BEAST_EXPECT(pv.value() == ttPAYMENT + 1);
92 BEAST_EXPECT(pv.getText() == "Payment");
93 BEAST_EXPECT(pv.getSType() == STI_UINT32);
94 BEAST_EXPECT(pv.getJson(JsonOptions::none) == "Payment");
95 STUInt32 pv2(sfPermissionValue, PaymentMint);
96 BEAST_EXPECT(pv2.value() == PaymentMint);
97 BEAST_EXPECT(pv2.getText() == "PaymentMint");
98 BEAST_EXPECT(pv2.getSType() == STI_UINT32);
99 BEAST_EXPECT(pv2.getJson(JsonOptions::none) == "PaymentMint");
100 }
101
102 void
104 {
105 STUInt64 u64(0xFFFFFFFFFFFFFFFFull);
106 BEAST_EXPECT(u64.value() == 0xFFFFFFFFFFFFFFFFull);
107 BEAST_EXPECT(u64.getText() == "18446744073709551615");
108 BEAST_EXPECT(u64.getSType() == STI_UINT64);
109
110 // By default, getJson returns hex string
111 auto jsonVal = u64.getJson(JsonOptions::none);
112 BEAST_EXPECT(jsonVal.isString());
113 BEAST_EXPECT(jsonVal.asString() == "ffffffffffffffff");
114
115 STUInt64 u64_2(sfMaximumAmount, 0xFFFFFFFFFFFFFFFFull);
116 BEAST_EXPECT(u64_2.value() == 0xFFFFFFFFFFFFFFFFull);
117 BEAST_EXPECT(u64_2.getText() == "18446744073709551615");
118 BEAST_EXPECT(u64_2.getSType() == STI_UINT64);
119 BEAST_EXPECT(
120 u64_2.getJson(JsonOptions::none) == "18446744073709551615");
121 }
122
123 void
124 run() override
125 {
126 testUInt8();
127 testUInt16();
128 testUInt32();
129 testUInt64();
130 }
131};
132
133BEAST_DEFINE_TESTSUITE(STInteger, protocol, ripple);
134
135} // namespace ripple
A testsuite class.
Definition suite.h:55
Json::Value getJson(JsonOptions) const override
Definition STInteger.cpp:76
std::string getText() const override
Definition STInteger.cpp:56
value_type value() const noexcept
Definition STInteger.h:146
SerializedTypeID getSType() const override
Definition STInteger.cpp:49
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
void run() override
Runs the suite.