File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed
main/kotlin/org.vechain.indexer
test/kotlin/org/vechain/indexer Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ jacoco {
2020
2121group = " org.vechain"
2222
23- val projectVersion = System .getenv(" PROJECT_VERSION" ) ? : " 6.3.0 "
23+ val projectVersion = System .getenv(" PROJECT_VERSION" ) ? : " 6.3.1 "
2424version = projectVersion
2525
2626val isSnapshot = version.toString().endsWith(" SNAPSHOT" )
Original file line number Diff line number Diff line change @@ -88,10 +88,14 @@ open class BlockIndexer(
8888 /* *
8989 * Rolls back to a safe state to ensure data integrity.
9090 *
91+ * Only rolls back if the block number is greater than zero.
92+ *
9193 * @param blockNumber The block number to roll back to.
9294 */
9395 protected open fun rollbackToSafeState (blockNumber : Long ) {
94- rollback(blockNumber)
96+ if (blockNumber > 0 ) {
97+ rollback(blockNumber)
98+ }
9599 }
96100
97101 /* *
Original file line number Diff line number Diff line change @@ -205,10 +205,8 @@ internal class BlockIndexerTest {
205205
206206 indexer.initialise()
207207
208- verify(exactly = 2 ) {
209- processor.getLastSyncedBlock()
210- } // Verify the rollback is performed once
211- verify(exactly = 1 ) { processor.rollback(0L ) }
208+ verify(exactly = 2 ) { processor.getLastSyncedBlock() }
209+ verify(exactly = 0 ) { processor.rollback(any()) }
212210
213211 expect {
214212 // Verify the status is INITIALISED
@@ -221,6 +219,29 @@ internal class BlockIndexerTest {
221219 }
222220 }
223221
222+ @Test
223+ fun `Should rollback to startBlock when startBlock is greater than zero and no last synced block` () =
224+ runBlocking {
225+ indexer =
226+ BlockIndexer (
227+ name = " TestBlockIndexer" ,
228+ thorClient = thorClient,
229+ processor = processor,
230+ startBlock = 50L ,
231+ eventProcessor = null ,
232+ pruner = null ,
233+ prunerInterval = 10000L ,
234+ syncLoggerInterval = 1L ,
235+ inspectionClauses = null ,
236+ dependsOn = null ,
237+ )
238+ every { processor.getLastSyncedBlock() } returns null
239+
240+ indexer.initialise()
241+
242+ verify(exactly = 1 ) { processor.rollback(50L ) }
243+ }
244+
224245 @Test
225246 fun `Previous block should be null if last synced block doesn't match current block - 1` () {
226247 every { processor.getLastSyncedBlock() } returns
You can’t perform that action at this time.
0 commit comments