From: Jack Grigg Date: Fri, 28 Jul 2017 10:35:46 +0000 (+0000) Subject: Correct and extend EstimateNetHeightInner tests X-Git-Url: https://repo.jachan.dev/VerusCoin.git/commitdiff_plain/4a651837be5840e3f023a03a9a91c6537009153b Correct and extend EstimateNetHeightInner tests Corrections are to the median block times, which were generated by subtracting CBlockIndex::nMedianTimeSpan / 2 from the block height and then multiplying by the target spacing. GetMedianTimePast() takes an array sorted by std::sort() and returns element CBlockIndex::nMedianTimeSpan / 2, meaning that if CBlockIndex::nMedianTimeSpan is odd (which it is), there is an out-by-one error in the subtraction. --- diff --git a/src/gtest/test_metrics.cpp b/src/gtest/test_metrics.cpp index 8e0aa9e02..8f313b5d2 100644 --- a/src/gtest/test_metrics.cpp +++ b/src/gtest/test_metrics.cpp @@ -96,24 +96,40 @@ TEST(Metrics, GetLocalSolPS) { TEST(Metrics, EstimateNetHeightInner) { // Ensure that the (rounded) current height is returned if the tip is current SetMockTime(15000); - EXPECT_EQ(100, EstimateNetHeightInner(100, 14250, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(100, 14100, 50, 7500, 150)); SetMockTime(15150); - EXPECT_EQ(100, EstimateNetHeightInner(101, 14400, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(101, 14250, 50, 7500, 150)); // Ensure that correct estimates are returned if the tip is in the past SetMockTime(15300); // Tip is 2 blocks behind - EXPECT_EQ(100, EstimateNetHeightInner(100, 14250, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(100, 14100, 50, 7500, 150)); SetMockTime(15900); // Tip is 6 blocks behind - EXPECT_EQ(110, EstimateNetHeightInner(100, 14250, 50, 7500, 150)); + EXPECT_EQ(110, EstimateNetHeightInner(100, 14100, 50, 7500, 150)); + + // Check estimates during resync + SetMockTime(15000); + EXPECT_EQ(100, EstimateNetHeightInner( 0, 0, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner( 7, 600, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner( 8, 600, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(10, 750, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(11, 900, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(20, 2100, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(49, 6450, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(50, 6600, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(51, 6750, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(55, 7350, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(56, 7500, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(57, 7650, 50, 7500, 150)); + EXPECT_EQ(100, EstimateNetHeightInner(75, 10350, 50, 7500, 150)); // More complex calculations: SetMockTime(20000); // - Checkpoint spacing: 200 // -> Average spacing: 175 // -> estimated height: 127 -> 130 - EXPECT_EQ(130, EstimateNetHeightInner(100, 14250, 50, 5250, 150)); + EXPECT_EQ(130, EstimateNetHeightInner(100, 14100, 50, 5250, 150)); // - Checkpoint spacing: 50 // -> Average spacing: 100 // -> estimated height: 153 -> 150 - EXPECT_EQ(150, EstimateNetHeightInner(100, 14250, 50, 12000, 150)); + EXPECT_EQ(150, EstimateNetHeightInner(100, 14100, 50, 12000, 150)); }