1
1
package io .iohk .ethereum .sync
2
2
3
- import java .net .{InetSocketAddress , ServerSocket }
4
-
5
3
import akka .util .ByteString
6
4
import io .iohk .ethereum .FlatSpecBase
7
5
import io .iohk .ethereum .domain ._
8
6
import io .iohk .ethereum .ledger .InMemoryWorldStateProxy
9
7
import io .iohk .ethereum .sync .FastSyncItSpec ._
10
- import io .iohk .ethereum .sync .FastSyncItSpecUtils .{FakePeer , FakePeerCustomConfig , HostConfig }
8
+ import io .iohk .ethereum .sync .util .FastSyncItSpecUtils .FakePeer
9
+ import io .iohk .ethereum .sync .util .SyncCommonItSpec ._
10
+ import io .iohk .ethereum .sync .util .SyncCommonItSpecUtils ._
11
11
import monix .execution .Scheduler
12
- import org .scalatest .BeforeAndAfter
12
+ import org .scalatest .BeforeAndAfterAll
13
13
import org .scalatest .matchers .should .Matchers
14
14
15
15
import scala .concurrent .duration ._
16
16
17
- class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
17
+ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfterAll {
18
18
implicit val testScheduler = Scheduler .fixedPool(" test" , 16 )
19
19
20
- " FastSync" should " should sync blockchain without state nodes" in customTestCaseResourceM(
20
+ override def afterAll (): Unit = {
21
+ testScheduler.shutdown()
22
+ testScheduler.awaitTermination(60 .second)
23
+ }
24
+
25
+ " FastSync" should " sync blockchain without state nodes" in customTestCaseResourceM(
21
26
FakePeer .start3FakePeersRes()
22
27
) { case (peer1, peer2, peer3) =>
23
28
for {
@@ -32,7 +37,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
32
37
}
33
38
}
34
39
35
- it should " should sync blockchain with state nodes" in customTestCaseResourceM(FakePeer .start3FakePeersRes()) {
40
+ it should " sync blockchain with state nodes" in customTestCaseResourceM(FakePeer .start3FakePeersRes()) {
36
41
case (peer1, peer2, peer3) =>
37
42
for {
38
43
_ <- peer2.importBlocksUntil(1000 )(updateStateAtBlock(500 ))
@@ -52,7 +57,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
52
57
}
53
58
}
54
59
55
- it should " should sync blockchain with state nodes when peer do not response with full responses" in
60
+ it should " sync blockchain with state nodes when peer do not response with full responses" in
56
61
customTestCaseResourceM(
57
62
FakePeer .start3FakePeersRes(
58
63
fakePeerCustomConfig2 = FakePeerCustomConfig (HostConfig ()),
@@ -77,7 +82,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
77
82
}
78
83
}
79
84
80
- it should " should sync blockchain with state nodes when one of the peers send empty state responses" in
85
+ it should " sync blockchain with state nodes when one of the peers send empty state responses" in
81
86
customTestCaseResourceM(
82
87
FakePeer .start3FakePeersRes(
83
88
fakePeerCustomConfig2 = FakePeerCustomConfig (HostConfig ()),
@@ -102,20 +107,19 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
102
107
}
103
108
}
104
109
105
- it should " should update pivot block" in customTestCaseResourceM(FakePeer .start2FakePeersRes()) {
106
- case (peer1, peer2) =>
107
- for {
108
- _ <- peer2.importBlocksUntil(1000 )(IdentityUpdate )
109
- _ <- peer1.connectToPeers(Set (peer2.node))
110
- _ <- peer2.importBlocksUntil(2000 )(IdentityUpdate ).startAndForget
111
- _ <- peer1.startFastSync().delayExecution(50 .milliseconds)
112
- _ <- peer1.waitForFastSyncFinish()
113
- } yield {
114
- assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
115
- }
110
+ it should " update pivot block" in customTestCaseResourceM(FakePeer .start2FakePeersRes()) { case (peer1, peer2) =>
111
+ for {
112
+ _ <- peer2.importBlocksUntil(1000 )(IdentityUpdate )
113
+ _ <- peer1.connectToPeers(Set (peer2.node))
114
+ _ <- peer2.importBlocksUntil(2000 )(IdentityUpdate ).startAndForget
115
+ _ <- peer1.startFastSync().delayExecution(50 .milliseconds)
116
+ _ <- peer1.waitForFastSyncFinish()
117
+ } yield {
118
+ assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
119
+ }
116
120
}
117
121
118
- it should " should update pivot block and sync this new pivot block state" in customTestCaseResourceM(
122
+ it should " update pivot block and sync this new pivot block state" in customTestCaseResourceM(
119
123
FakePeer .start2FakePeersRes()
120
124
) { case (peer1, peer2) =>
121
125
for {
@@ -132,18 +136,6 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
132
136
}
133
137
134
138
object FastSyncItSpec {
135
- def randomAddress (): InetSocketAddress = {
136
- val s = new ServerSocket (0 )
137
- try {
138
- new InetSocketAddress (" localhost" , s.getLocalPort)
139
- } finally {
140
- s.close()
141
- }
142
- }
143
-
144
- final case class BlockchainState (bestBlock : Block , currentWorldState : InMemoryWorldStateProxy , currentTd : BigInt )
145
-
146
- val IdentityUpdate : (BigInt , InMemoryWorldStateProxy ) => InMemoryWorldStateProxy = (_, world) => world
147
139
148
140
def updateWorldWithNAccounts (n : Int , world : InMemoryWorldStateProxy ): InMemoryWorldStateProxy = {
149
141
val resultWorld = (0 until n).foldLeft(world) { (world, num) =>
0 commit comments