Skip to content

Commit 61fbcac

Browse files
biandrattiMaximiliano Biandrattilemastero
authored
[ETCM-127] Regular sync integration tests (#740)
* regular sync - it - should update target block * add it - should sync blockchain progressing forward in the same time * it - should sync peers with divergent chains will be forced to resolve branches * fix it with divergent chains * refactor it - common behavior regular and fast sync * style refactor * fix style * unify behavior between regular and fast sync * unify fast and sync - change it regular sync assert * change test descriptions * add it scalafmt Co-authored-by: Maximiliano Biandratti <[email protected]> Co-authored-by: Piotr Paradziński <[email protected]>
1 parent 69932a3 commit 61fbcac

12 files changed

+1126
-699
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ val root = {
6868
libraryDependencies ++= dep
6969
)
7070
.settings(executableScriptName := name.value)
71-
.settings(inConfig(Integration)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
71+
.settings(inConfig(Integration)(Defaults.testSettings
72+
++ org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings :+ (Test / parallelExecution := false)): _*)
7273
.settings(inConfig(Benchmark)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
7374
.settings(inConfig(Evm)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
7475
.settings(inConfig(Ets)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)

src/it/scala/io/iohk/ethereum/sync/FastSyncItSpec.scala

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
package io.iohk.ethereum.sync
22

3-
import java.net.{InetSocketAddress, ServerSocket}
4-
53
import akka.util.ByteString
64
import io.iohk.ethereum.FlatSpecBase
75
import io.iohk.ethereum.domain._
86
import io.iohk.ethereum.ledger.InMemoryWorldStateProxy
97
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._
1111
import monix.execution.Scheduler
12-
import org.scalatest.BeforeAndAfter
12+
import org.scalatest.BeforeAndAfterAll
1313
import org.scalatest.matchers.should.Matchers
1414

1515
import scala.concurrent.duration._
1616

17-
class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
17+
class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfterAll {
1818
implicit val testScheduler = Scheduler.fixedPool("test", 16)
1919

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(
2126
FakePeer.start3FakePeersRes()
2227
) { case (peer1, peer2, peer3) =>
2328
for {
@@ -32,7 +37,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
3237
}
3338
}
3439

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()) {
3641
case (peer1, peer2, peer3) =>
3742
for {
3843
_ <- peer2.importBlocksUntil(1000)(updateStateAtBlock(500))
@@ -52,7 +57,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
5257
}
5358
}
5459

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
5661
customTestCaseResourceM(
5762
FakePeer.start3FakePeersRes(
5863
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
@@ -77,7 +82,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
7782
}
7883
}
7984

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
8186
customTestCaseResourceM(
8287
FakePeer.start3FakePeersRes(
8388
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
@@ -102,20 +107,19 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
102107
}
103108
}
104109

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+
}
116120
}
117121

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(
119123
FakePeer.start2FakePeersRes()
120124
) { case (peer1, peer2) =>
121125
for {
@@ -132,18 +136,6 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
132136
}
133137

134138
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
147139

148140
def updateWorldWithNAccounts(n: Int, world: InMemoryWorldStateProxy): InMemoryWorldStateProxy = {
149141
val resultWorld = (0 until n).foldLeft(world) { (world, num) =>

0 commit comments

Comments
 (0)