Skip to content

[ETCM-127] Regular sync integration tests #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ val root = {
libraryDependencies ++= dep
)
.settings(executableScriptName := name.value)
.settings(inConfig(Integration)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Integration)(Defaults.testSettings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add formatting to all subprojects ?

++ org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Benchmark)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Evm)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Ets)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
Expand Down
58 changes: 25 additions & 33 deletions src/it/scala/io/iohk/ethereum/sync/FastSyncItSpec.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package io.iohk.ethereum.sync

import java.net.{InetSocketAddress, ServerSocket}

import akka.util.ByteString
import io.iohk.ethereum.FlatSpecBase
import io.iohk.ethereum.domain._
import io.iohk.ethereum.ledger.InMemoryWorldStateProxy
import io.iohk.ethereum.sync.FastSyncItSpec._
import io.iohk.ethereum.sync.FastSyncItSpecUtils.{FakePeer, FakePeerCustomConfig, HostConfig}
import io.iohk.ethereum.sync.util.FastSyncItSpecUtils.FakePeer
import io.iohk.ethereum.sync.util.SyncCommonItSpec._
import io.iohk.ethereum.sync.util.SyncCommonItSpecUtils._
import monix.execution.Scheduler
import org.scalatest.BeforeAndAfter
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers

import scala.concurrent.duration._

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

"FastSync" should "should sync blockchain without state nodes" in customTestCaseResourceM(
override def afterAll(): Unit = {
testScheduler.shutdown()
testScheduler.awaitTermination(60.second)
}

"FastSync" should "sync blockchain without state nodes" in customTestCaseResourceM(
FakePeer.start3FakePeersRes()
) { case (peer1, peer2, peer3) =>
for {
Expand All @@ -32,7 +37,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
}
}

it should "should sync blockchain with state nodes" in customTestCaseResourceM(FakePeer.start3FakePeersRes()) {
it should "sync blockchain with state nodes" in customTestCaseResourceM(FakePeer.start3FakePeersRes()) {
case (peer1, peer2, peer3) =>
for {
_ <- peer2.importBlocksUntil(1000)(updateStateAtBlock(500))
Expand All @@ -52,7 +57,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
}
}

it should "should sync blockchain with state nodes when peer do not response with full responses" in
it should "sync blockchain with state nodes when peer do not response with full responses" in
customTestCaseResourceM(
FakePeer.start3FakePeersRes(
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
Expand All @@ -77,7 +82,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
}
}

it should "should sync blockchain with state nodes when one of the peers send empty state responses" in
it should "sync blockchain with state nodes when one of the peers send empty state responses" in
customTestCaseResourceM(
FakePeer.start3FakePeersRes(
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
Expand All @@ -102,20 +107,19 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
}
}

it should "should update pivot block" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
case (peer1, peer2) =>
for {
_ <- peer2.importBlocksUntil(1000)(IdentityUpdate)
_ <- peer1.connectToPeers(Set(peer2.node))
_ <- peer2.importBlocksUntil(2000)(IdentityUpdate).startAndForget
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
}
it should "update pivot block" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) { case (peer1, peer2) =>
for {
_ <- peer2.importBlocksUntil(1000)(IdentityUpdate)
_ <- peer1.connectToPeers(Set(peer2.node))
_ <- peer2.importBlocksUntil(2000)(IdentityUpdate).startAndForget
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
}
}

it should "should update pivot block and sync this new pivot block state" in customTestCaseResourceM(
it should "update pivot block and sync this new pivot block state" in customTestCaseResourceM(
FakePeer.start2FakePeersRes()
) { case (peer1, peer2) =>
for {
Expand All @@ -132,18 +136,6 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
}

object FastSyncItSpec {
def randomAddress(): InetSocketAddress = {
val s = new ServerSocket(0)
try {
new InetSocketAddress("localhost", s.getLocalPort)
} finally {
s.close()
}
}

final case class BlockchainState(bestBlock: Block, currentWorldState: InMemoryWorldStateProxy, currentTd: BigInt)

val IdentityUpdate: (BigInt, InMemoryWorldStateProxy) => InMemoryWorldStateProxy = (_, world) => world

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