Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add forAllApiVersions helper function #4611

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/test/jtx/Env.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STObject.h>
#include <ripple/protocol/STTx.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <functional>
#include <string>
#include <test/jtx/AbstractClient.h>
Expand Down Expand Up @@ -715,6 +716,40 @@ Env::rpc(std::string const& cmd, Args&&... args)
std::forward<Args>(args)...);
}

/**
* The SingleVersionedTestCallable concept checks for a callable that takes
* an unsigned integer as its argument and returns void.
*/
template <class T>
concept SingleVersionedTestCallable = requires(T callable, unsigned int version)
{
{
callable(version)
}
->std::same_as<void>;
};

/**
* 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 <class... T>
concept VersionedTestCallable = (... && SingleVersionedTestCallable<T>);
void
forAllApiVersions(VersionedTestCallable auto... testCallable)
{
for (auto testVersion = RPC::apiMinimumSupportedVersion;
testVersion <= RPC::apiBetaVersion;
++testVersion)
{
(..., testCallable(testVersion));
}
}

} // namespace jtx
} // namespace test
} // namespace ripple
Expand Down
9 changes: 2 additions & 7 deletions src/test/rpc/AccountTx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <ripple/beast/unit_test.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <test/jtx.h>

#include <boost/container/flat_set.hpp>
Expand Down Expand Up @@ -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(
std::bind_front(&AccountTx_test::testParameters, this));
testContents();
testAccountDelete();
}
Expand Down
10 changes: 2 additions & 8 deletions src/test/rpc/LedgerRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <ripple/beast/unit_test.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <test/jtx.h>

namespace ripple {
Expand Down Expand Up @@ -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(std::bind_front(
&LedgerRPC_test::testLedgerEntryInvalidParams, this));
}
};

Expand Down