Files
rippled/src/test/overlay/ProtocolVersion_test.cpp
Ed Hennis 25d246fc92 Merge remote-tracking branch 'XRPLF/develop' into ximinez/fix-getledger
* XRPLF/develop:
  ci: Rewrite clang-tidy workflow(s) in a reusable manner (7062)
  chore: Ignore identifier-naming update in git blame (7066)
  refactor: Enable clang-tidy `readability-identifier-naming` check (6571)
  refactor: Revert certain `Throw`s by `LogicError`s (7036)
  ci: Rename print-env -> print-build-env (7061)
  fix: Gate -mcmodel flags to x86_64 in sanitizer builds (7049)
  fix: Prevents overwriting a bool value in an invariant (6609)
  fix: Address code review comments regarding `boost::coroutine2` (6977)
  refactor: Apply various minor improvements and corrections (7045)
  fix: Store `Delegate` object in delegating and authorized account directories for proper deletion (6681)
  ci: Use print-env from XRPLF/actions (7052)
  fix: Make assorted RPC fixes (6529)
  chore: Enable clang-tidy v21 new checks (7031)
  feat: Create new transaction testing framework `TxTest` (6537)
  feat: Add cleanup amendment for 3.2.0 (7037)
  fix: Fix ubsan flagged issues (6151)
2026-05-05 00:08:59 -04:00

77 lines
2.4 KiB
C++

#include <xrpld/overlay/detail/ProtocolVersion.h>
#include <xrpl/beast/unit_test/suite.h>
#include <optional>
#include <string>
namespace xrpl {
class ProtocolVersion_test : public beast::unit_test::Suite
{
private:
void
check(std::string const& s, std::string const& answer)
{
auto join = [](auto first, auto last) {
std::string result;
if (first != last)
{
result = to_string(*first++);
while (first != last)
result += "," + to_string(*first++);
}
return result;
};
auto const result = parseProtocolVersions(s);
BEAST_EXPECT(join(result.begin(), result.end()) == answer);
}
public:
void
run() override
{
testcase("Convert protocol version to string");
BEAST_EXPECT(to_string(makeProtocol(1, 3)) == "XRPL/1.3");
BEAST_EXPECT(to_string(makeProtocol(2, 0)) == "XRPL/2.0");
BEAST_EXPECT(to_string(makeProtocol(2, 1)) == "XRPL/2.1");
BEAST_EXPECT(to_string(makeProtocol(10, 10)) == "XRPL/10.10");
{
testcase("Convert strings to protocol versions");
// Empty string
check("", "");
check("RTXP/1.1,RTXP/1.2,RTXP/1.3,XRPL/2.1,XRPL/2.0,/XRPL/3.0", "XRPL/2.0,XRPL/2.1");
check("RTXP/0.9,RTXP/1.01,XRPL/0.3,XRPL/2.01,websocket", "");
check(
"XRPL/2.0,XRPL/2.0,XRPL/19.4,XRPL/7.89,XRPL/XRPL/3.0,XRPL/2.01",
"XRPL/2.0,XRPL/7.89,XRPL/19.4");
check(
"XRPL/2.0,XRPL/3.0,XRPL/4,XRPL/,XRPL,OPT XRPL/2.2,XRPL/5.67",
"XRPL/2.0,XRPL/3.0,XRPL/5.67");
}
{
testcase("Protocol version negotiation");
BEAST_EXPECT(negotiateProtocolVersion("RTXP/1.2") == std::nullopt);
BEAST_EXPECT(
negotiateProtocolVersion("RTXP/1.2, XRPL/2.0, XRPL/2.1") == makeProtocol(2, 1));
BEAST_EXPECT(negotiateProtocolVersion("XRPL/2.2") == makeProtocol(2, 2));
BEAST_EXPECT(
negotiateProtocolVersion("RTXP/1.2, XRPL/2.2, XRPL/2.3, XRPL/2.4, XRPL/999.999") ==
makeProtocol(2, 3));
BEAST_EXPECT(negotiateProtocolVersion("XRPL/999.999, WebSocket/1.0") == std::nullopt);
BEAST_EXPECT(negotiateProtocolVersion("") == std::nullopt);
}
}
};
BEAST_DEFINE_TESTSUITE(ProtocolVersion, overlay, xrpl);
} // namespace xrpl