Skip to content

Commit

Permalink
Merge pull request #1530 from wavesplatform/separate-matcher-config
Browse files Browse the repository at this point in the history
NODE-1197 Separate matcher config
  • Loading branch information
Nastya Urlapova authored Oct 3, 2018
2 parents c6236b4 + d3953e4 commit 49e774b
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 751 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers}
import scala.concurrent.duration._
import scala.math.BigDecimal.RoundingMode
import scala.util.{Random, Try}
import com.wavesplatform.it.sync.matcher.config.MatcherPriceAssetConfig._

class CancelOrderTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure with NodesFromDocker with ReportingTestName {

import CancelOrderTestSuite._

override protected def nodeConfigs: Seq[Config] = Configs

private def matcherNode = nodes.head
Expand Down Expand Up @@ -93,101 +92,3 @@ class CancelOrderTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll
}

}

object CancelOrderTestSuite {

import ConfigFactory._
import com.wavesplatform.it.NodeConfigs._

private val ForbiddenAssetId = "FdbnAsset"
private val Decimals: Byte = 2

private val minerDisabled = parseString("waves.miner.enable = no")
private val matcherConfig = parseString(s"""
|waves.matcher {
| enable = yes
| account = 3HmFkAoQRs4Y3PE2uR6ohN7wS4VqPBGKv7k
| bind-address = "0.0.0.0"
| order-match-tx-fee = 300000
| blacklisted-assets = ["$ForbiddenAssetId"]
| balance-watching.enable = yes
|}""".stripMargin).withFallback(minerDisabled)

private val _Configs: Seq[Config] = (Default.last +: Random.shuffle(Default.init).take(3))
.zip(Seq(matcherConfig, minerDisabled, minerDisabled, empty()))
.map { case (n, o) => o.withFallback(n) }

private val aliceSeed = _Configs(1).getString("account-seed")
private val bobSeed = _Configs(2).getString("account-seed")
private val alicePk = PrivateKeyAccount.fromSeed(aliceSeed).right.get
private val bobPk = PrivateKeyAccount.fromSeed(bobSeed).right.get

val IssueUsdTx: IssueTransactionV1 = IssueTransactionV1
.selfSigned(
sender = alicePk,
name = "USD-X".getBytes(),
description = "asset description".getBytes(),
quantity = defaultAssetQuantity,
decimals = Decimals,
reissuable = false,
fee = 1.waves,
timestamp = System.currentTimeMillis()
)
.right
.get

val IssueWctTx: IssueTransactionV1 = IssueTransactionV1
.selfSigned(
sender = bobPk,
name = "WCT-X".getBytes(),
description = "asset description".getBytes(),
quantity = defaultAssetQuantity,
decimals = Decimals,
reissuable = false,
fee = 1.waves,
timestamp = System.currentTimeMillis()
)
.right
.get

val UsdId: AssetId = IssueUsdTx.id()
val WctId = IssueWctTx.id()

val wctUsdPair = AssetPair(
amountAsset = Some(WctId),
priceAsset = Some(UsdId)
)

val wctWavesPair = AssetPair(
amountAsset = Some(WctId),
priceAsset = None
)

val wavesUsdPair = AssetPair(
amountAsset = None,
priceAsset = Some(UsdId)
)

private val updatedMatcherConfig = parseString(s"""
|waves.matcher {
| price-assets = [ "$UsdId", "WAVES"]
|}
""".stripMargin)

private val Configs = _Configs.map(updatedMatcherConfig.withFallback(_))

def createSignedIssueRequest(tx: IssueTransactionV1): SignedIssueV1Request = {
import tx._
SignedIssueV1Request(
Base58.encode(tx.sender.publicKey),
new String(name),
new String(description),
quantity,
decimals,
reissuable,
fee,
timestamp,
signature.base58
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.wavesplatform.it.sync.matcher

import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.config.Config
import com.wavesplatform.it._
import com.wavesplatform.it.api.SyncHttpApi._
import com.wavesplatform.it.api.SyncMatcherHttpApi._
import com.wavesplatform.it.sync._
import com.wavesplatform.it.sync.matcher.config.MatcherDefaultConfig._
import com.wavesplatform.it.transactions.NodesFromDocker
import com.wavesplatform.state.ByteStr
import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType}
Expand All @@ -20,8 +22,6 @@ class MatcherMassOrdersTestSuite
with BeforeAndAfterAll
with CancelAfterFailure {

import MatcherMassOrdersTestSuite._

override protected def nodeConfigs: Seq[Config] = Configs

private def matcherNode = nodes.head
Expand All @@ -33,30 +33,30 @@ class MatcherMassOrdersTestSuite

// Alice issues new assets
val aliceAsset =
aliceNode.issue(aliceNode.address, "AliceCoin", "AliceCoin for matcher's tests", AssetQuantity, 0, reissuable = false, 100000000L).id
aliceNode.issue(aliceNode.address, "AliceCoin", "AliceCoin for matcher's tests", someAssetAmount, 0, reissuable = false, 100000000L).id
nodes.waitForHeightAriseAndTxPresent(aliceAsset)

val aliceSecondAsset = aliceNode
.issue(aliceNode.address, "AliceSecondCoin", "AliceSecondCoin for matcher's tests", AssetQuantity, 0, reissuable = false, 100000000L)
.issue(aliceNode.address, "AliceSecondCoin", "AliceSecondCoin for matcher's tests", someAssetAmount, 0, reissuable = false, 100000000L)
.id
nodes.waitForHeightAriseAndTxPresent(aliceSecondAsset)

val aliceWavesPair = AssetPair(ByteStr.decodeBase58(aliceAsset).toOption, None)
val aliceSecondWavesPair = AssetPair(ByteStr.decodeBase58(aliceSecondAsset).toOption, None)

// Check balances on Alice's account
aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, AssetQuantity)
aliceNode.assertAssetBalance(aliceNode.address, aliceSecondAsset, AssetQuantity)
aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, someAssetAmount)
aliceNode.assertAssetBalance(aliceNode.address, aliceSecondAsset, someAssetAmount)
matcherNode.assertAssetBalance(matcherNode.address, aliceAsset, 0)

val transfer1ToBobId = aliceNode.transfer(aliceNode.address, bobNode.address, AssetQuantity / 2, 100000, Some(aliceAsset), None).id
val transfer1ToBobId = aliceNode.transfer(aliceNode.address, bobNode.address, someAssetAmount / 2, 100000, Some(aliceAsset), None).id
nodes.waitForHeightAriseAndTxPresent(transfer1ToBobId)

val transfer2ToBobId = aliceNode.transfer(aliceNode.address, bobNode.address, AssetQuantity / 2, 100000, Some(aliceSecondAsset), None).id
val transfer2ToBobId = aliceNode.transfer(aliceNode.address, bobNode.address, someAssetAmount / 2, 100000, Some(aliceSecondAsset), None).id
nodes.waitForHeightAriseAndTxPresent(transfer2ToBobId)

bobNode.assertAssetBalance(bobNode.address, aliceAsset, AssetQuantity / 2)
bobNode.assertAssetBalance(bobNode.address, aliceSecondAsset, AssetQuantity / 2)
bobNode.assertAssetBalance(bobNode.address, aliceAsset, someAssetAmount / 2)
bobNode.assertAssetBalance(bobNode.address, aliceSecondAsset, someAssetAmount / 2)

// Alice places sell orders
val aliceOrderIdFill = matcherNode
Expand Down Expand Up @@ -165,28 +165,3 @@ class MatcherMassOrdersTestSuite
matcherNode.fullOrderHistory(node).filter(_.id == orderId).seq.head.status shouldBe expectedStatus
}
}

object MatcherMassOrdersTestSuite {
private val ForbiddenAssetId = "FdbnAsset"
private val orderLimit = 20
private val AssetQuantity: Long = 1000000000

import ConfigFactory._
import NodeConfigs.Default

private val minerDisabled = parseString("waves.miner.enable = no")
private val matcherConfig = ConfigFactory.parseString(s"""
|waves.matcher {
| enable = yes
| account = 3HmFkAoQRs4Y3PE2uR6ohN7wS4VqPBGKv7k
| bind-address = "0.0.0.0"
| order-match-tx-fee = 300000
| blacklisted-assets = [$ForbiddenAssetId]
| order-cleanup-interval = 20s
| rest-order-limit=$orderLimit
|}""".stripMargin).withFallback(minerDisabled)

private val Configs: Seq[Config] = (Default.last +: Random.shuffle(Default.init).take(3))
.zip(Seq(matcherConfig, minerDisabled, minerDisabled, empty()))
.map { case (n, o) => o.withFallback(n) }
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.wavesplatform.it.sync.matcher

import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.config.{Config}
import com.wavesplatform.it.api.SyncHttpApi._
import com.wavesplatform.it.api.SyncMatcherHttpApi._
import com.wavesplatform.it.sync._
import com.wavesplatform.it.transactions.NodesFromDocker
import com.wavesplatform.it.{TransferSending, _}
import com.wavesplatform.it.sync.matcher.config.MatcherDefaultConfig._
import com.wavesplatform.state.ByteStr
import org.scalatest.concurrent.Eventually
import com.wavesplatform.transaction.assets.exchange.{AssetPair, OrderType}
import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers}

import scala.concurrent.duration._
import scala.util.Random

class MatcherMigrationTestSuite
extends FreeSpec
Expand All @@ -24,8 +24,6 @@ class MatcherMigrationTestSuite
with TransferSending
with Eventually {

import MatcherMigrationTestSuite._

override protected def nodeConfigs: Seq[Config] = Configs
private def matcherNode = nodes.head
private def aliceNode = nodes(1)
Expand Down Expand Up @@ -73,30 +71,9 @@ class MatcherMigrationTestSuite
val tbAfter = matcherNode.tradableBalance(aliceNode, aliceWavesPair)
val rbAfter = matcherNode.reservedBalance(aliceNode)

// TODO: @monroid uncomment this after merge with version-0.13.x
// assert(tbBefore == tbAfter)
// assert(rbBefore == rbAfter)
assert(tbBefore == tbAfter)
assert(rbBefore == rbAfter)

}
}
}

object MatcherMigrationTestSuite {
import ConfigFactory._
import com.wavesplatform.it.NodeConfigs._

val genesisTs = System.currentTimeMillis()
private val minerDisabled = parseString("waves.miner.enable = no")
private val matcherConfig = parseString(s"""
|waves.matcher {
| enable = yes
| account = 3HmFkAoQRs4Y3PE2uR6ohN7wS4VqPBGKv7k
| bind-address = "0.0.0.0"
| order-match-tx-fee = 300000
|}
|""".stripMargin)

private val Configs: Seq[Config] = (Default.last +: Random.shuffle(Default.init).take(3))
.zip(Seq(matcherConfig, minerDisabled, minerDisabled, empty()))
.map { case (n, o) => o.withFallback(n) }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wavesplatform.it.sync.matcher

import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.config.{Config}
import com.wavesplatform.it.api.SyncHttpApi._
import com.wavesplatform.it.api.SyncMatcherHttpApi._
import com.wavesplatform.it.transactions.NodesFromDocker
Expand All @@ -11,6 +11,8 @@ import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderTyp
import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers}

import scala.concurrent.duration._
import com.wavesplatform.it.sync._
import com.wavesplatform.it.sync.matcher.config.MatcherDefaultConfig._
import scala.util.Random

class MatcherRestartTestSuite
Expand All @@ -22,27 +24,26 @@ class MatcherRestartTestSuite
with NodesFromDocker
with TransferSending {

import MatcherRestartTestSuite._

override protected def nodeConfigs: Seq[Config] = Configs
private def matcherNode = nodes.head
private def aliceNode = nodes(1)
private def orderVersion = (Random.nextInt(2) + 1).toByte

"check order execution" - {
// Alice issues new asset
val aliceAsset =
aliceNode.issue(aliceNode.address, "DisconnectCoin", "Alice's coin for disconnect tests", AssetQuantity, 0, reissuable = false, 100000000L).id
aliceNode.issue(aliceNode.address, "DisconnectCoin", "Alice's coin for disconnect tests", someAssetAmount, 0, reissuable = false, 100000000L).id
nodes.waitForHeightAriseAndTxPresent(aliceAsset)

val aliceWavesPair = AssetPair(ByteStr.decodeBase58(aliceAsset).toOption, None)
// check assets's balances
aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, AssetQuantity)
aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, someAssetAmount)
aliceNode.assertAssetBalance(matcherNode.address, aliceAsset, 0)

"make order and after matcher's restart try to cancel it" in {
// Alice places sell order
val aliceOrder = matcherNode
.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, 500)
.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, 500, orderVersion)
aliceOrder.status shouldBe "OrderAccepted"
val firstOrder = aliceOrder.message.id

Expand Down Expand Up @@ -71,7 +72,7 @@ class MatcherRestartTestSuite
orders1.asks.head.price shouldBe 2.waves * Order.PriceConstant

val aliceSecondOrder = matcherNode
.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, 500, version = 1: Byte, 5.minutes)
.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, 500, orderVersion, 5.minutes)
aliceSecondOrder.status shouldBe "OrderAccepted"

val orders2 = matcherNode.orderBook(aliceWavesPair)
Expand All @@ -89,38 +90,3 @@ class MatcherRestartTestSuite
}
}
}

object MatcherRestartTestSuite {
val ForbiddenAssetId = "FdbnAsset"
import NodeConfigs.Default
private val matcherConfig = ConfigFactory.parseString(s"""
|waves {
| matcher {
| enable = yes
| account = 3HmFkAoQRs4Y3PE2uR6ohN7wS4VqPBGKv7k
| bind-address = "0.0.0.0"
| order-match-tx-fee = 300000
| blacklisted-assets = [$ForbiddenAssetId]
| order-cleanup-interval = 20s
| }
| rest-api {
| enable = yes
| api-key-hash = 7L6GpLHhA5KyJTAVc8WFHwEcyTY8fC8rRbyMCiFnM4i
| }
| miner.enable=no
|}""".stripMargin)
private val nonGeneratingPeersConfig = ConfigFactory.parseString(
"""waves {
| matcher.order-cleanup-interval = 30s
| miner.enable=no
|}""".stripMargin
)
val AssetQuantity: Long = 1000
val MatcherFee: Long = 300000
val TransactionFee: Long = 300000
private val Configs: Seq[Config] = {
val notMatchingNodes = Random.shuffle(Default.init).take(3)
Seq(matcherConfig.withFallback(Default.last), notMatchingNodes.head) ++
notMatchingNodes.tail.map(nonGeneratingPeersConfig.withFallback)
}
}
Loading

0 comments on commit 49e774b

Please sign in to comment.