@@ -4,7 +4,6 @@ import com.nhaarman.mockito_kotlin.*
44import helpers.RxTestRule
55import io.horizontalsystems.bitcoinkit.RealmFactoryMock
66import io.horizontalsystems.bitcoinkit.core.ISyncStateListener
7- import io.horizontalsystems.bitcoinkit.models.Block
87import io.horizontalsystems.bitcoinkit.models.BlockHash
98import io.horizontalsystems.bitcoinkit.models.PublicKey
109import io.horizontalsystems.bitcoinkit.network.peer.PeerGroup
@@ -20,7 +19,7 @@ import java.util.concurrent.TimeUnit
2019class InitialSyncerTest {
2120
2221 private val factories = RealmFactoryMock ()
23- private val initialSyncerApi = mock(InitialSyncerApi ::class .java)
22+ private val initialSyncerApi = mock(BlockDiscoveryBatch ::class .java)
2423 private val kitStateListener = mock(ISyncStateListener ::class .java)
2524
2625 private val stateManager = mock(StateManager ::class .java)
@@ -48,10 +47,10 @@ class InitialSyncerTest {
4847 @Test
4948 fun sync () {
5049 whenever(stateManager.restored).thenReturn(false )
51- whenever(initialSyncerApi.fetchFromApi (0 , true )).thenReturn(apiRespStub)
52- whenever(initialSyncerApi.fetchFromApi (0 , false )).thenReturn(apiRespStub)
53- whenever(initialSyncerApi.fetchFromApi (1 , true )).thenReturn(Single .just(Pair (listOf (), listOf ())))
54- whenever(initialSyncerApi.fetchFromApi (1 , false )).thenReturn(Single .just(Pair (listOf (), listOf ())))
50+ whenever(initialSyncerApi.discoverBlockHashes (0 , true )).thenReturn(apiRespStub)
51+ whenever(initialSyncerApi.discoverBlockHashes (0 , false )).thenReturn(apiRespStub)
52+ whenever(initialSyncerApi.discoverBlockHashes (1 , true )).thenReturn(Single .just(Pair (listOf (), listOf ())))
53+ whenever(initialSyncerApi.discoverBlockHashes (1 , false )).thenReturn(Single .just(Pair (listOf (), listOf ())))
5554
5655 initialSyncer.sync()
5756
@@ -65,8 +64,8 @@ class InitialSyncerTest {
6564 val responseWithTimeout = apiRespStub.timeout(1 , TimeUnit .SECONDS )
6665
6766 whenever(stateManager.restored).thenReturn(false )
68- whenever(initialSyncerApi.fetchFromApi (0 , true )).thenReturn(responseWithTimeout)
69- whenever(initialSyncerApi.fetchFromApi (0 , false )).thenReturn(responseWithTimeout)
67+ whenever(initialSyncerApi.discoverBlockHashes (0 , true )).thenReturn(responseWithTimeout)
68+ whenever(initialSyncerApi.discoverBlockHashes (0 , false )).thenReturn(responseWithTimeout)
7069
7170 initialSyncer.sync()
7271 initialSyncer.stop()
@@ -77,8 +76,8 @@ class InitialSyncerTest {
7776 // @Test
7877 // fun refresh() {
7978 // whenever(stateManager.restored).thenReturn(false)
80- // whenever(initialSyncerApi.fetchFromApi (true)).thenReturn(apiRespStub)
81- // whenever(initialSyncerApi.fetchFromApi (false)).thenReturn(apiRespStub)
79+ // whenever(initialSyncerApi.discoverBlockHashes (true)).thenReturn(apiRespStub)
80+ // whenever(initialSyncerApi.discoverBlockHashes (false)).thenReturn(apiRespStub)
8281 //
8382 // initialSyncer.sync()
8483 // initialSyncer.sync() // refresh
@@ -130,10 +129,10 @@ class InitialSyncerTest {
130129
131130 whenever(stateManager.restored).thenReturn(false )
132131
133- whenever(initialSyncerApi.fetchFromApi (0 , true )).thenReturn(externalObservable)
134- whenever(initialSyncerApi.fetchFromApi (0 , false )).thenReturn(internalObservable)
135- whenever(initialSyncerApi.fetchFromApi (1 , true )).thenReturn(Single .just(Pair (listOf (), listOf ())))
136- whenever(initialSyncerApi.fetchFromApi (1 , false )).thenReturn(Single .just(Pair (listOf (), listOf ())))
132+ whenever(initialSyncerApi.discoverBlockHashes (0 , true )).thenReturn(externalObservable)
133+ whenever(initialSyncerApi.discoverBlockHashes (0 , false )).thenReturn(internalObservable)
134+ whenever(initialSyncerApi.discoverBlockHashes (1 , true )).thenReturn(Single .just(Pair (listOf (), listOf ())))
135+ whenever(initialSyncerApi.discoverBlockHashes (1 , false )).thenReturn(Single .just(Pair (listOf (), listOf ())))
137136
138137 initialSyncer.sync()
139138
@@ -156,16 +155,16 @@ class InitialSyncerTest {
156155 fun sync_apiNotSynced_blocksDiscoveredFail () {
157156 whenever(stateManager.restored).thenReturn(false )
158157
159- whenever(initialSyncerApi.fetchFromApi (0 , true )).thenReturn(Single .error(Exception ()))
160- whenever(initialSyncerApi.fetchFromApi (0 , false )).thenReturn(Single .error(Exception ()))
158+ whenever(initialSyncerApi.discoverBlockHashes (0 , true )).thenReturn(Single .error(Exception ()))
159+ whenever(initialSyncerApi.discoverBlockHashes (0 , false )).thenReturn(Single .error(Exception ()))
161160
162161 initialSyncer.sync()
163162
164163 verify(stateManager, never()).restored = true
165164 verifyNoMoreInteractions(peerGroup)
166165
167166 assertTrue(realm.where(PublicKey ::class .java).findAll().isEmpty())
168- assertTrue(realm.where(Block ::class .java).findAll().isEmpty())
167+ assertTrue(realm.where(BlockHash ::class .java).findAll().isEmpty())
169168 }
170169
171170 private fun containsBlock (blocks : List <BlockHash >, block : BlockHash ) =
0 commit comments