Skip to content

Commit

Permalink
Merge branch 'master' into node-339-level-db
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Jan 11, 2018
2 parents 0ec89f6 + bb48536 commit b9c653d
Show file tree
Hide file tree
Showing 41 changed files with 429 additions and 498 deletions.
4 changes: 3 additions & 1 deletion src/it/scala/com/wavesplatform/it/ActivationTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.wavesplatform.it

import com.typesafe.config.Config
import org.scalatest.{FreeSpec, Matchers}

import scala.concurrent.Await
import scala.concurrent.duration._

class ActivationTestSuite extends FreeSpec with Matchers with IntegrationNodesInitializationAndStopping {
override lazy val nodes: Seq[Node] = docker.startNodes(NodeConfigs.Default.take(2))

override protected def nodeConfigs: Seq[Config] = NodeConfigs.newBuilder.withDefault(2).buildNonConflicting()

"api consuming example" in {
Await.result(nodes.head.waitForHeight(5), 5.minute)
Expand Down
28 changes: 8 additions & 20 deletions src/it/scala/com/wavesplatform/it/BlacklistTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wavesplatform.it

import com.typesafe.config.Config
import com.wavesplatform.it.api.MultipleNodesApi
import com.wavesplatform.it.api.NodeApi.BlacklistedPeer
import org.scalatest._
Expand All @@ -9,32 +10,19 @@ import scala.concurrent.Future.traverse
import scala.concurrent.duration._
import scala.concurrent.Await

class BlacklistTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure
with ReportingTestName with MultipleNodesApi {
class BlacklistTestSuite extends FreeSpec with Matchers with CancelAfterFailure with ReportingTestName
with MultipleNodesApi {

private lazy val docker = Docker(getClass)
override lazy val nodes: Seq[Node] = docker.startNodes(
NodeConfigs.newBuilder
.overrideBase(_.quorum(2))
.withDefault(3)
.withSpecial(_.quorum(0))
.build()
)
override protected def nodeConfigs: Seq[Config] = NodeConfigs.newBuilder
.overrideBase(_.quorum(2))
.withDefault(3)
.withSpecial(_.quorum(0))
.buildNonConflicting()

private def primaryNode = nodes.last

private def otherNodes = nodes.init

override protected def beforeAll(): Unit = {
super.beforeAll()
log.debug(s"There are ${nodes.size} in tests") // Initializing of a lazy variable
}

override protected def afterAll(): Unit = {
super.afterAll()
docker.close()
}

"network should grow up to 10 blocks" in Await.result(primaryNode.waitForHeight(10), 3.minutes)

"primary node should blacklist other nodes" in Await.result(
Expand Down
21 changes: 6 additions & 15 deletions src/it/scala/com/wavesplatform/it/BlockHeadersTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wavesplatform.it

import com.typesafe.config.Config
import com.wavesplatform.it.api.MultipleNodesApi
import com.wavesplatform.it.api.NodeApi.{Block, BlockHeaders}

Expand All @@ -16,31 +17,21 @@ import scala.util.Random
class BlockHeadersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure
with MultipleNodesApi with ReportingTestName with ScorexLogging {

private lazy val docker = Docker(getClass)

lazy val nodes: Seq[Node] = docker.startNodes(
NodeConfigs.newBuilder
.overrideBase(_.quorum(2))
.withDefault(2)
.withSpecial(_.nonMiner)
.build()
)
override protected def nodeConfigs: Seq[Config] = NodeConfigs.newBuilder
.overrideBase(_.quorum(2))
.withDefault(2)
.withSpecial(_.nonMiner)
.buildNonConflicting()

private def notMiner: Node = nodes.last

private def firstAddress = nodes(1).address

override protected def beforeAll(): Unit = {
super.beforeAll()
log.debug(s"There are ${nodes.size} in tests") // Initializing of a lazy variable
Await.result(traverse(nodes)(_.waitForHeight(2)), 1.minute)
}

override protected def afterAll(): Unit = {
super.afterAll()
docker.close()
}

private def txRequestsGen(n: Int, fee: Long): Future[Unit] = {
val parallelRequests = 1

Expand Down
4 changes: 2 additions & 2 deletions src/it/scala/com/wavesplatform/it/Docker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Docker(suiteConfig: Config = ConfigFactory.empty,
.setMaxConnectionsPerHost(3)
.setMaxRequestRetry(1)
.setReadTimeout(10000)
.setPooledConnectionIdleTimeout(2000)
.setKeepAlive(false)
.setRequestTimeout(10000))

private val client = DefaultDockerClient.fromEnv().build()
Expand Down Expand Up @@ -205,7 +205,7 @@ class Docker(suiteConfig: Config = ConfigFactory.empty,

val node = new Node(actualConfig, getNodeInfo(containerId, actualConfig), http)
nodes.add(node)
log.debug(s"Started $containerId -> ${node.settings.networkSettings.nodeName}")
log.debug(s"Started $containerId -> ${node.settings.networkSettings.nodeName}: ${node.nodeInfo}")
node
} catch {
case NonFatal(e) =>
Expand Down
16 changes: 16 additions & 0 deletions src/it/scala/com/wavesplatform/it/HasDocker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wavesplatform.it

import monix.eval.Coeval
import org.scalatest.{BeforeAndAfterAll, Suite}

trait HasDocker extends BeforeAndAfterAll {
this: Suite =>
protected val dockerSingleton: Coeval[Docker] = Coeval.evalOnce(createDocker)
protected final def docker: Docker = dockerSingleton()

protected def createDocker: Docker = Docker(getClass)
override protected def afterAll(): Unit = {
super.afterAll()
docker.close()
}
}
22 changes: 22 additions & 0 deletions src/it/scala/com/wavesplatform/it/HasNodes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wavesplatform.it

import com.typesafe.config.Config
import monix.eval.Coeval
import org.scalatest.Suite

trait HasNodes extends HasDocker {
this: Suite =>

protected def nodeConfigs: Seq[Config]
protected val nodesSingleton: Coeval[Seq[Node]] = dockerSingleton
.map(_.startNodes(nodeConfigs))
.memoize

protected final def nodes: Seq[Node] = nodesSingleton()

override protected def beforeAll(): Unit = {
nodesSingleton.run
super.beforeAll()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,18 @@ package com.wavesplatform.it
import org.scalatest._
import scorex.utils.ScorexLogging

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future.traverse
import scala.concurrent.duration._

trait IntegrationNodesInitializationAndStopping extends BeforeAndAfterAll with ScorexLogging with ReportingTestName {
trait IntegrationNodesInitializationAndStopping extends BeforeAndAfterAll with ScorexLogging
with ReportingTestName {
this: Suite =>
protected lazy val docker: Docker = Docker(getClass)
def nodes: Seq[Node]

abstract override def beforeAll(): Unit = {
super.beforeAll()
log.debug(s"There are ${nodes.size} in tests") // Initializing of a lazy variable
Await.result(traverse(nodes)(_.waitForHeight(2)), 1.minute)
}

abstract override def afterAll(): Unit = {
super.afterAll()
ensureNoDeadlock()
docker.close()
}

private def ensureNoDeadlock() = {
Await.result(Future.traverse(nodes)(_.height), 7.seconds)
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import scala.concurrent.{Await, Future}

trait IntegrationSuiteWithThreeAddresses extends BeforeAndAfterAll with Matchers with ScalaFutures
with IntegrationPatience with RecoverMethods with RequestErrorAssert with IntegrationTestsScheme
with MultipleNodesApi with ScorexLogging {
with MultipleNodesApi with HasNodes with ScorexLogging {
this: Suite =>

def nodes: Seq[Node]

def notMiner: Node

protected def sender: Node = notMiner
Expand Down Expand Up @@ -104,7 +102,6 @@ trait IntegrationSuiteWithThreeAddresses extends BeforeAndAfterAll with Matchers

abstract override def beforeAll(): Unit = {
super.beforeAll()
log.debug(s"There are ${nodes.size} in tests") // Initializing of a lazy variable

def waitForTxsToReachAllNodes(txIds: Seq[String]): Future[_] = {
val txNodePairs = for {
Expand Down
136 changes: 56 additions & 80 deletions src/it/scala/com/wavesplatform/it/MicroblocksFeeTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.wavesplatform.it

import com.typesafe.config.{Config, ConfigFactory}
import com.wavesplatform.it.NodeConfigs.Default
import com.wavesplatform.it.util._
import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers}
import org.scalatest.{CancelAfterFailure, FreeSpec, Matchers}
import scorex.utils.ScorexLogging

import scala.concurrent.ExecutionContext.Implicits.global
Expand All @@ -11,29 +12,13 @@ import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.Random

class MicroblocksFeeTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure
with ScorexLogging {

import MicroblocksFeeTestSuite._

private lazy val docker = Docker(getClass)
private lazy val nodes = docker.startNodes(Configs)
class MicroblocksFeeTestSuite extends FreeSpec with Matchers with CancelAfterFailure
with HasDocker with HasNodes with ScorexLogging {

private def notMiner = nodes.head

private def firstAddress = nodes(1).address

override protected def beforeAll(): Unit = {
super.beforeAll()
log.debug(s"There are ${nodes.size} in tests") // Initializing of a lazy variable
}

override protected def afterAll(): Unit = {
super.afterAll()
docker.close()
}


private def txRequestsGen(n: Int, fee: Long): Future[Unit] = {
val parallelRequests = 1

Expand All @@ -53,7 +38,6 @@ class MicroblocksFeeTestSuite extends FreeSpec with Matchers with BeforeAndAfter
}

"fee distribution when NG activates" in {

val f = for {
height <- traverse(nodes)(_.height).map(_.max)

Expand Down Expand Up @@ -90,67 +74,59 @@ class MicroblocksFeeTestSuite extends FreeSpec with Matchers with BeforeAndAfter
Await.result(f, 2.minute)
}


object MicroblocksFeeTestSuite {

import NodeConfigs.Default

val NodesCount: Int = 3

val microblockActivationHeight = 10
private val miner = ConfigFactory.parseString(
s"""
|waves {
| blockchain {
| custom {
| functionality{
| pre-activated-features = {2=$microblockActivationHeight}
| }
| genesis {
| signature: "gC84PYfvJRdLpUKDXNddTcWmH3wWhhKD4W9d2Z1HY46xkvgAdqoksknXHKzCBe2PEhzmDW49VKxfWeyzoMB4LKi"
| transactions = [
| {recipient: "3Hm3LGoNPmw1VTZ3eRA2pAfeQPhnaBm6YFC", amount: 250000000000000},
| {recipient: "3HPG313x548Z9kJa5XY4LVMLnUuF77chcnG", amount: 250000000000000},
| {recipient: "3HZxhQhpSU4yEGJdGetncnHaiMnGmUusr9s", amount: 250000000000000},
| {recipient: "3HVW7RDYVkcN5xFGBNAUnGirb5KaBSnbUyB", amount: 250000000000000}
| ]
| }
| }
| }
| miner.quorum = 3
|}
private val microblockActivationHeight = 10
private val minerConfig = ConfigFactory.parseString(
s"""
|waves {
| blockchain {
| custom {
| functionality{
| pre-activated-features = {2=$microblockActivationHeight}
| }
| genesis {
| signature: "gC84PYfvJRdLpUKDXNddTcWmH3wWhhKD4W9d2Z1HY46xkvgAdqoksknXHKzCBe2PEhzmDW49VKxfWeyzoMB4LKi"
| transactions = [
| {recipient: "3Hm3LGoNPmw1VTZ3eRA2pAfeQPhnaBm6YFC", amount: 250000000000000},
| {recipient: "3HPG313x548Z9kJa5XY4LVMLnUuF77chcnG", amount: 250000000000000},
| {recipient: "3HZxhQhpSU4yEGJdGetncnHaiMnGmUusr9s", amount: 250000000000000},
| {recipient: "3HVW7RDYVkcN5xFGBNAUnGirb5KaBSnbUyB", amount: 250000000000000}
| ]
| }
| }
| }
| miner.quorum = 3
|}
""".stripMargin
)
private val notMiner = ConfigFactory.parseString(
s"""waves {
| blockchain {
| custom {
| functionality{
| pre-activated-features = {2=$microblockActivationHeight}
| }
| genesis {
| signature: "gC84PYfvJRdLpUKDXNddTcWmH3wWhhKD4W9d2Z1HY46xkvgAdqoksknXHKzCBe2PEhzmDW49VKxfWeyzoMB4LKi"
| transactions = [
| {recipient: "3Hm3LGoNPmw1VTZ3eRA2pAfeQPhnaBm6YFC", amount: 250000000000000},
| {recipient: "3HPG313x548Z9kJa5XY4LVMLnUuF77chcnG", amount: 250000000000000},
| {recipient: "3HZxhQhpSU4yEGJdGetncnHaiMnGmUusr9s", amount: 250000000000000},
| {recipient: "3HVW7RDYVkcN5xFGBNAUnGirb5KaBSnbUyB", amount: 250000000000000}
| ]
| }
| }
| }
| miner.enable = no
|}
)

private val notMinerConfig = ConfigFactory.parseString(
s"""waves {
| blockchain {
| custom {
| functionality{
| pre-activated-features = {2=$microblockActivationHeight}
| }
| genesis {
| signature: "gC84PYfvJRdLpUKDXNddTcWmH3wWhhKD4W9d2Z1HY46xkvgAdqoksknXHKzCBe2PEhzmDW49VKxfWeyzoMB4LKi"
| transactions = [
| {recipient: "3Hm3LGoNPmw1VTZ3eRA2pAfeQPhnaBm6YFC", amount: 250000000000000},
| {recipient: "3HPG313x548Z9kJa5XY4LVMLnUuF77chcnG", amount: 250000000000000},
| {recipient: "3HZxhQhpSU4yEGJdGetncnHaiMnGmUusr9s", amount: 250000000000000},
| {recipient: "3HVW7RDYVkcN5xFGBNAUnGirb5KaBSnbUyB", amount: 250000000000000}
| ]
| }
| }
| }
| miner.enable = no
|}
""".stripMargin

)


val Configs: Seq[Config] = Seq(notMiner.withFallback(Default.head),
notMiner.withFallback(Default(1)),
miner.withFallback(Default(2)),
miner.withFallback(Default(3)))

}
)

override protected def nodeConfigs: Seq[Config] = Seq(
notMinerConfig.withFallback(Default.head),
notMinerConfig.withFallback(Default(1)),
minerConfig.withFallback(Default(2)),
minerConfig.withFallback(Default(3))
)

}
Loading

0 comments on commit b9c653d

Please sign in to comment.