Skip to content

Commit

Permalink
add vl list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Jul 10, 2023
1 parent 92d512c commit 7625039
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,10 +1988,7 @@ ValidatorList::getFirstPublisherListJson()
{
shared_lock lock(mutex_);
if (publisherLists_.empty())
{
std::cout << "publisherLists_ empty\n";
return {};
}

Json::Value ret;

Expand Down
74 changes: 74 additions & 0 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/
//==============================================================================

#include <ripple/app/main/BasicApp.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/basics/Slice.h>
#include <ripple/basics/base64.h>
#include <ripple/basics/strHex.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/overlay/impl/ProtocolMessage.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/PublicKey.h>
Expand All @@ -30,6 +32,7 @@
#include <ripple/protocol/jss.h>
#include <ripple/protocol/messages.h>
#include <test/jtx.h>
#include <test/jtx/TrustedPublisherServer.h>

#include <boost/beast/core/multi_buffer.hpp>

Expand Down Expand Up @@ -2410,6 +2413,76 @@ class ValidatorList_test : public beast::unit_test::suite
{{108, {6}}, {108, {7}}, {110, {10}}, {110, {12}}});
}

std::unique_ptr<Config>
makeVLConfig()
{
using namespace jtx;
using namespace std::string_literals;

std::vector<TrustedPublisherServer::Validator> validators1 = {
TrustedPublisherServer::randomValidator(),
TrustedPublisherServer::randomValidator()};

// Manage single-thread io_service for server.
BasicApp worker{1};
using namespace std::chrono_literals;
NetClock::time_point const validUntil{3600s};
NetClock::time_point const validFrom2{validUntil - 60s};
NetClock::time_point const validUntil2{validFrom2 + 3600s};
auto server1 = make_TrustedPublisherServer(
worker.get_io_service(),
validators1,
validUntil,
{{validFrom2, validUntil2}},
false,
1,
false);

std::string siteURI1 =
"http://"s + getEnvLocalhostAddr() + ":1234/validators1";
return envconfig([&](std::unique_ptr<Config> cfg) {
cfg->section(SECTION_VALIDATOR_LIST_SITES).append(siteURI1);
cfg->section(SECTION_VALIDATOR_LIST_KEYS).append(strHex(server1->publisherPublic()));
cfg->XPOP_DIR = "xpop";
return cfg;
});
}

void testGetFirstPublisherListJson()
{
testcase("getFirstPublisherListJson");

using namespace test::jtx;
using namespace std::literals;

// Test case 1: publisherLists_ is empty
{
test::jtx::Env env{*this};
auto const unl = env.app().validators().getFirstPublisherListJson();
BEAST_EXPECT(!unl.has_value());
}

// Test case 2: publisherLists_ is not empty
{
test::jtx::Env env{*this, makeVLConfig()};
auto const unl = env.app().validators().getFirstPublisherListJson();
BEAST_EXPECT(unl.has_value());
}

// Test case 3: publisherLists_ is from cache
{
test::jtx::Env env{*this, makeVLConfig()};
auto const unl = env.app().validators().getFirstPublisherListJson();
BEAST_EXPECT(unl.has_value());
auto const public_key = (*unl)[jss::public_key];
BEAST_EXPECT(public_key != nullptr);
auto const unl1 = env.app().validators().getFirstPublisherListJson();
BEAST_EXPECT(unl1.has_value());
BEAST_EXPECT((*unl1)[jss::public_key] == public_key);
// DA TODO: Change Publisher List and verify updated cached
}
}

public:
void
run() override
Expand All @@ -2423,6 +2496,7 @@ class ValidatorList_test : public beast::unit_test::suite
testNegativeUNL();
testSha512Hash();
testBuildMessages();
testGetFirstPublisherListJson();
}
}; // namespace test

Expand Down

0 comments on commit 7625039

Please sign in to comment.