From 9a65b92fe7abe3924e2c916dde92c3ba7c406824 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Sat, 8 Jul 2023 20:36:24 -0400 Subject: [PATCH 01/11] helper function to avoid duplication of code --- src/test/jtx/Env.h | 20 ++++++++++++++++++++ src/test/rpc/AccountTx_test.cpp | 9 ++------- src/test/rpc/LedgerRPC_test.cpp | 10 ++-------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 2a85a57e1db..40e5233f4af 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -703,6 +704,25 @@ Env::rpc(std::string const& cmd, Args&&... args) std::forward(args)...); } +/** + * Executes a set of provided functions (Fs...) over a range of versions from + * RPC::apiMinimumSupportedVersion to RPC::apiBetaVersion. Each function in + * Fs... is expected to take a version number as its argument. This is useful + * for running a series of tests or operations that need to be performed on + * multiple versions of an API. + */ +template +void +forAllApiVersions(Fs... fs) +{ + for (auto testVersion = RPC::apiMinimumSupportedVersion; + testVersion <= RPC::apiBetaVersion; + ++testVersion) + { + (..., fs(testVersion)); + } +} + } // namespace jtx } // namespace test } // namespace ripple diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 2e09ad93b86..1cddf1a7ded 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -667,12 +666,8 @@ class AccountTx_test : public beast::unit_test::suite void run() override { - for (auto testVersion = RPC::apiMinimumSupportedVersion; - testVersion <= RPC::apiBetaVersion; - ++testVersion) - { - testParameters(testVersion); - } + test::jtx::forAllApiVersions( + [this](auto version) { testParameters(version); }); testContents(); testAccountDelete(); } diff --git a/src/test/rpc/LedgerRPC_test.cpp b/src/test/rpc/LedgerRPC_test.cpp index 9c9a63005a7..61e06d8ab88 100644 --- a/src/test/rpc/LedgerRPC_test.cpp +++ b/src/test/rpc/LedgerRPC_test.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace ripple { @@ -1737,13 +1736,8 @@ class LedgerRPC_test : public beast::unit_test::suite testQueue(); testLedgerAccountsOption(); - // version specific tests - for (auto testVersion = RPC::apiMinimumSupportedVersion; - testVersion <= RPC::apiBetaVersion; - ++testVersion) - { - testLedgerEntryInvalidParams(testVersion); - } + test::jtx::forAllApiVersions( + [this](auto version) { testLedgerEntryInvalidParams(version); }); } }; From 0b77500c287f14e953ed0c667e25073e9889fa30 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Sat, 8 Jul 2023 20:39:02 -0400 Subject: [PATCH 02/11] header order --- src/test/jtx/Env.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 40e5233f4af..62ca69bdbd8 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -54,6 +53,8 @@ #include #include #include +#include + namespace ripple { namespace test { From f85e8b887e720bcb38a87669b044aeff617afa6a Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Sat, 8 Jul 2023 20:43:16 -0400 Subject: [PATCH 03/11] delete extra new line --- src/test/jtx/Env.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 62ca69bdbd8..3ccfc5c2dcd 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -55,7 +55,6 @@ #include #include - namespace ripple { namespace test { namespace jtx { From d9b9eb0b78b9e591fd24baec0837169b599dcd28 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Sat, 8 Jul 2023 20:54:35 -0400 Subject: [PATCH 04/11] clang format --- src/test/jtx/Env.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 3ccfc5c2dcd..40e5233f4af 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -53,7 +54,6 @@ #include #include #include -#include namespace ripple { namespace test { From 24d3f47fcf1fa5d062d2d6e19ed82f5b9a186022 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Mon, 10 Jul 2023 12:32:43 -0400 Subject: [PATCH 05/11] levelization patch --- Builds/levelization/results/ordering.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Builds/levelization/results/ordering.txt b/Builds/levelization/results/ordering.txt index 401040fc2d7..f57c19997c3 100644 --- a/Builds/levelization/results/ordering.txt +++ b/Builds/levelization/results/ordering.txt @@ -142,6 +142,7 @@ test.jtx > ripple.json test.jtx > ripple.ledger test.jtx > ripple.net test.jtx > ripple.protocol +test.jtx > ripple.rpc test.jtx > ripple.server test.ledger > ripple.app test.ledger > ripple.basics From b66f08f72d521fdc25825365de8d2a3393e04c4d Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Tue, 18 Jul 2023 17:44:39 -0400 Subject: [PATCH 06/11] apply constraints on the template --- src/test/jtx/Env.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 40e5233f4af..54bb678aef9 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -705,21 +705,34 @@ Env::rpc(std::string const& cmd, Args&&... args) } /** - * Executes a set of provided functions (Fs...) over a range of versions from - * RPC::apiMinimumSupportedVersion to RPC::apiBetaVersion. Each function in - * Fs... is expected to take a version number as its argument. This is useful - * for running a series of tests or operations that need to be performed on - * multiple versions of an API. + * The SingleVersionedTestCallable concept checks for a callable that takes + * an unsigned integer as its argument and returns void. */ -template +template +concept SingleVersionedTestCallable = requires(T callable, unsigned int v) { + { + callable(v) + } -> std::same_as; +}; + +/** + * The VersionedTestCallable concept checks if a set of callables all satisfy + * the SingleVersionedTestCallable concept. This allows forAllApiVersions to + * accept any number of functions. It executes a set of provided functions over + * a range of versions from RPC::apiMinimumSupportedVersion to + * RPC::apiBetaVersion. This is useful for running a series of tests or + * operations that need to be performed on multiple versions of an API. + */ +template +concept VersionedTestCallable = (... && SingleVersionedTestCallable); void -forAllApiVersions(Fs... fs) +forAllApiVersions(VersionedTestCallable auto... testCallable) { for (auto testVersion = RPC::apiMinimumSupportedVersion; testVersion <= RPC::apiBetaVersion; ++testVersion) { - (..., fs(testVersion)); + (..., testCallable(testVersion)); } } From b2e74c74d0a458b17e9e0255358dcc74c0d1d982 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Tue, 18 Jul 2023 17:56:49 -0400 Subject: [PATCH 07/11] clang-format --- src/test/jtx/Env.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 54bb678aef9..47f59171546 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -709,10 +709,9 @@ Env::rpc(std::string const& cmd, Args&&... args) * an unsigned integer as its argument and returns void. */ template -concept SingleVersionedTestCallable = requires(T callable, unsigned int v) { - { - callable(v) - } -> std::same_as; +concept SingleVersionedTestCallable = requires(T callable, unsigned int v) +{ + {callable(v)} -> std::same_as; }; /** From fdfdf95b7e020c0c487e4d1e19b56cf855180322 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Tue, 18 Jul 2023 17:59:05 -0400 Subject: [PATCH 08/11] clang-format --- src/test/jtx/Env.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 47f59171546..b25be484323 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -711,7 +711,10 @@ Env::rpc(std::string const& cmd, Args&&... args) template concept SingleVersionedTestCallable = requires(T callable, unsigned int v) { - {callable(v)} -> std::same_as; + { + callable(v) + } + ->std::same_as; }; /** From ca39874354639d1659750077d104c87c336389a4 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Tue, 18 Jul 2023 19:05:18 -0400 Subject: [PATCH 09/11] var name --- src/test/jtx/Env.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index b25be484323..1065f83f85c 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -709,10 +709,10 @@ Env::rpc(std::string const& cmd, Args&&... args) * an unsigned integer as its argument and returns void. */ template -concept SingleVersionedTestCallable = requires(T callable, unsigned int v) +concept SingleVersionedTestCallable = requires(T callable, unsigned int version) { { - callable(v) + callable(version) } ->std::same_as; }; From 1ee843f4066dd12261ff68a42d487b475a71c7fc Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Tue, 18 Jul 2023 19:22:42 -0400 Subject: [PATCH 10/11] lambdas -> std::bind_front --- src/test/rpc/AccountTx_test.cpp | 2 +- src/test/rpc/LedgerRPC_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 1cddf1a7ded..05baf869eee 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -667,7 +667,7 @@ class AccountTx_test : public beast::unit_test::suite run() override { test::jtx::forAllApiVersions( - [this](auto version) { testParameters(version); }); + std::bind_front(&AccountTx_test::testParameters, this)); testContents(); testAccountDelete(); } diff --git a/src/test/rpc/LedgerRPC_test.cpp b/src/test/rpc/LedgerRPC_test.cpp index 61e06d8ab88..443209ca726 100644 --- a/src/test/rpc/LedgerRPC_test.cpp +++ b/src/test/rpc/LedgerRPC_test.cpp @@ -1736,8 +1736,8 @@ class LedgerRPC_test : public beast::unit_test::suite testQueue(); testLedgerAccountsOption(); - test::jtx::forAllApiVersions( - [this](auto version) { testLedgerEntryInvalidParams(version); }); + test::jtx::forAllApiVersions(std::bind_front( + &LedgerRPC_test::testLedgerEntryInvalidParams, this)); } }; From 5ea57ab0c1a27adeb16127671600d9ace087f740 Mon Sep 17 00:00:00 2001 From: Arihant Kothari Date: Wed, 19 Jul 2023 23:54:04 -0400 Subject: [PATCH 11/11] test: add forAllApiVersions helper function (#4611) Introduce a new variadic template helper function, `forAllApiVersions`, that accepts callables to execute a set of functions over a range of versions - from RPC::apiMinimumSupportedVersion to RPC::apiBetaVersion. This avoids the duplication of code. Context: #4552