mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-17 09:35:51 +00:00
Merge remote-tracking branch 'upstream/ripple/se/fees' into ripple/smart-escrow
This commit is contained in:
@@ -647,11 +647,17 @@ parseLeaf(
|
|||||||
}
|
}
|
||||||
else if (value.isInt())
|
else if (value.isInt())
|
||||||
{
|
{
|
||||||
|
// future-proofing - a static assert failure if the JSON
|
||||||
|
// library ever supports larger ints
|
||||||
|
// In such case, we will need additional bounds checks here
|
||||||
|
static_assert(
|
||||||
|
std::is_same_v<decltype(value.asInt()), std::int32_t>);
|
||||||
ret = detail::make_stvar<STInt32>(field, value.asInt());
|
ret = detail::make_stvar<STInt32>(field, value.asInt());
|
||||||
}
|
}
|
||||||
else if (value.isUInt())
|
else if (value.isUInt())
|
||||||
{
|
{
|
||||||
if (value.asUInt() >
|
auto const uintValue = value.asUInt();
|
||||||
|
if (uintValue >
|
||||||
static_cast<std::uint32_t>(
|
static_cast<std::uint32_t>(
|
||||||
std::numeric_limits<std::int32_t>::max()))
|
std::numeric_limits<std::int32_t>::max()))
|
||||||
{
|
{
|
||||||
@@ -659,7 +665,7 @@ parseLeaf(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = detail::make_stvar<STInt32>(
|
ret = detail::make_stvar<STInt32>(
|
||||||
field, safe_cast<std::int32_t>(value.asInt()));
|
field, static_cast<std::int32_t>(uintValue));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -122,10 +122,27 @@ struct STAccount_test : public beast::unit_test::suite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testAccountID()
|
||||||
|
{
|
||||||
|
auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
|
||||||
|
if (auto const parsed = parseBase58<AccountID>(s); BEAST_EXPECT(parsed))
|
||||||
|
{
|
||||||
|
BEAST_EXPECT(toBase58(*parsed) == s);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto const s =
|
||||||
|
"âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f";
|
||||||
|
BEAST_EXPECT(!parseBase58<AccountID>(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
testSTAccount();
|
testSTAccount();
|
||||||
|
testAccountID();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
void
|
void
|
||||||
testUInt8()
|
testUInt8()
|
||||||
{
|
{
|
||||||
|
testcase("UInt8");
|
||||||
STUInt8 u8(255);
|
STUInt8 u8(255);
|
||||||
BEAST_EXPECT(u8.value() == 255);
|
BEAST_EXPECT(u8.value() == 255);
|
||||||
BEAST_EXPECT(u8.getText() == "255");
|
BEAST_EXPECT(u8.getText() == "255");
|
||||||
@@ -56,6 +57,7 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
void
|
void
|
||||||
testUInt16()
|
testUInt16()
|
||||||
{
|
{
|
||||||
|
testcase("UInt16");
|
||||||
STUInt16 u16(65535);
|
STUInt16 u16(65535);
|
||||||
BEAST_EXPECT(u16.value() == 65535);
|
BEAST_EXPECT(u16.value() == 65535);
|
||||||
BEAST_EXPECT(u16.getText() == "65535");
|
BEAST_EXPECT(u16.getText() == "65535");
|
||||||
@@ -80,6 +82,7 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
void
|
void
|
||||||
testUInt32()
|
testUInt32()
|
||||||
{
|
{
|
||||||
|
testcase("UInt32");
|
||||||
STUInt32 u32(4'294'967'295u);
|
STUInt32 u32(4'294'967'295u);
|
||||||
BEAST_EXPECT(u32.value() == 4'294'967'295u);
|
BEAST_EXPECT(u32.value() == 4'294'967'295u);
|
||||||
BEAST_EXPECT(u32.getText() == "4294967295");
|
BEAST_EXPECT(u32.getText() == "4294967295");
|
||||||
@@ -102,6 +105,7 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
void
|
void
|
||||||
testUInt64()
|
testUInt64()
|
||||||
{
|
{
|
||||||
|
testcase("UInt64");
|
||||||
STUInt64 u64(0xFFFFFFFFFFFFFFFFull);
|
STUInt64 u64(0xFFFFFFFFFFFFFFFFull);
|
||||||
BEAST_EXPECT(u64.value() == 0xFFFFFFFFFFFFFFFFull);
|
BEAST_EXPECT(u64.value() == 0xFFFFFFFFFFFFFFFFull);
|
||||||
BEAST_EXPECT(u64.getText() == "18446744073709551615");
|
BEAST_EXPECT(u64.getText() == "18446744073709551615");
|
||||||
@@ -120,6 +124,29 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
u64_2.getJson(JsonOptions::none) == "18446744073709551615");
|
u64_2.getJson(JsonOptions::none) == "18446744073709551615");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testInt32()
|
||||||
|
{
|
||||||
|
testcase("Int32");
|
||||||
|
{
|
||||||
|
int const minInt32 = -2147483648;
|
||||||
|
STInt32 i32(minInt32);
|
||||||
|
BEAST_EXPECT(i32.value() == minInt32);
|
||||||
|
BEAST_EXPECT(i32.getText() == "-2147483648");
|
||||||
|
BEAST_EXPECT(i32.getSType() == STI_INT32);
|
||||||
|
BEAST_EXPECT(i32.getJson(JsonOptions::none) == minInt32);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int const maxInt32 = 2147483647;
|
||||||
|
STInt32 i32(maxInt32);
|
||||||
|
BEAST_EXPECT(i32.value() == maxInt32);
|
||||||
|
BEAST_EXPECT(i32.getText() == "2147483647");
|
||||||
|
BEAST_EXPECT(i32.getSType() == STI_INT32);
|
||||||
|
BEAST_EXPECT(i32.getJson(JsonOptions::none) == maxInt32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
@@ -127,6 +154,7 @@ struct STInteger_test : public beast::unit_test::suite
|
|||||||
testUInt16();
|
testUInt16();
|
||||||
testUInt32();
|
testUInt32();
|
||||||
testUInt64();
|
testUInt64();
|
||||||
|
testInt32();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -736,6 +736,110 @@ class STParsedJSON_test : public beast::unit_test::suite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testInt32()
|
||||||
|
{
|
||||||
|
testcase("Int32");
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
int const minInt32 = -2147483648;
|
||||||
|
j[sfWasmReturnCode] = minInt32;
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(obj.object.has_value());
|
||||||
|
if (BEAST_EXPECT(obj.object->isFieldPresent(sfWasmReturnCode)))
|
||||||
|
BEAST_EXPECT(
|
||||||
|
obj.object->getFieldI32(sfWasmReturnCode) == minInt32);
|
||||||
|
}
|
||||||
|
|
||||||
|
// max value
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
int const maxInt32 = 2147483647;
|
||||||
|
j[sfWasmReturnCode] = maxInt32;
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(obj.object.has_value());
|
||||||
|
if (BEAST_EXPECT(obj.object->isFieldPresent(sfWasmReturnCode)))
|
||||||
|
BEAST_EXPECT(
|
||||||
|
obj.object->getFieldI32(sfWasmReturnCode) == maxInt32);
|
||||||
|
}
|
||||||
|
|
||||||
|
// max uint value
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
unsigned int const maxUInt32 = 2147483647u;
|
||||||
|
j[sfWasmReturnCode] = maxUInt32;
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(obj.object.has_value());
|
||||||
|
if (BEAST_EXPECT(obj.object->isFieldPresent(sfWasmReturnCode)))
|
||||||
|
BEAST_EXPECT(
|
||||||
|
obj.object->getFieldI32(sfWasmReturnCode) ==
|
||||||
|
static_cast<int32_t>(maxUInt32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with string value
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = "2147483647";
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(obj.object.has_value());
|
||||||
|
if (BEAST_EXPECT(obj.object->isFieldPresent(sfWasmReturnCode)))
|
||||||
|
BEAST_EXPECT(
|
||||||
|
obj.object->getFieldI32(sfWasmReturnCode) == 2147483647u);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with string negative value
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
int value = -2147483648;
|
||||||
|
j[sfWasmReturnCode] = std::to_string(value);
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(obj.object.has_value());
|
||||||
|
if (BEAST_EXPECT(obj.object->isFieldPresent(sfWasmReturnCode)))
|
||||||
|
BEAST_EXPECT(
|
||||||
|
obj.object->getFieldI32(sfWasmReturnCode) == value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test out of range value for int32 (negative)
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = "-2147483649";
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(!obj.object.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test out of range value for int32 (positive)
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = 2147483648u;
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(!obj.object.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test string value out of range
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = "2147483648";
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(!obj.object.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test bad_type (arrayValue)
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = Json::Value(Json::arrayValue);
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(!obj.object.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test bad_type (objectValue)
|
||||||
|
{
|
||||||
|
Json::Value j;
|
||||||
|
j[sfWasmReturnCode] = Json::Value(Json::objectValue);
|
||||||
|
STParsedJSONObject obj("Test", j);
|
||||||
|
BEAST_EXPECT(!obj.object.has_value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
testBlob()
|
testBlob()
|
||||||
{
|
{
|
||||||
@@ -1338,8 +1442,7 @@ class STParsedJSON_test : public beast::unit_test::suite
|
|||||||
issueJson["issuer"] = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
|
issueJson["issuer"] = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
|
||||||
j[sfAsset] = issueJson;
|
j[sfAsset] = issueJson;
|
||||||
STParsedJSONObject obj("Test", j);
|
STParsedJSONObject obj("Test", j);
|
||||||
if (BEAST_EXPECTS(
|
if (BEAST_EXPECT(obj.object.has_value()))
|
||||||
obj.object.has_value(), obj.error.toStyledString()))
|
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(obj.object->isFieldPresent(sfAsset));
|
BEAST_EXPECT(obj.object->isFieldPresent(sfAsset));
|
||||||
auto const& issueField = (*obj.object)[sfAsset];
|
auto const& issueField = (*obj.object)[sfAsset];
|
||||||
@@ -2235,6 +2338,7 @@ class STParsedJSON_test : public beast::unit_test::suite
|
|||||||
testUInt160();
|
testUInt160();
|
||||||
testUInt192();
|
testUInt192();
|
||||||
testUInt256();
|
testUInt256();
|
||||||
|
testInt32();
|
||||||
testBlob();
|
testBlob();
|
||||||
testVector256();
|
testVector256();
|
||||||
testAccount();
|
testAccount();
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <xrpl/beast/unit_test.h>
|
|
||||||
#include <xrpl/protocol/UintTypes.h>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
struct types_test : public beast::unit_test::suite
|
|
||||||
{
|
|
||||||
void
|
|
||||||
testAccountID()
|
|
||||||
{
|
|
||||||
auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
|
|
||||||
if (auto const parsed = parseBase58<AccountID>(s); BEAST_EXPECT(parsed))
|
|
||||||
{
|
|
||||||
BEAST_EXPECT(toBase58(*parsed) == s);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto const s =
|
|
||||||
"âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f";
|
|
||||||
BEAST_EXPECT(!parseBase58<AccountID>(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
run() override
|
|
||||||
{
|
|
||||||
testAccountID();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(types, protocol, ripple);
|
|
||||||
|
|
||||||
} // namespace ripple
|
|
||||||
Reference in New Issue
Block a user