Skip to content

Commit

Permalink
[FOLD] Add unexpired list test
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb committed Oct 4, 2017
1 parent 1145465 commit 3bb20f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ ValidatorList::applyList (
(iOld != oldList.end () && *iOld < *iNew))
{
// Decrement list count for removed keys
if (keyListings_[*iOld] == 1)
if (keyListings_[*iOld] <= 1)
keyListings_.erase (*iOld);
else
--keyListings_[*iOld];
Expand Down
28 changes: 25 additions & 3 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ class ValidatorList_test : public beast::unit_test::suite
BEAST_EXPECT(trustedKeys->load (
emptyLocalKey, emptyCfgKeys, cfgKeys));

std::vector<PublicKey> list ({randomNode()});
hash_set<PublicKey> activeValidators ({ list[0] });
std::vector<PublicKey> list ({randomNode(), randomNode()});
hash_set<PublicKey> activeValidators ({ list[0], list[1] });

auto const version = 1;
auto const sequence = 1;
Expand All @@ -740,13 +740,35 @@ class ValidatorList_test : public beast::unit_test::suite

trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(trustedKeys->trusted (list[0]));
BEAST_EXPECT(trustedKeys->quorum () == 1);
BEAST_EXPECT(trustedKeys->trusted (list[1]));
BEAST_EXPECT(trustedKeys->quorum () == 2);

env.timeKeeper().set(expiration);
trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(! trustedKeys->trusted (list[0]));
BEAST_EXPECT(! trustedKeys->trusted (list[1]));
BEAST_EXPECT(trustedKeys->quorum () ==
std::numeric_limits<std::size_t>::max());

// (Re)trust validators from new valid list
std::vector<PublicKey> list2 ({list[0], randomNode()});
activeValidators.insert(list2[1]);
auto const sequence2 = 2;
NetClock::time_point const expiration2 =
env.timeKeeper().now() + 60s;
auto const blob2 = makeList (
list2, sequence2, expiration2.time_since_epoch().count());
auto const sig2 = signList (blob2, pubSigningKeys);

BEAST_EXPECT(ListDisposition::accepted ==
trustedKeys->applyList (
manifest, blob2, sig2, version));

trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(trustedKeys->trusted (list[0]));
BEAST_EXPECT(trustedKeys->trusted (list2[1]));
BEAST_EXPECT(! trustedKeys->trusted (list[1]));
BEAST_EXPECT(trustedKeys->quorum () == 2);
}
{
// Test 1-9 configured validators
Expand Down

0 comments on commit 3bb20f9

Please sign in to comment.