diff --git a/src/test/rpc/ServerDefinitions_test.cpp b/src/test/rpc/ServerDefinitions_test.cpp index 0529708f4..81fb4c8e3 100644 --- a/src/test/rpc/ServerDefinitions_test.cpp +++ b/src/test/rpc/ServerDefinitions_test.cpp @@ -55,9 +55,9 @@ public: using namespace test::jtx; + Env env(*this); + auto const result = env.rpc("server_definitions"); { - Env env(*this); - auto const result = env.rpc("server_definitions"); BEAST_EXPECT(!result[jss::result].isMember(jss::error)); BEAST_EXPECT(result[jss::result].isMember(jss::FIELDS)); BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES)); @@ -71,6 +71,38 @@ public: BEAST_EXPECT(result[jss::result].isMember(jss::hash)); BEAST_EXPECT(result[jss::result][jss::status] == "success"); } + + // check exception SFields + { + auto const fieldExists = [&](std::string name) { + for (auto& field : result[jss::result][jss::FIELDS]) + { + if (field[0u].asString() == name) + { + return true; + } + } + return false; + }; + BEAST_EXPECT(fieldExists("Generic")); + BEAST_EXPECT(fieldExists("Invalid")); + BEAST_EXPECT(fieldExists("ObjectEndMarker")); + BEAST_EXPECT(fieldExists("ArrayEndMarker")); + BEAST_EXPECT(fieldExists("taker_gets_funded")); + BEAST_EXPECT(fieldExists("taker_pays_funded")); + BEAST_EXPECT(fieldExists("hash")); + BEAST_EXPECT(fieldExists("index")); + } + + // verify no duplicate field names in FIELDS array + { + std::set fieldNames; + for (auto const& field : result[jss::result][jss::FIELDS]) + { + auto const name = field[0u].asString(); + BEAST_EXPECT(fieldNames.insert(name).second); + } + } } void diff --git a/src/xrpld/rpc/handlers/ServerDefinitions.cpp b/src/xrpld/rpc/handlers/ServerDefinitions.cpp index 628311332..8c99a8de2 100644 --- a/src/xrpld/rpc/handlers/ServerDefinitions.cpp +++ b/src/xrpld/rpc/handlers/ServerDefinitions.cpp @@ -267,32 +267,6 @@ private: ret[jss::FIELDS][i++] = a; } - { - Json::Value a = Json::arrayValue; - a[0U] = "hash"; - Json::Value v = Json::objectValue; - v[jss::nth] = 257; - v[jss::isVLEncoded] = false; - v[jss::isSerialized] = false; - v[jss::isSigningField] = false; - v[jss::type] = "Hash256"; - a[1U] = v; - ret[jss::FIELDS][i++] = a; - } - - { - Json::Value a = Json::arrayValue; - a[0U] = "index"; - Json::Value v = Json::objectValue; - v[jss::nth] = 258; - v[jss::isVLEncoded] = false; - v[jss::isSerialized] = false; - v[jss::isSigningField] = false; - v[jss::type] = "Hash256"; - a[1U] = v; - ret[jss::FIELDS][i++] = a; - } - { Json::Value a = Json::arrayValue; a[0U] = "taker_gets_funded"; @@ -326,22 +300,23 @@ private: Json::Value innerObj = Json::objectValue; - uint32_t fc = code & 0xFFU; - uint32_t tc = code >> 16U; + uint32_t type = f->fieldType; - innerObj[jss::nth] = fc; + innerObj[jss::nth] = f->fieldValue; innerObj[jss::isVLEncoded] = - (tc == 7U /* Blob */ || tc == 8U /* AccountID */ || - tc == 19U /* Vector256 */); + (type == 7U /* Blob */ || type == 8U /* AccountID */ || + type == 19U /* Vector256 */); innerObj[jss::isSerialized] = - (tc < - 10000); /* TRANSACTION, LEDGER_ENTRY, VALIDATION, METADATA */ + (type < 10000 && f->fieldName != "hash" && + f->fieldName != + "index"); /* hash, index, TRANSACTION, LEDGER_ENTRY, + VALIDATION, METADATA */ innerObj[jss::isSigningField] = f->shouldInclude(false); - innerObj[jss::type] = type_map[tc]; + innerObj[jss::type] = type_map[type]; Json::Value innerArray = Json::arrayValue; innerArray[0U] = f->fieldName;