Skip to content

Commit

Permalink
PM-3133: Test BlockExecutor.syncState
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jun 18, 2021
1 parent 2d3a433 commit ea32ed5
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ object BlockExecutorProps extends Properties("BlockExecutor") {
def syncState(
sources: NonEmptyVector[Int],
block: TestBlock
): Task[Boolean] = ???
): Task[Boolean] =
Task.pure(true)

def executeBlock(
block: TestBlock,
Expand Down Expand Up @@ -355,4 +356,38 @@ object BlockExecutorProps extends Properties("BlockExecutor") {
}
}
}

property("syncState") = forAll { (fixture: TestFixture) =>
run {
fixture.resources.use { res =>
val lastBatch = fixture.batches.last
for {
block <- fixture.storeRunner.runReadOnly {
TestBlockStorage.get(lastBatch.lastExecutedBlockHash).map(_.get)
}
_ <- res.blockExecutor.syncState(
sources = NonEmptyVector.one(0),
block = block
)
_ <- res.blockExecutor.enqueue(lastBatch)

executedBlockHashes <- fixture.awaitBlockExecution(
fixture.lastBatchCommitedBlockHash
)

// The last executed block should be the new root after pruning away old blocks.
pathFromRoot <- fixture.storeRunner.runReadOnly {
TestBlockStorage.getPathFromRoot(
fixture.lastBatchCommitedBlockHash
)
}
} yield {
all(
"prunes to the fast forwared block" |: pathFromRoot.head == lastBatch.lastExecutedBlockHash,
"executes from the fast forwarded block" |: executedBlockHashes == pathFromRoot.tail
)
}
}
}
}
}

0 comments on commit ea32ed5

Please sign in to comment.