Compare commits

...

2 Commits

Author SHA1 Message Date
Mayukha Vadari
a6d9060218 clean up 2026-04-23 16:56:30 -04:00
Mayukha Vadari
6afe1ba64c fix: Regressions in server_definitions 2026-04-23 16:53:38 -04:00
3 changed files with 45 additions and 30 deletions

View File

@@ -100,7 +100,7 @@ SField::SField(private_access_tag_t, int fc, char const* fn)
, fieldName(fn)
, fieldMeta(sMD_Never)
, fieldNum(++num)
, signingField(IsSigning::yes)
, signingField(IsSigning::no)
, jsonName(fieldName.c_str())
{
XRPL_ASSERT(

View File

@@ -8,6 +8,9 @@
#include <xrpl/protocol/TxFlags.h>
#include <xrpl/protocol/jss.h>
#include <set>
#include <string>
namespace xrpl::test {
class ServerDefinitions_test : public beast::unit_test::suite
@@ -37,20 +40,23 @@ public:
{
auto const firstField = result[jss::result][jss::FIELDS][0u];
BEAST_EXPECT(firstField[0u].asString() == "Generic");
BEAST_EXPECT(firstField[0u].asString() == "Invalid");
BEAST_EXPECT(firstField[1][jss::isSerialized].asBool() == false);
BEAST_EXPECT(firstField[1][jss::isSigningField].asBool() == false);
BEAST_EXPECT(firstField[1][jss::isVLEncoded].asBool() == false);
BEAST_EXPECT(firstField[1][jss::nth].asUInt() == 0);
BEAST_EXPECT(firstField[1][jss::nth].asInt() == -1);
BEAST_EXPECT(firstField[1][jss::type].asString() == "Unknown");
}
BEAST_EXPECT(
result[jss::result][jss::LEDGER_ENTRY_TYPES]["AccountRoot"].asUInt() == 97);
BEAST_EXPECT(
result[jss::result][jss::TRANSACTION_RESULTS]["tecDIR_FULL"].asUInt() == 121);
BEAST_EXPECT(result[jss::result][jss::TRANSACTION_TYPES]["Payment"].asUInt() == 0);
BEAST_EXPECT(result[jss::result][jss::TYPES]["AccountID"].asUInt() == 8);
{
auto const field = result[jss::result][jss::FIELDS][6u];
BEAST_EXPECT(field[0u].asString() == "LedgerEntryType");
BEAST_EXPECT(field[1][jss::isSerialized].asBool() == true);
BEAST_EXPECT(field[1][jss::isSigningField].asBool() == true);
BEAST_EXPECT(field[1][jss::isVLEncoded].asBool() == false);
BEAST_EXPECT(field[1][jss::nth].asUInt() == 1);
BEAST_EXPECT(field[1][jss::type].asString() == "UInt16");
}
// check exception SFields
{
@@ -74,17 +80,34 @@ public:
BEAST_EXPECT(fieldExists("index"));
}
// verify no duplicate field names in FIELDS array
{
std::set<std::string> fieldNames;
for (auto const& field : result[jss::result][jss::FIELDS])
{
auto const name = field[0u].asString();
BEAST_EXPECT(fieldNames.insert(name).second);
}
}
// test that base_uint types are replaced with "Hash" prefix
{
auto const types = result[jss::result][jss::TYPES];
BEAST_EXPECT(types["Hash128"].asUInt() == 4);
BEAST_EXPECT(types["Hash160"].asUInt() == 17);
BEAST_EXPECT(types["Hash192"].asUInt() == 21);
BEAST_EXPECT(types["Hash256"].asUInt() == 5);
BEAST_EXPECT(types["Hash384"].asUInt() == 22);
BEAST_EXPECT(types["Hash512"].asUInt() == 23);
BEAST_EXPECT(types.isMember("Hash128") && types["Hash128"].asUInt() == 4);
BEAST_EXPECT(types.isMember("Hash160") && types["Hash160"].asUInt() == 17);
BEAST_EXPECT(types.isMember("Hash192") && types["Hash192"].asUInt() == 21);
BEAST_EXPECT(types.isMember("Hash256") && types["Hash256"].asUInt() == 5);
BEAST_EXPECT(types.isMember("Hash384") && types["Hash384"].asUInt() == 22);
BEAST_EXPECT(types.isMember("Hash512") && types["Hash512"].asUInt() == 23);
}
BEAST_EXPECT(
result[jss::result][jss::LEDGER_ENTRY_TYPES]["AccountRoot"].asUInt() == 97);
BEAST_EXPECT(
result[jss::result][jss::TRANSACTION_RESULTS]["tecDIR_FULL"].asUInt() == 121);
BEAST_EXPECT(result[jss::result][jss::TRANSACTION_TYPES]["Payment"].asUInt() == 0);
BEAST_EXPECT(result[jss::result][jss::TYPES]["AccountID"].asUInt() == 8);
// test the properties of the LEDGER_ENTRY_FLAGS section
{
BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_FLAGS));

View File

@@ -149,18 +149,6 @@ ServerDefinitions::ServerDefinitions() : defs_{Json::objectValue}
defs_[jss::FIELDS] = Json::arrayValue;
uint32_t i = 0;
{
Json::Value a = Json::arrayValue;
a[0U] = "Generic";
Json::Value v = Json::objectValue;
v[jss::nth] = 0;
v[jss::isVLEncoded] = false;
v[jss::isSerialized] = false;
v[jss::isSigningField] = false;
v[jss::type] = "Unknown";
a[1U] = v;
defs_[jss::FIELDS][i++] = a;
}
{
Json::Value a = Json::arrayValue;
@@ -227,21 +215,25 @@ ServerDefinitions::ServerDefinitions() : defs_{Json::objectValue}
defs_[jss::FIELDS][i++] = a;
}
for (auto const& [code, field] : xrpl::SField::getKnownCodeToField())
// copy into a sorted map to ensure deterministic output order (sorted by fieldCode)
static std::map<int, SField const*> const sortedFields(
xrpl::SField::getKnownCodeToField().begin(), xrpl::SField::getKnownCodeToField().end());
for (auto const& [code, field] : sortedFields)
{
if (field->fieldName.empty())
continue;
Json::Value innerObj = Json::objectValue;
uint32_t type = field->fieldType;
uint32_t const type = field->fieldType;
innerObj[jss::nth] = field->fieldValue;
// whether the field is variable-length encoded this means that the length is included
// before the content
innerObj[jss::isVLEncoded] =
(type == 7U /* Blob */ || type == 8U /* AccountID */ || type == 19U /* Vector256 */);
(type == STI_VL || type == STI_ACCOUNT || type == STI_VECTOR256);
// whether the field is included in serialization
innerObj[jss::isSerialized] =