Skip to content

Commit 85ecd26

Browse files
author
Leonor Boga
committed
ETCM-944 Rename test class to SchedulerStateSpec
1 parent b4e451a commit 85ecd26

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.iohk.ethereum.blockchain.sync
2+
3+
import akka.util.ByteString
4+
import io.iohk.ethereum.blockchain.sync.fast.SyncStateScheduler.{SchedulerState, StateNode, StateNodeRequest}
5+
import org.scalatest.flatspec.AnyFlatSpec
6+
import org.scalatest.matchers.must.Matchers
7+
8+
class SchedulerStateSpec extends AnyFlatSpec with Matchers {
9+
"SchedulerState" should "schedule node hashes for retrieval" in new TestSetup {
10+
val stateWithRequest = schedulerState.schedule(request1)
11+
assert(stateWithRequest != schedulerState)
12+
assert(stateWithRequest.getPendingRequestByHash(request1.nodeHash).contains(request1))
13+
}
14+
15+
it should "return enqueued elements in depth order" in new TestSetup {
16+
val stateWithRequests = schedulerState.schedule(request2).schedule(request3).schedule(request1).schedule(request4)
17+
assert(stateWithRequests != schedulerState)
18+
val (allMissingElements, newState) = stateWithRequests.getAllMissingHashes
19+
assert(allMissingElements == reqestsInDepthOrder.map(_.nodeHash))
20+
val (allMissingElements1, newState1) = newState.getAllMissingHashes
21+
assert(allMissingElements1.isEmpty)
22+
}
23+
24+
it should "return at most n enqueued elements in depth order" in new TestSetup {
25+
val stateWithRequests = schedulerState.schedule(request2).schedule(request3).schedule(request1).schedule(request4)
26+
assert(stateWithRequests != schedulerState)
27+
val (twoMissingElements, newState) = stateWithRequests.getMissingHashes(2)
28+
assert(twoMissingElements == reqestsInDepthOrder.take(2).map(_.nodeHash))
29+
val (allMissingElements1, newState1) = newState.getAllMissingHashes
30+
assert(allMissingElements1.size == 2)
31+
}
32+
33+
trait TestSetup extends EphemBlockchainTestSetup {
34+
val schedulerState = SchedulerState()
35+
val request1 = StateNodeRequest(ByteString(1), None, StateNode, Seq(), 1, 0)
36+
val request2 = StateNodeRequest(ByteString(2), None, StateNode, Seq(), 2, 0)
37+
val request3 = StateNodeRequest(ByteString(3), None, StateNode, Seq(), 3, 0)
38+
val request4 = StateNodeRequest(ByteString(4), None, StateNode, Seq(), 4, 0)
39+
40+
val reqestsInDepthOrder = List(request4, request3, request2, request1)
41+
}
42+
}

0 commit comments

Comments
 (0)