@@ -23,10 +23,12 @@ class BlockClockModelTests : public QObject
2323private Q_SLOTS :
2424 void currentTimeUsesNamedTwelveHourFraction ();
2525 void unchangedSecondDoesNotRepublishCurrentTime ();
26+ void blockArrivalRefreshesCurrentTime ();
2627 void blockHistoryIsSortedUniqueAndPeriodBounded ();
2728 void historyLoadsOnInitializationAndPeriodRollover ();
2829 void emptyHistoryDoesNotEmitRedundantChanges ();
2930 void timerHasModelOwnershipAndCanBeDisabledForTests ();
31+ void timerAlignsToNextMinute ();
3032};
3133
3234void BlockClockModelTests::currentTimeUsesNamedTwelveHourFraction ()
@@ -51,9 +53,26 @@ void BlockClockModelTests::unchangedSecondDoesNotRepublishCurrentTime()
5153 QCOMPARE (current_time_spy.count (), 1 );
5254}
5355
56+ void BlockClockModelTests::blockArrivalRefreshesCurrentTime ()
57+ {
58+ QDateTime current_time{UtcTime (15 )};
59+ BlockClockModel model{{}, false , [&] { return current_time; }};
60+ QSignalSpy current_time_spy{&model, &BlockClockModel::currentTimeFractionChanged};
61+
62+ current_time = UtcTime (15 , 1 );
63+ model.recordBlockTime (UtcTime (15 , 0 , 30 ).toSecsSinceEpoch ());
64+
65+ QCOMPARE (current_time_spy.count (), 1 );
66+ QVERIFY (qAbs (model.currentTimeFraction () - (181.0 / 720.0 )) < 0.000001 );
67+ QCOMPARE (model.blockTimeFractions ().size (), 1 );
68+ QVERIFY (qAbs (model.blockTimeFractions ().constFirst () -
69+ (10830.0 / BlockClockModel::PERIOD_SECONDS )) < 0.000001 );
70+ }
71+
5472void BlockClockModelTests::blockHistoryIsSortedUniqueAndPeriodBounded ()
5573{
56- BlockClockModel model{{}, false };
74+ const QDateTime current_time{UtcTime (15 )};
75+ BlockClockModel model{{}, false , [current_time] { return current_time; }};
5776 model.updateCurrentTime (UtcTime (15 ));
5877 const qint64 start{model.periodStart ()};
5978 QSignalSpy history_spy{&model, &BlockClockModel::blockTimeFractionsChanged};
@@ -106,15 +125,27 @@ void BlockClockModelTests::emptyHistoryDoesNotEmitRedundantChanges()
106125
107126void BlockClockModelTests::timerHasModelOwnershipAndCanBeDisabledForTests ()
108127{
109- BlockClockModel stopped_model{{}, false };
128+ const QDateTime current_time{UtcTime (15 )};
129+ const auto current_time_provider{[current_time] { return current_time; }};
130+ BlockClockModel stopped_model{{}, false , current_time_provider};
110131 QCOMPARE (stopped_model.timerActive (), false );
111132 QCOMPARE (stopped_model.findChildren <QTimer*>().size (), 1 );
112133 QCOMPARE (stopped_model.findChildren <QTimer*>().constFirst ()->parent (), &stopped_model);
113134
114- BlockClockModel running_model{{}, true };
135+ BlockClockModel running_model{{}, true , current_time_provider };
115136 QCOMPARE (running_model.timerActive (), true );
116137}
117138
139+ void BlockClockModelTests::timerAlignsToNextMinute ()
140+ {
141+ const QDateTime current_time{UtcTime (15 , 0 , 45 ).addMSecs (250 )};
142+ BlockClockModel model{{}, true , [current_time] { return current_time; }};
143+ QTimer* timer{model.findChildren <QTimer*>().constFirst ()};
144+
145+ QCOMPARE (timer->timerType (), Qt::PreciseTimer);
146+ QCOMPARE (timer->interval (), BlockClockModel::CLOCK_UPDATE_INTERVAL_MS - 45250 );
147+ }
148+
118149#ifdef BITCOINQML_NO_TEST_MAIN
119150BITCOINQML_REGISTER_QT_TEST (BlockClockModelTests)
120151#else
0 commit comments