diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/CancelOrderTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/CancelOrderTestSuite.scala index 281dc250dd7..47ab2612c48 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/CancelOrderTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/CancelOrderTestSuite.scala @@ -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 @@ -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 - ) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMassOrdersTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMassOrdersTestSuite.scala index 73e25647b02..55fe31220a2 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMassOrdersTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMassOrdersTestSuite.scala @@ -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} @@ -20,8 +22,6 @@ class MatcherMassOrdersTestSuite with BeforeAndAfterAll with CancelAfterFailure { - import MatcherMassOrdersTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs private def matcherNode = nodes.head @@ -33,11 +33,11 @@ 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) @@ -45,18 +45,18 @@ class MatcherMassOrdersTestSuite 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 @@ -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) } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMigrationTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMigrationTestSuite.scala index fcf10fc0c06..19deb987215 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMigrationTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherMigrationTestSuite.scala @@ -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 @@ -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) @@ -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) } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherRestartTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherRestartTestSuite.scala index 5fd10d99123..21545924d1c 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherRestartTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherRestartTestSuite.scala @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTestSuite.scala index eb48eb5b8a2..a9c479835e1 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTestSuite.scala @@ -1,10 +1,12 @@ package com.wavesplatform.it.sync.matcher -import com.typesafe.config.{Config, ConfigFactory} +import com.typesafe.config.Config import com.wavesplatform.it.ReportingTestName import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.SyncMatcherHttpApi._ import com.wavesplatform.it.api.{AssetDecimalsInfo, LevelResponse} +import com.wavesplatform.it.sync._ +import com.wavesplatform.it.sync.matcher.config.MatcherDefaultConfig._ import com.wavesplatform.it.transactions.NodesFromDocker import com.wavesplatform.it.util._ import com.wavesplatform.state.ByteStr @@ -16,8 +18,6 @@ import scala.util.Random class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure with NodesFromDocker with ReportingTestName { - import MatcherTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs private def matcherNode = nodes.head @@ -27,7 +27,9 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit private def bobNode = nodes(2) private val aliceSellAmount = 500 + private val TransactionFee = 300000 private val amountAssetName = "AliceCoin" + private val AssetQuantity = 1000 private val aliceCoinDecimals: Byte = 0 private def orderVersion = (Random.nextInt(2) + 1).toByte @@ -42,12 +44,14 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit val aliceWavesPair = AssetPair(ByteStr.decodeBase58(aliceAsset).toOption, None) - // Wait for balance on Alice's account - aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, AssetQuantity) - matcherNode.assertAssetBalance(matcherNode.address, aliceAsset, 0) - bobNode.assertAssetBalance(bobNode.address, aliceAsset, 0) + val order1 = + matcherNode.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, aliceSellAmount, orderVersion, 2.minutes) - val order1 = matcherNode.placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, aliceSellAmount, 1: Byte, 2.minutes) + "assert addresses balances" in { + aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, AssetQuantity) + matcherNode.assertAssetBalance(matcherNode.address, aliceAsset, 0) + bobNode.assertAssetBalance(bobNode.address, aliceAsset, 0) + } "matcher should respond with Public key" in { matcherNode.matcherGet("/matcher").getResponseBody.stripPrefix("\"").stripSuffix("\"") shouldBe matcherNode.publicKeyStr @@ -118,15 +122,15 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit // Bob checks that he spent some Waves val updatedBobBalance = bobNode.accountBalances(bobNode.address)._1 - updatedBobBalance shouldBe (bobBalance - 2.waves * 200 - MatcherFee) + updatedBobBalance shouldBe (bobBalance - 2.waves * 200 - matcherFee) // Alice checks that she received some Waves val updatedAliceBalance = aliceNode.accountBalances(aliceNode.address)._1 - updatedAliceBalance shouldBe (aliceBalance + 2.waves * 200 - (MatcherFee * 200.0 / 500.0).toLong) + updatedAliceBalance shouldBe (aliceBalance + 2.waves * 200 - (matcherFee * 200.0 / 500.0).toLong) // Matcher checks that it earn fees val updatedMatcherBalance = matcherNode.accountBalances(matcherNode.address)._1 - updatedMatcherBalance shouldBe (matcherBalance + MatcherFee + (MatcherFee * 200.0 / 500.0).toLong - TransactionFee) + updatedMatcherBalance shouldBe (matcherBalance + matcherFee + (matcherFee * 200.0 / 500.0).toLong - TransactionFee) } "request activeOnly orders" in { @@ -172,14 +176,14 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit val updatedMatcherBalance = matcherNode.accountBalances(matcherNode.address)._1 updatedMatcherBalance should be( - matcherBalance - 2 * TransactionFee + MatcherFee + (MatcherFee * 150.0 / 350.0).toLong + (MatcherFee * 200.0 / 350.0).toLong + (MatcherFee * 200.0 / 500.0).toLong) + matcherBalance - 2 * TransactionFee + matcherFee + (matcherFee * 150.0 / 350.0).toLong + (matcherFee * 200.0 / 350.0).toLong + (matcherFee * 200.0 / 500.0).toLong) val updatedBobBalance = bobNode.accountBalances(bobNode.address)._1 - updatedBobBalance should be(bobBalance - MatcherFee + 150 * (19.waves / 10.0).toLong) + updatedBobBalance should be(bobBalance - matcherFee + 150 * (19.waves / 10.0).toLong) val updatedAliceBalance = aliceNode.accountBalances(aliceNode.address)._1 updatedAliceBalance should be( - aliceBalance - (MatcherFee * 200.0 / 350.0).toLong - (MatcherFee * 150.0 / 350.0).toLong - (MatcherFee * 200.0 / 500.0).toLong - (19.waves / 10.0).toLong * 150) + aliceBalance - (matcherFee * 200.0 / 350.0).toLong - (matcherFee * 150.0 / 350.0).toLong - (matcherFee * 200.0 / 500.0).toLong - (19.waves / 10.0).toLong * 150) } "order could be canceled and resubmitted again" in { @@ -224,13 +228,13 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit bobNode.assertAssetBalance(bobNode.address, aliceAsset, 150) val updatedMatcherBalance = matcherNode.accountBalances(matcherNode.address)._1 - updatedMatcherBalance should be(matcherBalance - TransactionFee + MatcherFee + (MatcherFee * 100.0 / 130.0).toLong) + updatedMatcherBalance should be(matcherBalance - TransactionFee + matcherFee + (matcherFee * 100.0 / 130.0).toLong) val updatedBobBalance = bobNode.accountBalances(bobNode.address)._1 - updatedBobBalance should be(bobBalance - (MatcherFee * 100.0 / 130.0).toLong - 100 * 2.waves) + updatedBobBalance should be(bobBalance - (matcherFee * 100.0 / 130.0).toLong - 100 * 2.waves) val updatedAliceBalance = aliceNode.accountBalances(aliceNode.address)._1 - updatedAliceBalance should be(aliceBalance - MatcherFee + 2.waves * 100) + updatedAliceBalance should be(aliceBalance - matcherFee + 2.waves * 100) } "market status" in { @@ -329,7 +333,7 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit } val asset2 = - aliceNode.issue(aliceNode.address, "AliceCoin2", "AliceCoin for matcher's tests", AssetQuantity, 0, reissuable = false, 100000000L).id + aliceNode.issue(aliceNode.address, "AliceCoin2", "AliceCoin for matcher's tests", someAssetAmount, 0, reissuable = false, 100000000L).id nodes.waitForHeightAriseAndTxPresent(asset2) val aliceWavesPair2 = AssetPair(ByteStr.decodeBase58(asset2).toOption, None) @@ -391,31 +395,3 @@ class MatcherTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit } } } - -object MatcherTestSuite { - - import ConfigFactory._ - import com.wavesplatform.it.NodeConfigs._ - - private val ForbiddenAssetId = "FdbnAsset" - private val AssetQuantity = 1000 - private val MatcherFee = 300000 - private val TransactionFee = 300000 - private val orderLimit = 20 - - 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 - | 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) } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTickerTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTickerTestSuite.scala index bed1e155140..fe2dd52d7b2 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTickerTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/MatcherTickerTestSuite.scala @@ -45,13 +45,13 @@ class MatcherTickerTestSuite } "status of empty orderbook" in { -// TODO: add error message after fix of https://wavesplatform.atlassian.net/browse/NODE-1151 -// SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.marketStatus(wavesUsdPair), s"") + // TODO: add error message after fix of https://wavesplatform.atlassian.net/browse/NODE-1151 + // SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.marketStatus(wavesUsdPair), s"") } "error of non-existed order" in { //TODO: add error message after fix of https://wavesplatform.atlassian.net/browse/NODE-1151 -// SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.orderStatus(IssueUsdTx.id().toString, wavesUsdPair), s"") + // SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.orderStatus(IssueUsdTx.id().toString, wavesUsdPair), s"") } "try to work with incorrect pair" in { @@ -67,7 +67,7 @@ class MatcherTickerTestSuite .contains(s"WAVES/${usdWavesPair.amountAssetStr}")) //TODO: add error message after fix of https://wavesplatform.atlassian.net/browse/NODE-1151 -// SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.placeOrder(aliceNode, usdWavesPair, OrderType.BUY, 200, 1.waves), "") + // SyncMatcherHttpApi.assertNotFoundAndMessage(matcherNode.placeOrder(aliceNode, usdWavesPair, OrderType.BUY, 200, 1.waves), "") } "issue tokens" in { diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrderExclusionTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrderExclusionTestSuite.scala deleted file mode 100644 index 516939c904e..00000000000 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrderExclusionTestSuite.scala +++ /dev/null @@ -1,113 +0,0 @@ -package com.wavesplatform.it.sync.matcher - -import com.typesafe.config.{Config, ConfigFactory} -import com.wavesplatform.it._ -import com.wavesplatform.it.api.SyncHttpApi._ -import com.wavesplatform.it.api.SyncMatcherHttpApi._ -import com.wavesplatform.it.transactions.NodesFromDocker -import com.wavesplatform.it.util._ -import com.wavesplatform.state.ByteStr -import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} -import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers} - -import scala.concurrent.duration._ -import scala.util.Random - -class OrderExclusionTestSuite - extends FreeSpec - with Matchers - with BeforeAndAfterAll - with CancelAfterFailure - with ReportingTestName - with NodesFromDocker { - - import OrderExclusionTestSuite._ - - override protected def nodeConfigs: Seq[Config] = Configs - - private def matcherNode = nodes.head - - private def aliceNode = nodes(1) - - "check order execution" - { - // Alice issues new asset - val aliceAsset = - aliceNode.issue(aliceNode.address, "AliceCoin", "AliceCoin for matcher's tests", AssetQuantity, 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(matcherNode.address, aliceAsset, 0) - - "sell order could be placed and status it's correct" in { - // Alice places sell order - val aliceOrder = matcherNode - .placeOrder(aliceNode, aliceWavesPair, OrderType.SELL, 2.waves * Order.PriceConstant, 500, 2: Byte, 70.seconds) - - aliceOrder.status shouldBe "OrderAccepted" - - val orderId = aliceOrder.message.id - - // Alice checks that the order in order book - matcherNode.waitOrderStatus(aliceWavesPair, orderId, "Accepted") - matcherNode.fullOrderHistory(aliceNode).head.status shouldBe "Accepted" - - // Alice check that order is correct - val orders = matcherNode.orderBook(aliceWavesPair) - orders.asks.head.amount shouldBe 500 - orders.asks.head.price shouldBe 2.waves * Order.PriceConstant - - // sell order should be in the aliceNode orderbook - matcherNode.fullOrderHistory(aliceNode).head.status shouldBe "Accepted" - - //wait for expiration of order - matcherNode.waitOrderStatus(aliceWavesPair, orderId, "Cancelled", 2.minutes) - matcherNode.fullOrderHistory(aliceNode).head.status shouldBe "Cancelled" - } - } - -} - -object OrderExclusionTestSuite { - 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 - - // val Waves: Long = 100000000L - - 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) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrdersFromScriptedAccTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrdersFromScriptedAccTestSuite.scala index ebb445d1a81..d6bfe19f396 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrdersFromScriptedAccTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/OrdersFromScriptedAccTestSuite.scala @@ -95,8 +95,6 @@ class OrdersFromScriptedAccTestSuite matcherNode.waitOrderStatus(aliceWavesPair, orderId, "Filled") matcherNode.fullOrderHistory(aliceNode).head.status shouldBe "Filled" - // sell order should be in the aliceNode orderbook - matcherNode.fullOrderHistory(aliceNode).head.status shouldBe "Filled" } } } diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/RoundingIssuesTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/RoundingIssuesTestSuite.scala index 3ca391b7c34..61fde6e47dd 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/RoundingIssuesTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/RoundingIssuesTestSuite.scala @@ -1,23 +1,16 @@ package com.wavesplatform.it.sync.matcher -import com.typesafe.config.{Config, ConfigFactory} -import com.wavesplatform.account.PrivateKeyAccount -import com.wavesplatform.api.http.assets.SignedIssueV1Request +import com.typesafe.config.Config import com.wavesplatform.it.ReportingTestName import com.wavesplatform.it.api.LevelResponse import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.SyncMatcherHttpApi._ -import com.wavesplatform.it.sync.CustomFeeTransactionSuite.defaultAssetQuantity +import com.wavesplatform.it.sync.matcher.config.MatcherPriceAssetConfig._ import com.wavesplatform.it.transactions.NodesFromDocker -import com.wavesplatform.it.util._ -import com.wavesplatform.transaction.AssetId -import com.wavesplatform.transaction.assets.IssueTransactionV1 -import com.wavesplatform.transaction.assets.exchange.{AssetPair, OrderType} -import com.wavesplatform.utils.Base58 +import com.wavesplatform.transaction.assets.exchange.{OrderType} import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers} import scala.concurrent.duration._ -import scala.util.Random class RoundingIssuesTestSuite extends FreeSpec @@ -27,8 +20,6 @@ class RoundingIssuesTestSuite with NodesFromDocker with ReportingTestName { - import RoundingIssuesTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs private def matcherNode = nodes.head @@ -73,24 +64,24 @@ class RoundingIssuesTestSuite } "reserved balance should not be negative" in { - val counter = matcherNode.prepareOrder(aliceNode, ethBtcPair, OrderType.BUY, 31887L, 923431000L) + val counter = matcherNode.prepareOrder(bobNode, ethBtcPair, OrderType.BUY, 31887L, 923431000L) val counterId = matcherNode.placeOrder(counter).message.id - val submitted = matcherNode.prepareOrder(bobNode, ethBtcPair, OrderType.SELL, 31887L, 223345000L) + val submitted = matcherNode.prepareOrder(aliceNode, ethBtcPair, OrderType.SELL, 31887L, 223345000L) val submittedId = matcherNode.placeOrder(submitted).message.id val filledAmount = 223344937L matcherNode.waitOrderStatusAndAmount(ethBtcPair, submittedId, "Filled", Some(filledAmount), 1.minute) matcherNode.waitOrderStatusAndAmount(ethBtcPair, counterId, "PartiallyFilled", Some(filledAmount), 1.minute) - withClue("Bob's reserved balance before cancel")(matcherNode.reservedBalance(bobNode) shouldBe empty) + withClue("Alice's reserved balance before cancel")(matcherNode.reservedBalance(aliceNode) shouldBe empty) - matcherNode.cancelOrder(aliceNode, ethBtcPair, Some(counterId)) + matcherNode.cancelOrder(bobNode, ethBtcPair, Some(counterId)) val tx = matcherNode.transactionsByOrder(counterId).head matcherNode.waitForTransaction(tx.id) - withClue("Alice's reserved balance after cancel")(matcherNode.reservedBalance(aliceNode) shouldBe empty) + withClue("Bob's reserved balance after cancel")(matcherNode.reservedBalance(bobNode) shouldBe empty) } "should correctly fill 2 counter orders" in { @@ -114,114 +105,3 @@ class RoundingIssuesTestSuite } } - -object RoundingIssuesTestSuite { - - 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 alicePk = PrivateKeyAccount.fromSeed(aliceSeed).right.get - - private val bobSeed = _Configs(2).getString("account-seed") - 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 UsdId: AssetId = IssueUsdTx.id() - - val IssueEthTx: IssueTransactionV1 = IssueTransactionV1 - .selfSigned( - sender = bobPk, - name = "ETH-X".getBytes(), - description = "asset description".getBytes(), - quantity = defaultAssetQuantity, - decimals = 8, - reissuable = false, - fee = 1.waves, - timestamp = System.currentTimeMillis() - ) - .right - .get - - val EthId: AssetId = IssueEthTx.id() - - val IssueBtcTx: IssueTransactionV1 = IssueTransactionV1 - .selfSigned( - sender = alicePk, - name = "BTC-X".getBytes(), - description = "asset description".getBytes(), - quantity = defaultAssetQuantity, - decimals = 8, - reissuable = false, - fee = 1.waves, - timestamp = System.currentTimeMillis() - ) - .right - .get - - val BtcId: AssetId = IssueBtcTx.id() - - val wavesUsdPair = AssetPair( - amountAsset = None, - priceAsset = Some(UsdId) - ) - - val ethBtcPair = AssetPair( - amountAsset = Some(EthId), - priceAsset = Some(BtcId) - ) - - private val updatedMatcherConfig = parseString(s""" - |waves.matcher { - | price-assets = ["$UsdId", "$BtcId", "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 - ) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/SeveralPartialOrdersTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/SeveralPartialOrdersTestSuite.scala index 1e6e10ae6c1..e1e902750a1 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/SeveralPartialOrdersTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/SeveralPartialOrdersTestSuite.scala @@ -1,25 +1,18 @@ package com.wavesplatform.it.sync.matcher -import com.typesafe.config.{Config, ConfigFactory} -import com.wavesplatform.account.PrivateKeyAccount -import com.wavesplatform.api.http.assets.SignedIssueV1Request +import com.typesafe.config.Config import com.wavesplatform.it.ReportingTestName import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.SyncMatcherHttpApi._ -import com.wavesplatform.it.sync.CustomFeeTransactionSuite.defaultAssetQuantity +import com.wavesplatform.it.sync.matcher.config.MatcherPriceAssetConfig._ import com.wavesplatform.it.sync.matcherFee import com.wavesplatform.it.transactions.NodesFromDocker -import com.wavesplatform.it.util._ -import com.wavesplatform.transaction.AssetId -import com.wavesplatform.transaction.assets.IssueTransactionV1 import com.wavesplatform.transaction.assets.exchange.OrderType.BUY -import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} -import com.wavesplatform.utils.Base58 +import com.wavesplatform.transaction.assets.exchange.{Order, OrderType} import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers} import scala.concurrent.duration._ import scala.math.BigDecimal.RoundingMode -import scala.util.Random class SeveralPartialOrdersTestSuite extends FreeSpec @@ -29,8 +22,6 @@ class SeveralPartialOrdersTestSuite with NodesFromDocker with ReportingTestName { - import SeveralPartialOrdersTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs private def matcherNode = nodes.head @@ -90,74 +81,3 @@ class SeveralPartialOrdersTestSuite } } - -object SeveralPartialOrdersTestSuite { - - 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 alicePk = PrivateKeyAccount.fromSeed(aliceSeed).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 UsdId: AssetId = IssueUsdTx.id() - - 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 - ) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradeBalanceAndRoundingTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradeBalanceAndRoundingTestSuite.scala index 332eed72f9b..d450aef634e 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradeBalanceAndRoundingTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradeBalanceAndRoundingTestSuite.scala @@ -1,27 +1,23 @@ package com.wavesplatform.it.sync.matcher -import com.typesafe.config.{Config, ConfigFactory} -import com.wavesplatform.account.PrivateKeyAccount -import com.wavesplatform.api.http.assets.SignedIssueV1Request +import com.typesafe.config.Config import com.wavesplatform.it.ReportingTestName import com.wavesplatform.it.api.AssetDecimalsInfo import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.SyncMatcherHttpApi._ import com.wavesplatform.it.sync.CustomFeeTransactionSuite.defaultAssetQuantity import com.wavesplatform.it.sync._ +import com.wavesplatform.it.sync.matcher.config.MatcherPriceAssetConfig._ import com.wavesplatform.it.transactions.NodesFromDocker import com.wavesplatform.it.util._ import com.wavesplatform.matcher.model.LimitOrder -import com.wavesplatform.transaction.AssetId -import com.wavesplatform.transaction.assets.IssueTransactionV1 +import com.wavesplatform.state.ByteStr import com.wavesplatform.transaction.assets.exchange.OrderType.{BUY, SELL} import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} -import com.wavesplatform.utils.Base58 import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers} import scala.concurrent.duration._ import scala.math.BigDecimal.RoundingMode -import scala.util.Random class TradeBalanceAndRoundingTestSuite extends FreeSpec @@ -31,8 +27,6 @@ class TradeBalanceAndRoundingTestSuite with NodesFromDocker with ReportingTestName { - import TradeBalanceAndRoundingTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs private def matcherNode = nodes.head @@ -41,7 +35,7 @@ class TradeBalanceAndRoundingTestSuite private def bobNode = nodes(2) - Seq(IssueUsdTx, IssueWctTx, IssueEthTx).map(createSignedIssueRequest).foreach(matcherNode.signedIssue) + Seq(IssueUsdTx, IssueEthTx, IssueWctTx).map(createSignedIssueRequest).foreach(matcherNode.signedIssue) nodes.waitForHeightArise() "Alice and Bob trade WAVES-USD" - { @@ -341,121 +335,3 @@ class TradeBalanceAndRoundingTestSuite } } - -object TradeBalanceAndRoundingTestSuite { - - import ConfigFactory._ - import com.wavesplatform.it.NodeConfigs._ - - private val ForbiddenAssetId = "FdbnAsset" - 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 usdAssetName = "USD-X" - val wctAssetName = "WCT-X" - val ethAssetName = "ETH-X" - - val IssueUsdTx: IssueTransactionV1 = IssueTransactionV1 - .selfSigned( - sender = alicePk, - name = usdAssetName.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 = wctAssetName.getBytes(), - description = "asset description".getBytes(), - quantity = defaultAssetQuantity, - decimals = Decimals, - reissuable = false, - fee = 1.waves, - timestamp = System.currentTimeMillis() - ) - .right - .get - - val IssueEthTx: IssueTransactionV1 = IssueTransactionV1 - .selfSigned( - sender = alicePk, - name = ethAssetName.getBytes(), - description = "asset description".getBytes(), - quantity = defaultAssetQuantity, - decimals = 8, - reissuable = false, - fee = 1.waves, - timestamp = System.currentTimeMillis() - ) - .right - .get - - val UsdId: AssetId = IssueUsdTx.id() - val WctId: AssetId = IssueWctTx.id() - val EthId: AssetId = IssueEthTx.id() - - val wctUsdPair = AssetPair( - amountAsset = Some(WctId), - priceAsset = Some(UsdId) - ) - - val wctWavesPair = AssetPair( - amountAsset = Some(WctId), - priceAsset = None - ) - - val ethWavesPair = AssetPair( - amountAsset = Some(EthId), - 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 - ) - } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradersTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradersTestSuite.scala index 4786c9e0802..d9eddf0b799 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradersTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/TradersTestSuite.scala @@ -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.ReportingTestName 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.it.util._ import com.wavesplatform.matcher.market.MatcherActor @@ -11,30 +13,28 @@ import com.wavesplatform.matcher.model.MatcherModel.Price import com.wavesplatform.state.ByteStr import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} import org.scalatest.{BeforeAndAfterAll, CancelAfterFailure, FreeSpec, Matchers} - import scala.util.Random class TradersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll with CancelAfterFailure with NodesFromDocker with ReportingTestName { - import TradersTestSuite._ - override protected def nodeConfigs: Seq[Config] = Configs - private def matcherNode = nodes.head - private def aliceNode = nodes(1) - private def bobNode = nodes(2) - private def orderVersion = (Random.nextInt(2) + 1).toByte + private def matcherNode = nodes.head + private def aliceNode = nodes(1) + private def bobNode = nodes(2) + private val TransactionFee = 300000 + private def orderVersion = (Random.nextInt(2) + 1).toByte "Verifications of tricky ordering cases" - { // Alice issues new asset 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 aliceWavesPair = AssetPair(ByteStr.decodeBase58(aliceAsset).toOption, None) // Wait for balance on Alice's account - aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, AssetQuantity) + aliceNode.assertAssetBalance(aliceNode.address, aliceAsset, someAssetAmount) matcherNode.assertAssetBalance(matcherNode.address, aliceAsset, 0) bobNode.assertAssetBalance(bobNode.address, aliceAsset, 0) @@ -100,8 +100,8 @@ class TradersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit val oldestOrderId = bobPlacesAssetOrder(1000, twoAssetsPair, bobNewAsset) val newestOrderId = bobPlacesAssetOrder(1000, twoAssetsPair, bobNewAsset) - // TransactionFee for leasing, MatcherFee for one order - val leaseAmount = bobBalance - TransactionFee - MatcherFee + // TransactionFee for leasing, matcherFee for one order + val leaseAmount = bobBalance - TransactionFee - matcherFee val leaseId = bobNode.lease(bobNode.address, aliceNode.address, leaseAmount, TransactionFee).id nodes.waitForHeightAriseAndTxPresent(leaseId) @@ -124,8 +124,8 @@ class TradersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit val oldestOrderId = bobPlacesAssetOrder(1000, twoAssetsPair, bobNewAsset) val newestOrderId = bobPlacesAssetOrder(1000, twoAssetsPair, bobNewAsset) - // TransactionFee for leasing, MatcherFee for one order - val transferAmount = bobBalance - TransactionFee - MatcherFee + // TransactionFee for leasing, matcherFee for one order + val transferAmount = bobBalance - TransactionFee - matcherFee val transferId = bobNode.transfer(bobNode.address, aliceNode.address, transferAmount, TransactionFee, None, None).id nodes.waitForHeightAriseAndTxPresent(transferId) @@ -153,7 +153,7 @@ class TradersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit val newestOrderId = bobPlacesWaveOrder(bobWavesPair, 10.waves * Order.PriceConstant, 1) // waitForOrderStatus(matcherNode, bobAssetIdRaw, id, "Accepted") - val leaseAmount = bobBalance - TransactionFee - 10.waves - MatcherFee + val leaseAmount = bobBalance - TransactionFee - 10.waves - matcherFee val leaseId = bobNode.lease(bobNode.address, aliceNode.address, leaseAmount, TransactionFee).id nodes.waitForHeightAriseAndTxPresent(leaseId) @@ -234,29 +234,3 @@ class TradersTestSuite extends FreeSpec with Matchers with BeforeAndAfterAll wit } } - -object TradersTestSuite { - - import ConfigFactory._ - import com.wavesplatform.it.NodeConfigs._ - - private val ForbiddenAssetId = "FdbnAsset" - private val AssetQuantity = 1000 - private val MatcherFee = 300000 - private val TransactionFee = 300000 - - 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) } -} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherDefaultConfig.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherDefaultConfig.scala new file mode 100644 index 00000000000..42c6a010469 --- /dev/null +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherDefaultConfig.scala @@ -0,0 +1,32 @@ +package com.wavesplatform.it.sync.matcher.config + +import com.typesafe.config.{Config, ConfigFactory} + +import scala.util.Random + +object MatcherDefaultConfig { + + import ConfigFactory._ + import com.wavesplatform.it.NodeConfigs._ + + val ForbiddenAssetId = "FdbnAsset" + val orderLimit = 20 + + val minerDisabled = parseString("waves.miner.enable = no") + val matcherConfig = parseString(s""" + |waves.matcher { + | enable = yes + | account = 3HmFkAoQRs4Y3PE2uR6ohN7wS4VqPBGKv7k + | bind-address = "0.0.0.0" + | order-match-tx-fee = 300000 + | order-cleanup-interval = 20s + | blacklisted-assets = ["$ForbiddenAssetId"] + | balance-watching.enable = yes + | rest-order-limit=$orderLimit + |}""".stripMargin) + + 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) } + +} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherPriceAssetConfig.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherPriceAssetConfig.scala new file mode 100644 index 00000000000..bc6c73e0e95 --- /dev/null +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/config/MatcherPriceAssetConfig.scala @@ -0,0 +1,151 @@ +package com.wavesplatform.it.sync.matcher.config + +import com.typesafe.config.Config +import com.typesafe.config.ConfigFactory.{empty, parseString} +import com.wavesplatform.account.PrivateKeyAccount +import com.wavesplatform.api.http.assets.SignedIssueV1Request +import com.wavesplatform.it.NodeConfigs.Default +import com.wavesplatform.it.sync.CustomFeeTransactionSuite.defaultAssetQuantity +import com.wavesplatform.it.sync.matcher.config.MatcherDefaultConfig._ +import com.wavesplatform.it.util._ +import com.wavesplatform.transaction.assets.IssueTransactionV1 +import com.wavesplatform.transaction.assets.exchange.AssetPair +import com.wavesplatform.utils.Base58 + +import scala.util.Random + +object MatcherPriceAssetConfig { + + 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 Decimals: Byte = 2 + + val usdAssetName = "USD-X" + val wctAssetName = "WCT-X" + val ethAssetName = "ETH-X" + + val IssueUsdTx: IssueTransactionV1 = IssueTransactionV1 + .selfSigned( + sender = alicePk, + name = usdAssetName.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 = wctAssetName.getBytes(), + description = "asset description".getBytes(), + quantity = defaultAssetQuantity, + decimals = Decimals, + reissuable = false, + fee = 1.waves, + timestamp = System.currentTimeMillis() + ) + .right + .get + + val IssueEthTx: IssueTransactionV1 = IssueTransactionV1 + .selfSigned( + sender = alicePk, + name = ethAssetName.getBytes(), + description = "asset description".getBytes(), + quantity = defaultAssetQuantity, + decimals = 8, + reissuable = false, + fee = 1.waves, + timestamp = System.currentTimeMillis() + ) + .right + .get + + val IssueBtcTx: IssueTransactionV1 = IssueTransactionV1 + .selfSigned( + sender = bobPk, + name = "BTC-X".getBytes(), + description = "asset description".getBytes(), + quantity = defaultAssetQuantity, + decimals = 8, + reissuable = false, + fee = 1.waves, + timestamp = System.currentTimeMillis() + ) + .right + .get + + val BtcId = IssueBtcTx.id() + val EthId = IssueEthTx.id() + val UsdId = IssueUsdTx.id() + val WctId = IssueWctTx.id() + + val wctUsdPair = AssetPair( + amountAsset = Some(WctId), + priceAsset = Some(UsdId) + ) + + val wctWavesPair = AssetPair( + amountAsset = Some(WctId), + priceAsset = None + ) + + val ethWavesPair = AssetPair( + amountAsset = Some(EthId), + priceAsset = None + ) + + val ethBtcPair = AssetPair( + amountAsset = Some(EthId), + priceAsset = Some(BtcId) + ) + + val wavesUsdPair = AssetPair( + amountAsset = None, + priceAsset = Some(UsdId) + ) + + val ethUsdPair = AssetPair( + amountAsset = Some(EthId), + priceAsset = Some(UsdId) + ) + + val orderLimit = 10 + + private val updatedMatcherConfig = parseString(s""" + |waves.matcher { + | price-assets = [ "$UsdId", "$BtcId", "WAVES" ] + | rest-order-limit=$orderLimit + |} + """.stripMargin) + + val Configs: Seq[Config] = _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 + ) + } + +} diff --git a/it/src/test/scala/com/wavesplatform/it/sync/package.scala b/it/src/test/scala/com/wavesplatform/it/sync/package.scala index ee96afc18b5..529a11dba55 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/package.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/package.scala @@ -14,7 +14,7 @@ package object sync { val leasingAmount = transferAmount val issueAmount = transferAmount val massTransferFeePerTransfer = 0.0005.waves - val someAssetAmount = 100000 + val someAssetAmount = 9999999999999l val matcherFee = 0.003.waves def calcDataFee(data: List[DataEntry[_]]): Long = {