From fb8d648a08f40447f8f9eb3076bb3b10943a763e Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 27 Mar 2026 16:02:19 +0000 Subject: [PATCH] test: Don't hardcode apiVersion where possible (#3017) --- tests/unit/rpc/handlers/FeatureTests.cpp | 4 +++- .../rpc/handlers/GatewayBalancesTests.cpp | 9 +++++---- tests/unit/rpc/handlers/LedgerDataTests.cpp | 3 ++- tests/unit/rpc/handlers/LedgerTests.cpp | 10 ++++++---- tests/unit/rpc/handlers/NFTHistoryTests.cpp | 7 +++++-- .../rpc/handlers/TransactionEntryTests.cpp | 4 +++- tests/unit/rpc/handlers/VaultInfoTests.cpp | 19 +++++++++++++------ 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/tests/unit/rpc/handlers/FeatureTests.cpp b/tests/unit/rpc/handlers/FeatureTests.cpp index bba0f87b0..3483da0cd 100644 --- a/tests/unit/rpc/handlers/FeatureTests.cpp +++ b/tests/unit/rpc/handlers/FeatureTests.cpp @@ -28,6 +28,7 @@ constexpr auto kRANGE_MIN = 10; constexpr auto kRANGE_MAX = 30; constexpr auto kSEQ = 30; constexpr auto kLEDGER_HASH = "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652"; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -154,7 +155,8 @@ TEST_P(RPCFeatureHandlerParamTest, InvalidParams) runSpawn([&, this](auto yield) { auto const handler = AnyHandler{FeatureHandler{backend_, mockAmendmentCenterPtr_}}; auto const req = boost::json::parse(testBundle.testJson); - auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); diff --git a/tests/unit/rpc/handlers/GatewayBalancesTests.cpp b/tests/unit/rpc/handlers/GatewayBalancesTests.cpp index 7b9413ee9..0e946aec3 100644 --- a/tests/unit/rpc/handlers/GatewayBalancesTests.cpp +++ b/tests/unit/rpc/handlers/GatewayBalancesTests.cpp @@ -41,6 +41,7 @@ constexpr auto kLEDGER_HASH = "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF2 constexpr auto kINDEX1 = "1B8590C01B0006EDFA9ED60296DD052DC5E90F99659B25014D08E1BC983515BC"; constexpr auto kINDEX2 = "E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321"; constexpr auto kTXN_ID = "E3FE6EA3D48F0C2B639448020EA4F03D4F4F8FFDB243A852A0F59177921B4879"; +constexpr auto kAPI_VERSION = 2; struct ParameterTestBundle { std::string testName; @@ -198,7 +199,7 @@ generateParameterTestBundles() ), .expectedError = "invalidParams", .expectedErrorMessage = "hotwalletNotStringOrArray", - .apiVersion = 2u + .apiVersion = kAPI_VERSION }, ParameterTestBundle{ .testName = "WalletsNotStringAccountV2", @@ -211,7 +212,7 @@ generateParameterTestBundles() ), .expectedError = "invalidParams", .expectedErrorMessage = "hotwalletMalformed", - .apiVersion = 2u + .apiVersion = kAPI_VERSION }, ParameterTestBundle{ .testName = "WalletsInvalidAccountV2", @@ -224,7 +225,7 @@ generateParameterTestBundles() ), .expectedError = "invalidParams", .expectedErrorMessage = "hotwalletMalformed", - .apiVersion = 2u + .apiVersion = kAPI_VERSION }, ParameterTestBundle{ .testName = "WalletInvalidAccountV2", @@ -237,7 +238,7 @@ generateParameterTestBundles() ), .expectedError = "invalidParams", .expectedErrorMessage = "hotwalletMalformed", - .apiVersion = 2u + .apiVersion = kAPI_VERSION }, }; } diff --git a/tests/unit/rpc/handlers/LedgerDataTests.cpp b/tests/unit/rpc/handlers/LedgerDataTests.cpp index 82313415a..c18cdef7b 100644 --- a/tests/unit/rpc/handlers/LedgerDataTests.cpp +++ b/tests/unit/rpc/handlers/LedgerDataTests.cpp @@ -36,6 +36,7 @@ constexpr auto kLEDGER_HASH = "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF2 constexpr auto kINDEX1 = "05FB0EB4B899F056FA095537C5817163801F544BAFCEA39C995D76DB4D16F9DD"; constexpr auto kINDEX2 = "E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322"; constexpr auto kTXN_ID = "05FB0EB4B899F056FA095537C5817163801F544BAFCEA39C995D76DB4D16F0DD"; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -365,7 +366,7 @@ TEST_F(RPCLedgerDataHandlerTest, Version2) runSpawn([&, this](auto yield) { auto const handler = AnyHandler{LedgerDataHandler{backend_}}; auto const req = json::parse(R"JSON({"limit": 10})JSON"); - auto output = handler.process(req, Context{.yield = yield, .apiVersion = 2}); + auto output = handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_TRUE(output.result->as_object().contains("ledger")); diff --git a/tests/unit/rpc/handlers/LedgerTests.cpp b/tests/unit/rpc/handlers/LedgerTests.cpp index b04f873e3..0a40c7322 100644 --- a/tests/unit/rpc/handlers/LedgerTests.cpp +++ b/tests/unit/rpc/handlers/LedgerTests.cpp @@ -38,6 +38,7 @@ constexpr auto kCURRENCY = "0158415500000000C1F76FF6ECB0BAC600000000"; constexpr auto kRANGE_MIN = 10; constexpr auto kRANGE_MAX = 30; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -474,7 +475,8 @@ TEST_F(RPCLedgerHandlerTest, TransactionsExpandBinaryV2) "transactions": true })JSON" ); - auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2u}); + auto const output = + handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(*output.result, json::parse(kEXPECTED_OUT)); }); @@ -663,7 +665,7 @@ TEST_F(RPCLedgerHandlerTest, TransactionsExpandNotBinaryV2) "transactions": true })JSON" ); - auto output = handler.process(req, Context{.yield = yield, .apiVersion = 2u}); + auto output = handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); // remove human readable time, it is slightly different cross the platform EXPECT_EQ(output.result->as_object().at("ledger").as_object().erase("close_time_human"), 1); @@ -702,7 +704,7 @@ TEST_F(RPCLedgerHandlerTest, TwoRequestInARowTransactionsExpandNotBinaryV2) "transactions": true })JSON" ); - auto output = handler.process(req, Context{.yield = yield, .apiVersion = 2u}); + auto output = handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); auto const req2 = json::parse( @@ -716,7 +718,7 @@ TEST_F(RPCLedgerHandlerTest, TwoRequestInARowTransactionsExpandNotBinaryV2) kRANGE_MAX - 1 ) ); - auto output2 = handler.process(req2, Context{.yield = yield, .apiVersion = 2u}); + auto output2 = handler.process(req2, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output2); EXPECT_NE( output.result->at("ledger").at("transactions").as_array()[0].at("close_time_iso"), diff --git a/tests/unit/rpc/handlers/NFTHistoryTests.cpp b/tests/unit/rpc/handlers/NFTHistoryTests.cpp index 731b238a5..003da307a 100644 --- a/tests/unit/rpc/handlers/NFTHistoryTests.cpp +++ b/tests/unit/rpc/handlers/NFTHistoryTests.cpp @@ -32,6 +32,7 @@ constexpr auto kACCOUNT = "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"; constexpr auto kACCOUNT2 = "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun"; constexpr auto kLEDGER_HASH = "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652"; constexpr auto kNFT_ID = "00010000A7CAD27B688D14BA1A9FA5366554D6ADCF9CE0875B974D9F00000004"; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -588,7 +589,8 @@ TEST_F(RPCNFTHistoryHandlerTest, IndexSpecificForwardFalseV2) kMAX_SEQ - 1 ) ); - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2u}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(output.result.value(), boost::json::parse(kOUTPUT)); }); @@ -783,7 +785,8 @@ TEST_F(RPCNFTHistoryHandlerTest, BinaryTrueV2) -1 ) ); - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2u}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(output.result->at("nft_id").as_string(), kNFT_ID); EXPECT_EQ(output.result->at("ledger_index_min").as_uint64(), kMIN_SEQ); diff --git a/tests/unit/rpc/handlers/TransactionEntryTests.cpp b/tests/unit/rpc/handlers/TransactionEntryTests.cpp index f91147b46..6e841a52c 100644 --- a/tests/unit/rpc/handlers/TransactionEntryTests.cpp +++ b/tests/unit/rpc/handlers/TransactionEntryTests.cpp @@ -27,6 +27,7 @@ constexpr auto kTXN_ID = "05FB0EB4B899F056FA095537C5817163801F544BAFCEA39C995D76 constexpr auto kACCOUNT = "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"; constexpr auto kACCOUNT2 = "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun"; constexpr auto kCURRENCY = "0158415500000000C1F76FF6ECB0BAC600000000"; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -318,7 +319,8 @@ TEST_F(RPCTransactionEntryHandlerTest, NormalPathV2) tx.ledgerSequence ) ); - auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(json::parse(kOUTPUT), *output.result); }); diff --git a/tests/unit/rpc/handlers/VaultInfoTests.cpp b/tests/unit/rpc/handlers/VaultInfoTests.cpp index 19dc39baf..326fe69cb 100644 --- a/tests/unit/rpc/handlers/VaultInfoTests.cpp +++ b/tests/unit/rpc/handlers/VaultInfoTests.cpp @@ -35,6 +35,7 @@ constexpr auto kSEQ = 30; constexpr auto kASSET_CURRENCY = "XRP"; constexpr auto kASSET_ISSUER = "rrrrrrrrrrrrrrrrrrrrrhoLvTp"; constexpr auto kVAULT_ID = "61B03A6F8CEBD3AF9D8F696C3D0A9A9F0493B34BF6B5D93CF0BC009E6BA75303"; +constexpr auto kAPI_VERSION = 2; } // namespace @@ -168,7 +169,8 @@ TEST_P(VaultInfoParameterTest, InvalidParams) runSpawn([&, this](auto yield) { auto const handler = AnyHandler{VaultInfoHandler{backend_}}; auto const req = json::parse(testBundle.testJson); - auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(req, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); @@ -202,7 +204,8 @@ TEST_F(RPCVaultInfoHandlerTest, InputHasOwnerButNotFoundResultsInError) // Run the handler auto const handler = AnyHandler{VaultInfoHandler{backend_}}; runSpawn([&](auto yield) { - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "entryNotFound"); @@ -232,7 +235,8 @@ TEST_F(RPCVaultInfoHandlerTest, VaultIDFailsVaultDeserializationReturnsEntryNotF auto const handler = AnyHandler{VaultInfoHandler{backend_}}; runSpawn([&](auto yield) { - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); @@ -283,7 +287,8 @@ TEST_F(RPCVaultInfoHandlerTest, MissingIssuanceObject) auto const handler = AnyHandler{VaultInfoHandler{backend_}}; runSpawn([&](auto yield) { - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "entryNotFound"); @@ -377,7 +382,8 @@ TEST_F(RPCVaultInfoHandlerTest, ValidVaultObjectQueryByVaultID) // Run the handler auto const handler = AnyHandler{VaultInfoHandler{backend_}}; runSpawn([&](auto yield) { - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(*output.result, json::parse(kEXPECTED_OUTPUT)); }); @@ -476,7 +482,8 @@ TEST_F(RPCVaultInfoHandlerTest, ValidVaultObjectQueryByOwnerAndSeq) // Run the handler auto const handler = AnyHandler{VaultInfoHandler{backend_}}; runSpawn([&](auto yield) { - auto const output = handler.process(kINPUT, Context{.yield = yield, .apiVersion = 2}); + auto const output = + handler.process(kINPUT, Context{.yield = yield, .apiVersion = kAPI_VERSION}); ASSERT_TRUE(output); EXPECT_EQ(*output.result, json::parse(kEXPECTED_OUTPUT)); });