@@ -205,7 +205,7 @@ func TestNewPeerTypeProvider_ComputeForKeyNotFoundInCacheReturnsObserver(t *test
205205 assert .Nil (t , err )
206206}
207207
208- func TestPeerTypeProvider_IsCachePopulated_FalseAtConstruction (t * testing.T ) {
208+ func TestPeerTypeProvider_IsCachePopulated_FalseWhenCoordinatorReturnsEmpty (t * testing.T ) {
209209 arg := createDefaultArgPeerTypeProvider ()
210210
211211 ptp , err := NewPeerTypeProvider (arg )
@@ -215,21 +215,57 @@ func TestPeerTypeProvider_IsCachePopulated_FalseAtConstruction(t *testing.T) {
215215 assert .False (t , ptp .IsCachePopulated ())
216216}
217217
218- func TestPeerTypeProvider_IsCachePopulated_TrueAfterEpochStart (t * testing.T ) {
218+ func TestPeerTypeProvider_IsCachePopulated_TrueAtConstructionWhenCachePopulated (t * testing.T ) {
219+ arg := createDefaultArgPeerTypeProvider ()
220+ arg .NodesCoordinator = & mock.NodesCoordinatorMock {
221+ GetAllElectedValidatorsKeysCalled : func () ([][]byte , error ) {
222+ return [][]byte {[]byte ("validator-pk" )}, nil
223+ },
224+ }
225+
226+ ptp , err := NewPeerTypeProvider (arg )
227+ require .Nil (t , err )
228+ require .NotNil (t , ptp )
229+
230+ assert .True (t , ptp .IsCachePopulated ())
231+ }
232+
233+ func TestPeerTypeProvider_IsCachePopulated_TrueAfterEpochStartFillsCache (t * testing.T ) {
219234 arg := createDefaultArgPeerTypeProvider ()
220235 epochStartNotifier := & mock.EpochStartNotifierStub {}
221236 arg .EpochStartEventNotifier = epochStartNotifier
222237
238+ coordinator := & mock.NodesCoordinatorMock {}
239+ arg .NodesCoordinator = coordinator
240+
223241 ptp , err := NewPeerTypeProvider (arg )
224242 require .Nil (t , err )
225243 require .NotNil (t , ptp )
226244 require .False (t , ptp .IsCachePopulated ())
227245
246+ coordinator .GetAllElectedValidatorsKeysCalled = func () ([][]byte , error ) {
247+ return [][]byte {[]byte ("validator-pk" )}, nil
248+ }
228249 epochStartNotifier .NotifyAll (& block.Block {Header : & block.BlockHeader {Nonce : 1 , Epoch : 1 }})
229250
230251 assert .True (t , ptp .IsCachePopulated ())
231252}
232253
254+ func TestPeerTypeProvider_IsCachePopulated_StaysFalseWhenEpochStartFiresButCacheEmpty (t * testing.T ) {
255+ arg := createDefaultArgPeerTypeProvider ()
256+ epochStartNotifier := & mock.EpochStartNotifierStub {}
257+ arg .EpochStartEventNotifier = epochStartNotifier
258+
259+ ptp , err := NewPeerTypeProvider (arg )
260+ require .Nil (t , err )
261+ require .NotNil (t , ptp )
262+ require .False (t , ptp .IsCachePopulated ())
263+
264+ epochStartNotifier .NotifyAll (& block.Block {Header : & block.BlockHeader {Nonce : 1 , Epoch : 1 }})
265+
266+ assert .False (t , ptp .IsCachePopulated ())
267+ }
268+
233269func TestNewPeerTypeProvider_IsInterfaceNil (t * testing.T ) {
234270 arg := createDefaultArgPeerTypeProvider ()
235271
0 commit comments