xrpld
Loading...
Searching...
No Matches
BuildInfo_test.cpp
1#include <xrpl/beast/core/SemanticVersion.h>
2#include <xrpl/beast/unit_test/suite.h>
3#include <xrpl/protocol/BuildInfo.h>
4
5namespace xrpl {
6
8{
9public:
10 void
12 {
13 testcase("EncodeSoftwareVersion");
14
15 auto encodedVersion = build_info::encodeSoftwareVersion("1.2.3-b7");
16
17 // the first two bytes identify the particular implementation, 0x183B
18 BEAST_EXPECT((encodedVersion & 0xFFFF'0000'0000'0000LLU) == 0x183B'0000'0000'0000LLU);
19
20 // the next three bytes: major version, minor version, patch version,
21 // 0x010203
22 BEAST_EXPECT((encodedVersion & 0x0000'FFFF'FF00'0000LLU) == 0x0000'0102'0300'0000LLU);
23
24 // the next two bits:
25 {
26 // 01 if a beta
27 BEAST_EXPECT((encodedVersion & 0x0000'0000'00C0'0000LLU) >> 22 == 0b01);
28 // 10 if an RC
29 encodedVersion = build_info::encodeSoftwareVersion("1.2.4-rc7");
30 BEAST_EXPECT((encodedVersion & 0x0000'0000'00C0'0000LLU) >> 22 == 0b10);
31 // 11 if neither an RC nor a beta
32 encodedVersion = build_info::encodeSoftwareVersion("1.2.5");
33 BEAST_EXPECT((encodedVersion & 0x0000'0000'00C0'0000LLU) >> 22 == 0b11);
34 }
35
36 // the next six bits: rc/beta number (1-63)
37 encodedVersion = build_info::encodeSoftwareVersion("1.2.6-b63");
38 BEAST_EXPECT((encodedVersion & 0x0000'0000'003F'0000LLU) >> 16 == 63);
39
40 // the last two bytes are zeros
41 BEAST_EXPECT((encodedVersion & 0x0000'0000'0000'FFFFLLU) == 0);
42
43 // Test some version strings with wrong formats:
44 // no rc/beta number
45 encodedVersion = build_info::encodeSoftwareVersion("1.2.3-b");
46 BEAST_EXPECT((encodedVersion & 0x0000'0000'00FF'0000LLU) == 0);
47 // rc/beta number out of range
48 encodedVersion = build_info::encodeSoftwareVersion("1.2.3-b64");
49 BEAST_EXPECT((encodedVersion & 0x0000'0000'00FF'0000LLU) == 0);
50
51 // Check that the rc/beta number of a release is 0:
52 encodedVersion = build_info::encodeSoftwareVersion("1.2.6");
53 BEAST_EXPECT((encodedVersion & 0x0000'0000'003F'0000LLU) == 0);
54 }
55
56 void
58 {
59 testcase("IsXrpldVersion");
60 auto vFF = 0xFFFF'FFFF'FFFF'FFFFLLU;
61 BEAST_EXPECT(!build_info::isXrpldVersion(vFF));
62 auto vXrpld = 0x183B'0000'0000'0000LLU;
63 BEAST_EXPECT(build_info::isXrpldVersion(vXrpld));
64 }
65
66 void
68 {
69 testcase("IsNewerVersion");
70 auto vFF = 0xFFFF'FFFF'FFFF'FFFFLLU;
71 BEAST_EXPECT(!build_info::isNewerVersion(vFF));
72
73 // 1.5.9 is newer than a development build (0.0.0-dev), but not a release.
74 auto v159 = build_info::encodeSoftwareVersion("1.5.9");
75 BEAST_EXPECT(
78 beast::SemanticVersion("1.5.9")));
79
80 auto vCurrent = build_info::getEncodedVersion();
81 BEAST_EXPECT(!build_info::isNewerVersion(vCurrent));
82
83 auto vMax = build_info::encodeSoftwareVersion("255.255.255");
84 BEAST_EXPECT(build_info::isNewerVersion(vMax));
85 }
86
87 void
94};
95
97} // namespace xrpl
A Semantic Version number.
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
void run() override
Runs the suite.
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:63
bool isXrpldVersion(std::uint64_t version)
Check if the encoded software version is an xrpld software version.
std::uint64_t encodeSoftwareVersion(std::string_view versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:87
std::uint64_t getEncodedVersion()
Returns this server's version packed in a 64-bit integer.
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's xrpld software version.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)