Skip to content

Commit

Permalink
Improve version loop and static asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 23, 2023
1 parent 70bd1b7 commit 1cb93ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3150,10 +3150,15 @@ NetworkOPsImp::transJson(
}

MultiApiJson multiObj({jvObj, jvObj});
static_assert(MultiApiJson::size == 2);
static_assert(RPC::apiMinimumSupportedVersion == 1);
for (unsigned apiVersion = 1, lastIndex = MultiApiJson::size;
apiVersion <= 2;
// Minimum supported API version must match index 0 in MultiApiJson
static_assert(apiVersionSelector(RPC::apiMinimumSupportedVersion)() == 0);
// Beta API version must match last index in MultiApiJson
static_assert(
apiVersionSelector(RPC::apiBetaVersion)() + 1 //
== MultiApiJson::size);
for (unsigned apiVersion = RPC::apiMinimumSupportedVersion,
lastIndex = MultiApiJson::size;
apiVersion <= RPC::apiBetaVersion;
++apiVersion)
{
unsigned const index = apiVersionSelector(apiVersion)();
Expand Down
15 changes: 15 additions & 0 deletions src/test/json/MultivarJson_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//==============================================================================

#include <ripple/json/MultivarJson.h>
#include <ripple/rpc/impl/RPCHelpers.h>

#include <ripple/beast/unit_test.h>
#include "ripple/beast/unit_test/suite.hpp"
Expand Down Expand Up @@ -244,6 +245,7 @@ struct MultivarJson_test : beast::unit_test::suite
}

{
// NOTE It's fine to change this test when we change API versions
testcase("apiVersionSelector");

static_assert(MultiApiJson::size == 2);
Expand All @@ -269,6 +271,19 @@ struct MultivarJson_test : beast::unit_test::suite
apiVersionSelector(
std::numeric_limits<unsigned int>::max())() == 1);
}

{
// There should be no reson to change this test
testcase("apiVersionSelector invariants");

static_assert(
apiVersionSelector(RPC::apiMinimumSupportedVersion)() == 0);
static_assert(
apiVersionSelector(RPC::apiBetaVersion)() + 1 //
== MultiApiJson::size);

BEAST_EXPECT(MultiApiJson::size >= 1);
}
}
};

Expand Down

0 comments on commit 1cb93ec

Please sign in to comment.