Skip to content

Commit

Permalink
fix failing Linux Debug builds: do not call with ValidatorList::load(…
Browse files Browse the repository at this point in the history
…PublicKey::emptyPubKey) -- hits the assert inside the function
  • Loading branch information
ckeshava committed Oct 20, 2023
1 parent 44627dc commit 236c4ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/test/app/Manifest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Manifest_test : public beast::unit_test::suite
for (auto const& man : inManifests)
s1.push_back(
toBase58(TokenType::NodePublic, man->masterKey));
unl->load(emptyLocalKey, s1, keys);
unl->load({}, s1, keys);

m.save(
*dbCon,
Expand Down
78 changes: 29 additions & 49 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ class ValidatorList_test : public beast::unit_test::suite
jtx::Env env(
*this, jtx::envconfig(), nullptr, beast::severities::kDisabled);
auto& app = env.app();
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> const emptyCfgKeys;
std::vector<std::string> const emptyCfgPublishers;

Expand Down Expand Up @@ -278,8 +277,8 @@ class ValidatorList_test : public beast::unit_test::suite
env.journal);

// Correct (empty) configuration
BEAST_EXPECT(trustedKeys->load(
emptyLocalKey, emptyCfgKeys, emptyCfgPublishers));
BEAST_EXPECT(
trustedKeys->load({}, emptyCfgKeys, emptyCfgPublishers));

// load local validator key with or without manifest
BEAST_EXPECT(trustedKeys->load(
Expand All @@ -303,8 +302,7 @@ class ValidatorList_test : public beast::unit_test::suite
app.config().legacy("database_path"),
env.journal);

BEAST_EXPECT(
trustedKeys->load(emptyLocalKey, cfgKeys, emptyCfgPublishers));
BEAST_EXPECT(trustedKeys->load({}, cfgKeys, emptyCfgPublishers));

for (auto const& n : configList)
BEAST_EXPECT(trustedKeys->listed(n));
Expand All @@ -315,23 +313,21 @@ class ValidatorList_test : public beast::unit_test::suite

std::vector<std::string> cfgMasterKeys(
{format(masterNode1), format(masterNode2, " Comment")});
BEAST_EXPECT(trustedKeys->load(
emptyLocalKey, cfgMasterKeys, emptyCfgPublishers));
BEAST_EXPECT(
trustedKeys->load({}, cfgMasterKeys, emptyCfgPublishers));
BEAST_EXPECT(trustedKeys->listed(masterNode1));
BEAST_EXPECT(trustedKeys->listed(masterNode2));

// load should reject invalid config keys
BEAST_EXPECT(
!trustedKeys->load({}, {"NotAPublicKey"}, emptyCfgPublishers));
BEAST_EXPECT(!trustedKeys->load(
emptyLocalKey, {"NotAPublicKey"}, emptyCfgPublishers));
BEAST_EXPECT(!trustedKeys->load(
emptyLocalKey,
{format(randomNode(), "!")},
emptyCfgPublishers));
{}, {format(randomNode(), "!")}, emptyCfgPublishers));

// load terminates when encountering an invalid entry
auto const goodKey = randomNode();
BEAST_EXPECT(!trustedKeys->load(
emptyLocalKey,
{},
{format(randomNode(), "!"), format(goodKey)},
emptyCfgPublishers));
BEAST_EXPECT(!trustedKeys->listed(goodKey));
Expand Down Expand Up @@ -408,8 +404,7 @@ class ValidatorList_test : public beast::unit_test::suite

// load should reject invalid validator list signing keys
std::vector<std::string> badPublishers({"NotASigningKey"});
BEAST_EXPECT(
!trustedKeys->load(emptyLocalKey, emptyCfgKeys, badPublishers));
BEAST_EXPECT(!trustedKeys->load({}, emptyCfgKeys, badPublishers));

// load should reject validator list signing keys with invalid
// encoding
Expand All @@ -419,8 +414,7 @@ class ValidatorList_test : public beast::unit_test::suite
for (auto const& key : keys)
badPublishers.push_back(toBase58(TokenType::NodePublic, key));

BEAST_EXPECT(
!trustedKeys->load(emptyLocalKey, emptyCfgKeys, badPublishers));
BEAST_EXPECT(!trustedKeys->load({}, emptyCfgKeys, badPublishers));
for (auto const& key : keys)
BEAST_EXPECT(!trustedKeys->trustedPublisher(key));

Expand All @@ -429,8 +423,7 @@ class ValidatorList_test : public beast::unit_test::suite
for (auto const& key : keys)
cfgPublishers.push_back(strHex(key));

BEAST_EXPECT(
trustedKeys->load(emptyLocalKey, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublishers));
for (auto const& key : keys)
BEAST_EXPECT(trustedKeys->trustedPublisher(key));
}
Expand Down Expand Up @@ -464,8 +457,7 @@ class ValidatorList_test : public beast::unit_test::suite

std::vector<std::string> cfgPublishers = {
strHex(pubRevokedPublic), strHex(legitKey)};
BEAST_EXPECT(
trustedKeys->load(emptyLocalKey, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublishers));

BEAST_EXPECT(!trustedKeys->trustedPublisher(pubRevokedPublic));
BEAST_EXPECT(trustedKeys->trustedPublisher(legitKey));
Expand Down Expand Up @@ -569,10 +561,9 @@ class ValidatorList_test : public beast::unit_test::suite
1));

std::vector<std::string> cfgKeys1({strHex(publisherPublic)});
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;

BEAST_EXPECT(trustedKeys->load(emptyLocalKey, emptyCfgKeys, cfgKeys1));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys1));

std::map<std::size_t, std::vector<Validator>> const lists = []() {
auto constexpr listSize = 20;
Expand Down Expand Up @@ -954,10 +945,9 @@ class ValidatorList_test : public beast::unit_test::suite
1));

std::vector<std::string> cfgKeys1({strHex(publisherPublic)});
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;

BEAST_EXPECT(trustedKeys->load(emptyLocalKey, emptyCfgKeys, cfgKeys1));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys1));

std::vector<Validator> const list = []() {
auto constexpr listSize = 20;
Expand Down Expand Up @@ -1066,7 +1056,6 @@ class ValidatorList_test : public beast::unit_test::suite

std::string const siteUri = "testUpdateTrusted.test";

PublicKey emptyLocalKeyOuter(PublicKey::emptyPubKey);
ManifestCache manifestsOuter;
jtx::Env env(*this);
auto& app = env.app();
Expand Down Expand Up @@ -1096,8 +1085,8 @@ class ValidatorList_test : public beast::unit_test::suite
unseenValidators.emplace(calcNodeID(valKey));
}

BEAST_EXPECT(trustedKeysOuter->load(
emptyLocalKeyOuter, cfgKeys, cfgPublishersOuter));
BEAST_EXPECT(
trustedKeysOuter->load({}, cfgKeys, cfgPublishersOuter));

// updateTrusted should make all configured validators trusted
// even if they are not active/seen
Expand Down Expand Up @@ -1147,8 +1136,8 @@ class ValidatorList_test : public beast::unit_test::suite
std::vector<std::string> cfgKeys(
{toBase58(TokenType::NodePublic, masterPublic)});

BEAST_EXPECT(trustedKeysOuter->load(
emptyLocalKeyOuter, cfgKeys, cfgPublishersOuter));
BEAST_EXPECT(
trustedKeysOuter->load({}, cfgKeys, cfgPublishersOuter));

auto const signingKeys1 = randomKeyPair(KeyType::secp256k1);
auto const signingPublic1 = signingKeys1.first;
Expand Down Expand Up @@ -1260,8 +1249,7 @@ class ValidatorList_test : public beast::unit_test::suite
std::vector<std::string> cfgPublishers({strHex(publisherPublic)});
std::vector<std::string> emptyCfgKeys;

BEAST_EXPECT(trustedKeys->load(
emptyLocalKeyOuter, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublishers));

TrustChanges changes = trustedKeys->updateTrusted(
activeValidatorsOuter,
Expand Down Expand Up @@ -1305,8 +1293,7 @@ class ValidatorList_test : public beast::unit_test::suite
toBeSeen = calcNodeID(valKey);
}

BEAST_EXPECT(trustedKeys->load(
emptyLocalKeyOuter, cfgKeys, cfgPublishersOuter));
BEAST_EXPECT(trustedKeys->load({}, cfgKeys, cfgPublishersOuter));

TrustChanges changes = trustedKeys->updateTrusted(
activeValidators,
Expand Down Expand Up @@ -1339,7 +1326,6 @@ class ValidatorList_test : public beast::unit_test::suite
app.config().legacy("database_path"),
env.journal);

PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;
auto const publisherKeys = randomKeyPair(KeyType::secp256k1);
auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1);
Expand All @@ -1352,8 +1338,7 @@ class ValidatorList_test : public beast::unit_test::suite

std::vector<std::string> cfgKeys({strHex(publisherKeys.first)});

BEAST_EXPECT(
trustedKeys->load(emptyLocalKey, emptyCfgKeys, cfgKeys));
BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys));

std::vector<Validator> list({randomValidator(), randomValidator()});
hash_set<NodeID> activeValidators(
Expand Down Expand Up @@ -1463,8 +1448,7 @@ class ValidatorList_test : public beast::unit_test::suite
cfgKeys.push_back(toBase58(TokenType::NodePublic, valKey));
activeValidators.emplace(calcNodeID(valKey));
activeKeys.emplace(valKey);
BEAST_EXPECT(trustedKeys->load(
emptyLocalKeyOuter, cfgKeys, cfgPublishers));
BEAST_EXPECT(trustedKeys->load({}, cfgKeys, cfgPublishers));
TrustChanges changes = trustedKeys->updateTrusted(
activeValidators,
env.timeKeeper().now(),
Expand Down Expand Up @@ -1564,11 +1548,10 @@ class ValidatorList_test : public beast::unit_test::suite

std::vector<std::string> cfgPublishers(
{strHex(publisherPublic)});
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;

BEAST_EXPECT(trustedKeys->load(
emptyLocalKey, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(
trustedKeys->load({}, emptyCfgKeys, cfgPublishers));

auto const version = 1;
auto const sequence = 1;
Expand Down Expand Up @@ -1640,9 +1623,8 @@ class ValidatorList_test : public beast::unit_test::suite
BEAST_EXPECT(trustedKeys->expires() == std::nullopt);

// Config listed keys have maximum expiry
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
PublicKey localCfgListed = randomNode();
trustedKeys->load(emptyLocalKey, {toStr(localCfgListed)}, {});
trustedKeys->load({}, {toStr(localCfgListed)}, {});
BEAST_EXPECT(
trustedKeys->expires() &&
trustedKeys->expires().value() == NetClock::time_point::max());
Expand Down Expand Up @@ -1688,11 +1670,10 @@ class ValidatorList_test : public beast::unit_test::suite

std::vector<std::string> cfgPublishers(
{strHex(publisherPublic)});
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;

BEAST_EXPECT(trustedKeys->load(
emptyLocalKey, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(
trustedKeys->load({}, emptyCfgKeys, cfgPublishers));

auto const version = 2;
auto const sequence1 = 1;
Expand Down Expand Up @@ -1795,7 +1776,6 @@ class ValidatorList_test : public beast::unit_test::suite
{
testcase("NegativeUNL");
jtx::Env env(*this);
PublicKey emptyLocalKey(PublicKey::emptyPubKey);
ManifestCache manifests;

auto createValidatorList =
Expand All @@ -1820,7 +1800,7 @@ class ValidatorList_test : public beast::unit_test::suite
cfgKeys.push_back(toBase58(TokenType::NodePublic, valKey));
activeValidators.emplace(calcNodeID(valKey));
}
if (trustedKeys->load(emptyLocalKey, cfgKeys, cfgPublishers))
if (trustedKeys->load({}, cfgKeys, cfgPublishers))
{
trustedKeys->updateTrusted(
activeValidators,
Expand Down
4 changes: 1 addition & 3 deletions src/test/app/ValidatorSite_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class ValidatorSite_test : public beast::unit_test::suite
test::StreamSink sink;
beast::Journal journal{sink};

PublicKey emptyLocalKey(PublicKey::emptyPubKey);
std::vector<std::string> emptyCfgKeys;
struct publisher
{
Expand Down Expand Up @@ -229,8 +228,7 @@ class ValidatorSite_test : public beast::unit_test::suite
item.uri = uri.str();
}

BEAST_EXPECT(
trustedKeys.load(emptyLocalKey, emptyCfgKeys, cfgPublishers));
BEAST_EXPECT(trustedKeys.load({}, emptyCfgKeys, cfgPublishers));

// Normally, tests will only need a fraction of this time,
// but sometimes DNS resolution takes an inordinate amount
Expand Down

0 comments on commit 236c4ef

Please sign in to comment.