From 87c55df42d64a4146d747fabd4d08dd4f00f1ff3 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Tue, 4 Jun 2019 23:02:35 -0600 Subject: [PATCH] server: Let scalafmt format the test sources --- .../data/BalancePostgresDataHandlerSpec.scala | 36 +++-- .../data/BlockPostgresDataHandlerSpec.scala | 80 ++++++---- .../data/LedgerPostgresDataHandlerSpec.scala | 7 +- .../StatisticsPostgresDataHandlerSpec.scala | 19 ++- .../TransactionPostgresDataHandlerSpec.scala | 148 +++++++++--------- .../data/common/DockerPostgresService.scala | 49 +++--- .../data/common/PostgresDataHandlerSpec.scala | 11 +- .../xsn/explorer/gcs/GolombEncodingSpec.scala | 14 +- .../com/xsn/explorer/gcs/SipHashKeySpec.scala | 7 +- .../helpers/BalanceDummyDataHandler.scala | 15 +- .../xsn/explorer/helpers/BlockLoader.scala | 37 +++-- .../com/xsn/explorer/helpers/Config.scala | 7 +- .../xsn/explorer/helpers/DataGenerator.scala | 33 ++-- .../explorer/helpers/DataHandlerObjects.scala | 6 +- .../explorer/helpers/DummyXSNService.scala | 3 +- .../helpers/FileBasedXSNService.scala | 14 +- .../xsn/explorer/helpers/LedgerHelper.scala | 11 +- .../helpers/TransactionDummyDataHandler.scala | 37 ++++- .../explorer/helpers/TransactionLoader.scala | 19 ++- .../com/xsn/explorer/models/AddressSpec.scala | 13 +- .../explorer/models/TPoSContractSpec.scala | 18 ++- .../models/persisted/TransactionSpec.scala | 59 ++++--- .../models/values/HexStringSpec.scala | 6 +- .../LedgerSynchronizerServiceSpec.scala | 29 ++-- .../TransactionCollectorServiceSpec.scala | 9 +- .../services/XSNServiceRPCImplSpec.scala | 14 +- .../controllers/AddressesControllerSpec.scala | 17 +- .../controllers/BalancesControllerSpec.scala | 35 +++-- .../controllers/BlocksControllerSpec.scala | 78 ++++----- .../controllers/HealthControllerSpec.scala | 2 +- .../MasternodesControllerSpec.scala | 11 +- .../StatisticsControllerSpec.scala | 9 +- .../TransactionsControllerSpec.scala | 21 +-- .../test/controllers/common/MyAPISpec.scala | 3 +- 34 files changed, 486 insertions(+), 391 deletions(-) diff --git a/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala index 7b3ed248..74f1126a 100644 --- a/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala @@ -15,7 +15,8 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { import DataHelper._ - lazy val dataHandler = new BalancePostgresDataHandler(database, new BalancePostgresDAO(new FieldOrderingSQLInterpreter)) + lazy val dataHandler = + new BalancePostgresDataHandler(database, new BalancePostgresDAO(new FieldOrderingSQLInterpreter)) val defaultOrdering = FieldOrdering(BalanceField.Available, OrderingCondition.DescendingOrder) @@ -47,30 +48,31 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { Balance( address = DataHelper.createAddress("XxQ7j37LfuXgsLd5DZAwFKhT3s2ZMkW85F"), received = BigDecimal("1000"), - spent = BigDecimal("0")), - + spent = BigDecimal("0") + ), Balance( address = DataHelper.createAddress("Xbh5pJdBNm8J9PxnEmwVcuQKRmZZ7DkpcF"), received = BigDecimal("1000"), - spent = BigDecimal("100")), - + spent = BigDecimal("100") + ), Balance( address = DataHelper.createAddress("XfAATXtkRgCdMTrj2fxHvLsKLLmqAjhEAt"), received = BigDecimal("10000"), - spent = BigDecimal("1000")), - + spent = BigDecimal("1000") + ), Balance( address = DataHelper.createAddress("XiHW7SR56UPHeXKwcpeVsE4nUfkHv5RqE3"), received = BigDecimal("1000"), - spent = BigDecimal("500")) + spent = BigDecimal("500") + ) ).sortBy(_.available).reverse def prepare() = { clearDatabase() balances - .map(dataHandler.upsert) - .foreach(_.isGood mustEqual true) + .map(dataHandler.upsert) + .foreach(_.isGood mustEqual true) } "return the first 3 richest addresses" in { @@ -116,15 +118,16 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { Balance( address = DataHelper.createAddress("XiHW7SR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = BigDecimal("0"), - spent = BigDecimal("0")) + spent = BigDecimal("0") + ) ).sortBy(_.available).reverse def prepare() = { clearDatabase() balances - .map(dataHandler.upsert) - .foreach(_.isGood mustEqual true) + .map(dataHandler.upsert) + .foreach(_.isGood mustEqual true) } "ignore addresses with balance = 0" in { @@ -147,7 +150,7 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { Balance(createAddress("XlHW7SR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = 800), Balance(createAddress("XmmmmSR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = 700), Balance(createAddress("XnHW7SR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = 600), - Balance(createAddress("XxxxxSR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = 2000), + Balance(createAddress("XxxxxSR56uPHeXKwcpeVsE4nUfkHv5RqE3"), received = 2000) ) def prepare() = { @@ -156,13 +159,12 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { balances.foreach(dataHandler.upsert(_).isGood mustEqual true) database.withConnection { implicit conn => _root_.anorm - .SQL( - s""" + .SQL(s""" |INSERT INTO hidden_addresses (address) VALUES | ('${balances(4).address.string}'), | ('${balances(6).address.string}') |""".stripMargin) - .executeUpdate() + .executeUpdate() } } diff --git a/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala index 14a72950..29065433 100644 --- a/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala @@ -33,8 +33,9 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "getBy blockhash" should { "return a block" in { - val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - .copy(previousBlockhash = None, nextBlockhash = None) + val block = BlockLoader + .get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") + .copy(previousBlockhash = None, nextBlockhash = None) insert(block).isGood mustEqual true @@ -53,8 +54,9 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "getBy height" should { "return a block" in { - val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - .copy(previousBlockhash = None, nextBlockhash = None) + val block = BlockLoader + .get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") + .copy(previousBlockhash = None, nextBlockhash = None) insert(block).isGood mustEqual true @@ -73,12 +75,15 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "getBy" should { "paginate the results" in { - val block0 = BlockLoader.get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") - .copy(previousBlockhash = None, nextBlockhash = None) - val block1 = BlockLoader.get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") - .copy(nextBlockhash = None) - val block2 = BlockLoader.get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") - .copy(nextBlockhash = None) + val block0 = BlockLoader + .get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") + .copy(previousBlockhash = None, nextBlockhash = None) + val block1 = BlockLoader + .get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") + .copy(nextBlockhash = None) + val block2 = BlockLoader + .get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") + .copy(nextBlockhash = None) List(block0, block1, block2).map(insert).foreach(_.isGood mustEqual true) @@ -96,19 +101,20 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn matches(data(1), expected(1)) } - def testOrdering[B](field: BlockField)(sortBy: Block => B)(implicit order: Ordering[B]) = { - val block0 = BlockLoader.get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") - .copy(previousBlockhash = None, nextBlockhash = None) - val block1 = BlockLoader.get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") - .copy(nextBlockhash = None) - val block2 = BlockLoader.get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") - .copy(nextBlockhash = None) + val block0 = BlockLoader + .get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") + .copy(previousBlockhash = None, nextBlockhash = None) + val block1 = BlockLoader + .get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") + .copy(nextBlockhash = None) + val block2 = BlockLoader + .get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") + .copy(nextBlockhash = None) val blocks = List(block0, block1, block2) blocks.map(insert).foreach(_.isGood mustEqual true) - val ordering = FieldOrdering(field, OrderingCondition.AscendingOrder) val query = PaginatedQuery(Offset(0), Limit(10)) @@ -117,7 +123,8 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn result.map(_.hash) mustEqual expected val expectedReverse = expected.reverse - val resultReverse = dataHandler.getBy(query, ordering.copy(orderingCondition = OrderingCondition.DescendingOrder)).get.data + val resultReverse = + dataHandler.getBy(query, ordering.copy(orderingCondition = OrderingCondition.DescendingOrder)).get.data resultReverse.map(_.hash) mustEqual expectedReverse } @@ -132,8 +139,9 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "delete" should { "delete a block" in { - val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - .copy(previousBlockhash = None, nextBlockhash = None) + val block = BlockLoader + .get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") + .copy(previousBlockhash = None, nextBlockhash = None) insert(block).isGood mustEqual true val result = dataHandler.delete(block.hash) @@ -153,12 +161,15 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "return the block" in { clearDatabase() - val block0 = BlockLoader.get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") - .copy(previousBlockhash = None, nextBlockhash = None) - val block1 = BlockLoader.get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") - .copy(nextBlockhash = None) - val block2 = BlockLoader.get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") - .copy(nextBlockhash = None) + val block0 = BlockLoader + .get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") + .copy(previousBlockhash = None, nextBlockhash = None) + val block1 = BlockLoader + .get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") + .copy(nextBlockhash = None) + val block2 = BlockLoader + .get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") + .copy(nextBlockhash = None) List(block0, block1, block2).map(insert).foreach(_.isGood mustEqual true) @@ -179,12 +190,15 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeAn "return the block" in { clearDatabase() - val block0 = BlockLoader.get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") - .copy(previousBlockhash = None, nextBlockhash = None) - val block1 = BlockLoader.get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") - .copy(nextBlockhash = None) - val block2 = BlockLoader.get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") - .copy(nextBlockhash = None) + val block0 = BlockLoader + .get("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34") + .copy(previousBlockhash = None, nextBlockhash = None) + val block1 = BlockLoader + .get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") + .copy(nextBlockhash = None) + val block2 = BlockLoader + .get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") + .copy(nextBlockhash = None) List(block0, block1, block2).map(insert).foreach(_.isGood mustEqual true) diff --git a/server/test/com/xsn/explorer/data/LedgerPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/LedgerPostgresDataHandlerSpec.scala index e776e9ce..81694072 100644 --- a/server/test/com/xsn/explorer/data/LedgerPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/LedgerPostgresDataHandlerSpec.scala @@ -29,7 +29,8 @@ class LedgerPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeA blockList.drop(1).foreach { block => val transactions = getTransactions(block) - dataHandler.push(block.withTransactions(transactions), List.empty) mustEqual Bad(PreviousBlockMissingError).accumulating + dataHandler + .push(block.withTransactions(transactions), List.empty) mustEqual Bad(PreviousBlockMissingError).accumulating } } @@ -44,7 +45,9 @@ class LedgerPostgresDataHandlerSpec extends PostgresDataHandlerSpec with BeforeA dataHandler.push(genesis.withTransactions(getTransactions(genesis)), List.empty) mustEqual Good(()) val block = blockList(1).copy(previousBlockhash = None, height = genesis.height) - dataHandler.push(block.withTransactions(getTransactions(block)), List.empty) mustEqual Bad(RepeatedBlockHeightError).accumulating + dataHandler.push(block.withTransactions(getTransactions(block)), List.empty) mustEqual Bad( + RepeatedBlockHeightError + ).accumulating } } diff --git a/server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala index 7e3d5702..4670569e 100644 --- a/server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala @@ -12,7 +12,8 @@ import org.scalatest.OptionValues._ class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec { lazy val dataHandler = new StatisticsPostgresDataHandler(database, new StatisticsPostgresDAO) - lazy val balanceDataHandler = new BalancePostgresDataHandler(database, new BalancePostgresDAO(new FieldOrderingSQLInterpreter)) + lazy val balanceDataHandler = + new BalancePostgresDataHandler(database, new BalancePostgresDAO(new FieldOrderingSQLInterpreter)) "getStatistics" should { "succeed even if there is no data" in { @@ -25,12 +26,14 @@ class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec { val circulatingSupply = dataHandler.getStatistics().get.circulatingSupply.getOrElse(0) database.withConnection { implicit conn => - _root_.anorm.SQL( - s""" + _root_.anorm + .SQL( + s""" |INSERT INTO hidden_addresses (address) |VALUES ('${hiddenAddress.string}') """.stripMargin - ).execute() + ) + .execute() } val balance = Balance(hiddenAddress, received = BigDecimal(1000), spent = BigDecimal(500)) @@ -57,13 +60,15 @@ class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec { private def setAvailableCoins(total: BigDecimal) = { database.withConnection { implicit conn => - _root_.anorm.SQL( - s""" + _root_.anorm + .SQL( + s""" |UPDATE aggregated_amounts |SET value = value + $total |WHERE name = 'available_coins' """.stripMargin - ).executeUpdate() + ) + .executeUpdate() } } } diff --git a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala index 510325c6..e8bbc0b2 100644 --- a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala @@ -21,7 +21,7 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be import DataGenerator._ - lazy val dataHandler = createTransactionDataHandler(database) + lazy val dataHandler = createTransactionDataHandler(database) lazy val ledgerDataHandler = createLedgerDataHandler(database) lazy val blockDataHandler = createBlockDataHandler(database) @@ -75,7 +75,8 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be transaction.time, transaction.size, received = transaction.outputs.filter(_.address contains address).map(_.value).sum, - sent = transaction.inputs.filter(_.address contains address).map(_.value).sum) + sent = transaction.inputs.filter(_.address contains address).map(_.value).sum + ) val expected = PaginatedResult(query.offset, query.limit, Count(1), List(transactionWithValues)) val result = dataHandler.getBy(address, query, defaultOrdering) @@ -140,7 +141,10 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be index = 2, value = 0.01, addresses = List.empty, - script = HexString.from("0804678afd04678afd75a820894eeb82f9a851f5d1cb1be3249f58bc8d259963832c5e7474a76f7a859ee95c87").get) + script = HexString + .from("0804678afd04678afd75a820894eeb82f9a851f5d1cb1be3249f58bc8d259963832c5e7474a76f7a859ee95c87") + .get + ) upsertTransaction(tx) val result = dataHandler.getOutput(txid, 2) @@ -180,7 +184,9 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be result.data.size mustEqual transactions.size } - def testOrdering[B](field: TransactionField, orderingCondition: OrderingCondition)(lt: (Transaction.HasIO, Transaction.HasIO) => Boolean) = { + def testOrdering[B](field: TransactionField, orderingCondition: OrderingCondition)( + lt: (Transaction.HasIO, Transaction.HasIO) => Boolean + ) = { createBlock(block, transactions) val ordering = FieldOrdering(field, orderingCondition) @@ -193,58 +199,68 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be } "allow to sort by txid" in { - testOrdering(TransactionField.TransactionId, OrderingCondition.AscendingOrder) { case (a, b) => a.id.string.compareTo(b.id.string) < 0 } + testOrdering(TransactionField.TransactionId, OrderingCondition.AscendingOrder) { + case (a, b) => a.id.string.compareTo(b.id.string) < 0 + } } "allow to sort by txid - descending" in { - testOrdering(TransactionField.TransactionId, OrderingCondition.DescendingOrder) { case (a, b) => a.id.string.compareTo(b.id.string) > 0 } + testOrdering(TransactionField.TransactionId, OrderingCondition.DescendingOrder) { + case (a, b) => a.id.string.compareTo(b.id.string) > 0 + } } "allow to sort by time" in { - testOrdering(TransactionField.Time, OrderingCondition.AscendingOrder) { case (a, b) => - if (a.time < b.time) true - else if (a.time > b.time) false - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Time, OrderingCondition.AscendingOrder) { + case (a, b) => + if (a.time < b.time) true + else if (a.time > b.time) false + else a.id.string.compareTo(b.id.string) < 0 } } "allow to sort by time - descending" in { - testOrdering(TransactionField.Time, OrderingCondition.DescendingOrder) { case (a, b) => - if (a.time < b.time) false - else if (a.time > b.time) true - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Time, OrderingCondition.DescendingOrder) { + case (a, b) => + if (a.time < b.time) false + else if (a.time > b.time) true + else a.id.string.compareTo(b.id.string) < 0 } } "allow to sort by sent" in { - testOrdering(TransactionField.Sent, OrderingCondition.AscendingOrder) { case (a, b) => - if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) true - else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) false - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Sent, OrderingCondition.AscendingOrder) { + case (a, b) => + if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) true + else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) false + else a.id.string.compareTo(b.id.string) < 0 } } "allow to sort by sent - descending" in { - testOrdering(TransactionField.Sent, OrderingCondition.DescendingOrder) { case (a, b) => - if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) false - else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) true - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Sent, OrderingCondition.DescendingOrder) { + case (a, b) => + if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) false + else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) true + else a.id.string.compareTo(b.id.string) < 0 } } "allow to sort by received" in { - testOrdering(TransactionField.Received, OrderingCondition.AscendingOrder) { case (a, b) => - if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) true - else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) false - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Received, OrderingCondition.AscendingOrder) { + case (a, b) => + if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) true + else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) false + else a.id.string.compareTo(b.id.string) < 0 } } "allow to sort by received - descending" in { - testOrdering(TransactionField.Received, OrderingCondition.DescendingOrder) { case (a, b) => - if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) false - else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) true - else a.id.string.compareTo(b.id.string) < 0 + testOrdering(TransactionField.Received, OrderingCondition.DescendingOrder) { + case (a, b) => + if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) false + else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) true + else a.id.string.compareTo(b.id.string) < 0 } } } @@ -259,23 +275,12 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be val outputs = List( Transaction.Output(randomTransactionId, 0, BigDecimal(50), randomAddress, randomHexString()), - Transaction.Output( - randomTransactionId, - 1, - BigDecimal(250), - randomAddress, - HexString.from("00").get) + Transaction.Output(randomTransactionId, 1, BigDecimal(250), randomAddress, HexString.from("00").get) ) - val transactions = List.fill(4)(randomTransactionId).zip(List(321L, 320L, 319L, 319L)).map { case (txid, time) => - Transaction.HasIO( - Transaction( - txid, - blockhash, - time, - Size(1000)), - inputs, - outputs.map(_.copy(txid = txid))) + val transactions = List.fill(4)(randomTransactionId).zip(List(321L, 320L, 319L, 319L)).map { + case (txid, time) => + Transaction.HasIO(Transaction(txid, blockhash, time, Size(1000)), inputs, outputs.map(_.copy(txid = txid))) } val block = randomBlock(blockhash = blockhash).copy(transactions = transactions.map(_.id)) @@ -288,23 +293,28 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be val sorted = condition match { case OrderingCondition.AscendingOrder => transactions - .sortWith { case (a, b) => + .sortWith { + case (a, b) => if (a.time < b.time) true else if (a.time > b.time) false else a.id.string.compareTo(b.id.string) < 0 - } + } case OrderingCondition.DescendingOrder => transactions - .sortWith { case (a, b) => + .sortWith { + case (a, b) => if (a.time > b.time) true else if (a.time < b.time) false else a.id.string.compareTo(b.id.string) < 0 - } + } } def matchOnlyData(expected: Transaction.HasIO, actual: Transaction.HasIO) = { - actual.copy(inputs = List.empty, outputs = List.empty) mustEqual expected.copy(inputs = List.empty, outputs = List.empty) + actual.copy(inputs = List.empty, outputs = List.empty) mustEqual expected.copy( + inputs = List.empty, + outputs = List.empty + ) } s"[$tag] return the first elements" in { @@ -356,22 +366,10 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be val newTxid = randomTransactionId val outputs = List( Transaction.Output(newTxid, 0, BigDecimal(50), randomAddress, randomHexString()), - Transaction.Output( - newTxid, - 1, - BigDecimal(250), - randomAddress, - randomHexString()) + Transaction.Output(newTxid, 1, BigDecimal(250), randomAddress, randomHexString()) ) - val transaction = Transaction.HasIO( - Transaction( - newTxid, - blockhash, - 321, - Size(1000)), - inputs, - outputs) + val transaction = Transaction.HasIO(Transaction(newTxid, blockhash, 321, Size(1000)), inputs, outputs) val newTxid2 = randomTransactionId val newAddress = randomAddress @@ -383,24 +381,22 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be fromOutputIndex = 0, index = 0, value = transaction.outputs(0).value, - address = newAddress), + address = newAddress + ), Transaction.Input( fromTxid = transaction.id, fromOutputIndex = 1, index = 1, value = transaction.outputs(1).value, - address = newAddress) + address = newAddress + ) ), outputs = transaction.outputs.map(_.copy(txid = newTxid2)) ) - val transactions = List( - transaction, transaction2) + val transactions = List(transaction, transaction2) - val block = this.block.copy( - hash = blockhash, - height = Height(10), - transactions = transactions.map(_.id)) + val block = this.block.copy(hash = blockhash, height = Height(10), transactions = transactions.map(_.id)) createBlock(block, transactions) @@ -442,10 +438,10 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be private def createBlock(block: Block) = { val transactions = block.transactions - .map(_.string) - .map(TransactionLoader.getWithValues) - .map(Transaction.fromRPC) - .map(_._1) + .map(_.string) + .map(TransactionLoader.getWithValues) + .map(Transaction.fromRPC) + .map(_._1) val result = ledgerDataHandler.push(block.withTransactions(transactions), List.empty) diff --git a/server/test/com/xsn/explorer/data/common/DockerPostgresService.scala b/server/test/com/xsn/explorer/data/common/DockerPostgresService.scala index 67d77667..ac711556 100644 --- a/server/test/com/xsn/explorer/data/common/DockerPostgresService.scala +++ b/server/test/com/xsn/explorer/data/common/DockerPostgresService.scala @@ -13,12 +13,12 @@ trait DockerPostgresService extends DockerKit { import scala.concurrent.duration._ val postgresContainer = DockerContainer(PostgresImage) - .withCommand("-N 1000") - .withPorts((PostgresAdvertisedPort, Some(PostgresExposedPort))) - .withEnv(s"POSTGRES_USER=$PostgresUsername", s"POSTGRES_PASSWORD=$PostgresPassword") - .withReadyChecker( - new PostgresReadyChecker().looped(15, 1.second) - ) + .withCommand("-N 1000") + .withPorts((PostgresAdvertisedPort, Some(PostgresExposedPort))) + .withEnv(s"POSTGRES_USER=$PostgresUsername", s"POSTGRES_PASSWORD=$PostgresPassword") + .withReadyChecker( + new PostgresReadyChecker().looped(15, 1.second) + ) abstract override def dockerContainers: List[DockerContainer] = postgresContainer :: super.dockerContainers @@ -37,29 +37,28 @@ object DockerPostgresService { class PostgresReadyChecker extends DockerReadyChecker { override def apply( - container: DockerContainerState)( - implicit docker: DockerCommandExecutor, - ec: ExecutionContext) = { + container: DockerContainerState + )(implicit docker: DockerCommandExecutor, ec: ExecutionContext) = { container - .getPorts() - .map { ports => - try { - Class.forName("org.postgresql.Driver") - val url = s"jdbc:postgresql://${docker.host}:$PostgresExposedPort/" - Option(DriverManager.getConnection(url, PostgresUsername, PostgresPassword)) - .foreach { conn => - // NOTE: For some reason the result is always false - conn.createStatement().execute(s"CREATE DATABASE $DatabaseName") - conn.close() - } + .getPorts() + .map { ports => + try { + Class.forName("org.postgresql.Driver") + val url = s"jdbc:postgresql://${docker.host}:$PostgresExposedPort/" + Option(DriverManager.getConnection(url, PostgresUsername, PostgresPassword)) + .foreach { conn => + // NOTE: For some reason the result is always false + conn.createStatement().execute(s"CREATE DATABASE $DatabaseName") + conn.close() + } - true - } catch { - case _: Throwable => - false - } + true + } catch { + case _: Throwable => + false } + } } } } diff --git a/server/test/com/xsn/explorer/data/common/PostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/common/PostgresDataHandlerSpec.scala index f83828e1..338e3060 100644 --- a/server/test/com/xsn/explorer/data/common/PostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/common/PostgresDataHandlerSpec.scala @@ -25,17 +25,16 @@ import play.api.db.{Database, Databases} */ trait PostgresDataHandlerSpec extends WordSpec - with MustMatchers - with DockerTestKit - with DockerPostgresService - with BeforeAndAfterAll { + with MustMatchers + with DockerTestKit + with DockerPostgresService + with BeforeAndAfterAll { import DockerPostgresService._ implicit val pc = PatienceConfig(Span(20, Seconds), Span(1, Second)) - override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory( - DefaultDockerClient.fromEnv().build()) + override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(DefaultDockerClient.fromEnv().build()) override def beforeAll(): Unit = { super.beforeAll() diff --git a/server/test/com/xsn/explorer/gcs/GolombEncodingSpec.scala b/server/test/com/xsn/explorer/gcs/GolombEncodingSpec.scala index 619f367f..8c4b225f 100644 --- a/server/test/com/xsn/explorer/gcs/GolombEncodingSpec.scala +++ b/server/test/com/xsn/explorer/gcs/GolombEncodingSpec.scala @@ -28,9 +28,8 @@ class GolombEncodingSpec extends WordSpec { ) "the encoding" should { - val keyBytes = List( - 0x4c, 0xb1, 0xab, 0x12, 0x57, 0x62, 0x1e, 0x41, - 0x3b, 0x8b, 0x0e, 0x26, 0x64, 0x8d, 0x4a, 0x15).map(_.asInstanceOf[Byte]) + val keyBytes = List(0x4c, 0xb1, 0xab, 0x12, 0x57, 0x62, 0x1e, 0x41, 0x3b, 0x8b, 0x0e, 0x26, 0x64, 0x8d, 0x4a, 0x15) + .map(_.asInstanceOf[Byte]) val key = SipHashKey.fromBtcutil(keyBytes) val golomb = GolombEncoding.default(key) @@ -44,10 +43,10 @@ class GolombEncodingSpec extends WordSpec { "decode the same hashes" in { val hashes = golomb.hashes(words) val bytes = BaseEncoding - .base16() - .decode(encoded.hex.string.toUpperCase) - .toList - .map(new UnsignedByte(_)) + .base16() + .decode(encoded.hex.string.toUpperCase) + .toList + .map(new UnsignedByte(_)) val decoded = golomb.decode(bytes, words.size) @@ -55,6 +54,7 @@ class GolombEncodingSpec extends WordSpec { } "return the encoded hex from the btcutil gcs" in { + /** * The hex was generated from this go code: {{{ diff --git a/server/test/com/xsn/explorer/gcs/SipHashKeySpec.scala b/server/test/com/xsn/explorer/gcs/SipHashKeySpec.scala index 2cde92a4..43466172 100644 --- a/server/test/com/xsn/explorer/gcs/SipHashKeySpec.scala +++ b/server/test/com/xsn/explorer/gcs/SipHashKeySpec.scala @@ -8,13 +8,12 @@ class SipHashKeySpec extends WordSpec { "parsing a Btcutil-like key" should { "parse the right values" in { - val bytes = List( - 0x4c, 0xb1, 0xab, 0x12, 0x57, 0x62, 0x1e, 0x41, - 0x3b, 0x8b, 0x0e, 0x26, 0x64, 0x8d, 0x4a, 0x15).map(_.asInstanceOf[Byte]) + val bytes = List(0x4c, 0xb1, 0xab, 0x12, 0x57, 0x62, 0x1e, 0x41, 0x3b, 0x8b, 0x0e, 0x26, 0x64, 0x8d, 0x4a, + 0x15).map(_.asInstanceOf[Byte]) val key = SipHashKey.fromBtcutil(bytes) key.k0 must be(4692295987881554252L) - key.k1 must be(1534194084347808571l) + key.k1 must be(1534194084347808571L) } "allow to use a blockhash" in { diff --git a/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala b/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala index 076e1611..7c006904 100644 --- a/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala +++ b/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala @@ -13,11 +13,20 @@ class BalanceDummyDataHandler extends BalanceBlockingDataHandler { override def upsert(balance: Balance): ApplicationResult[Balance] = ??? - override def get(query: PaginatedQuery, ordering: FieldOrdering[BalanceField]): ApplicationResult[PaginatedResult[Balance]] = ??? + override def get( + query: PaginatedQuery, + ordering: FieldOrdering[BalanceField] + ): ApplicationResult[PaginatedResult[Balance]] = ??? override def getBy(address: Address): ApplicationResult[Balance] = ??? - override def getNonZeroBalances(query: PaginatedQuery, ordering: FieldOrdering[BalanceField]): ApplicationResult[PaginatedResult[Balance]] = ??? + override def getNonZeroBalances( + query: PaginatedQuery, + ordering: FieldOrdering[BalanceField] + ): ApplicationResult[PaginatedResult[Balance]] = ??? - override def getHighestBalances(limit: pagination.Limit, lastSeenAddress: Option[Address]): ApplicationResult[List[Balance]] = ??? + override def getHighestBalances( + limit: pagination.Limit, + lastSeenAddress: Option[Address] + ): ApplicationResult[List[Balance]] = ??? } diff --git a/server/test/com/xsn/explorer/helpers/BlockLoader.scala b/server/test/com/xsn/explorer/helpers/BlockLoader.scala index 52685977..73168889 100644 --- a/server/test/com/xsn/explorer/helpers/BlockLoader.scala +++ b/server/test/com/xsn/explorer/helpers/BlockLoader.scala @@ -18,25 +18,23 @@ object BlockLoader { def getWithTransactions(blockhash: String): persisted.Block.HasTransactions = { val rpcBlock = getRPC(blockhash) val block = Converters.toPersistedBlock(rpcBlock) - val transactions = rpcBlock - .transactions - .map(_.string) - .map(TransactionLoader.getWithValues) - .map(persisted.Transaction.fromRPC) - .map(_._1) + val transactions = rpcBlock.transactions + .map(_.string) + .map(TransactionLoader.getWithValues) + .map(persisted.Transaction.fromRPC) + .map(_._1) persisted.Block.HasTransactions(block, transactions) } def getWithTransactions(rpcBlock: rpc.Block): persisted.Block.HasTransactions = { val block = Converters.toPersistedBlock(rpcBlock) - val transactions = rpcBlock - .transactions - .map(_.string) - .map(TransactionLoader.getWithValues) - .map(_.copy(blockhash = rpcBlock.hash)) - .map(persisted.Transaction.fromRPC) - .map(_._1) + val transactions = rpcBlock.transactions + .map(_.string) + .map(TransactionLoader.getWithValues) + .map(_.copy(blockhash = rpcBlock.hash)) + .map(persisted.Transaction.fromRPC) + .map(_._1) persisted.Block.HasTransactions(block, transactions) } @@ -58,20 +56,21 @@ object BlockLoader { def all(): List[persisted.Block] = { allRPC() - .map(Converters.toPersistedBlock) + .map(Converters.toPersistedBlock) } def allRPC(): List[rpc.Block] = { val uri = getClass.getResource(s"/$BasePath") new File(uri.getPath) - .listFiles() - .toList - .map(_.getName) - .map(getRPC) + .listFiles() + .toList + .map(_.getName) + .map(getRPC) } def cleanGenesisBlock(block: rpc.Block): rpc.Block = { - val genesisBlockhash: Blockhash = Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get + val genesisBlockhash: Blockhash = + Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get Option(block) .filter(_.hash == genesisBlockhash) diff --git a/server/test/com/xsn/explorer/helpers/Config.scala b/server/test/com/xsn/explorer/helpers/Config.scala index a7be60b7..5f1825d9 100644 --- a/server/test/com/xsn/explorer/helpers/Config.scala +++ b/server/test/com/xsn/explorer/helpers/Config.scala @@ -4,10 +4,13 @@ import com.xsn.explorer.config.ExplorerConfig import com.xsn.explorer.models.values.Blockhash object Config { + val explorerConfig = new ExplorerConfig { - override def genesisBlock: Blockhash = Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get + override def genesisBlock: Blockhash = + Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get - override def liteVersionConfig: ExplorerConfig.LiteVersionConfig = ExplorerConfig.LiteVersionConfig(enabled = false, 0) + override def liteVersionConfig: ExplorerConfig.LiteVersionConfig = + ExplorerConfig.LiteVersionConfig(enabled = false, 0) } } diff --git a/server/test/com/xsn/explorer/helpers/DataGenerator.scala b/server/test/com/xsn/explorer/helpers/DataGenerator.scala index 3803ea2f..842a32a0 100644 --- a/server/test/com/xsn/explorer/helpers/DataGenerator.scala +++ b/server/test/com/xsn/explorer/helpers/DataGenerator.scala @@ -42,7 +42,8 @@ trait DataGenerator { def randomBlock( blockhash: Blockhash = randomBlockhash, previousBlockhash: Option[Blockhash] = None, - nextBlockhash: Option[Blockhash] = None): Block = { + nextBlockhash: Option[Blockhash] = None + ): Block = { Block( hash = blockhash, @@ -70,10 +71,11 @@ trait DataGenerator { index = nextInt(100), value = nextInt(1000000), address = randomAddress, - script = randomHexString(8)) + script = randomHexString(8) + ) } - def randomOutputs(n: Int = nextInt(5) + 1) : List[Transaction.Output] = { + def randomOutputs(n: Int = nextInt(5) + 1): List[Transaction.Output] = { (0 until n).map(x => randomOutput.copy(index = x)).toList } @@ -111,27 +113,26 @@ trait DataGenerator { def randomTransaction( blockhash: Blockhash, id: TransactionId = randomTransactionId, - utxos: List[Transaction.Output]): Transaction.HasIO = { + utxos: List[Transaction.Output] + ): Transaction.HasIO = { Transaction.HasIO( - Transaction( - id = id, - blockhash = blockhash, - time = java.lang.System.currentTimeMillis(), - Size(1000)), + Transaction(id = id, blockhash = blockhash, time = java.lang.System.currentTimeMillis(), Size(1000)), createInputs(utxos), randomOutputs().map(_.copy(txid = id)) ) } def createInputs(outputs: List[Transaction.Output]): List[Transaction.Input] = { - outputs.zipWithIndex.map { case (output, index) => - Transaction.Input( - fromTxid = output.txid, - fromOutputIndex = output.index, - index = index, - value = output.value, - address = randomAddress) + outputs.zipWithIndex.map { + case (output, index) => + Transaction.Input( + fromTxid = output.txid, + fromOutputIndex = output.index, + index = index, + value = output.value, + address = randomAddress + ) } } } diff --git a/server/test/com/xsn/explorer/helpers/DataHandlerObjects.scala b/server/test/com/xsn/explorer/helpers/DataHandlerObjects.scala index f710ea35..99b4bca5 100644 --- a/server/test/com/xsn/explorer/helpers/DataHandlerObjects.scala +++ b/server/test/com/xsn/explorer/helpers/DataHandlerObjects.scala @@ -20,7 +20,8 @@ trait DataHandlerObjects { transactionOutputDAO, tposContractDAO, addressTransactionDetailsDAO, - fieldOrderingSQLInterpreter) + fieldOrderingSQLInterpreter + ) lazy val blockFilterPostgresDAO = new BlockFilterPostgresDAO lazy val blockPostgresDAO = new BlockPostgresDAO(blockFilterPostgresDAO, fieldOrderingSQLInterpreter) lazy val balancePostgresDAO = new BalancePostgresDAO(fieldOrderingSQLInterpreter) @@ -33,7 +34,8 @@ trait DataHandlerObjects { blockFilterPostgresDAO, transactionPostgresDAO, balancePostgresDAO, - aggregatedAmountPostgresDAO) + aggregatedAmountPostgresDAO + ) } def createBlockDataHandler(database: Database) = { diff --git a/server/test/com/xsn/explorer/helpers/DummyXSNService.scala b/server/test/com/xsn/explorer/helpers/DummyXSNService.scala index fa371135..11893066 100644 --- a/server/test/com/xsn/explorer/helpers/DummyXSNService.scala +++ b/server/test/com/xsn/explorer/helpers/DummyXSNService.scala @@ -9,7 +9,8 @@ import play.api.libs.json.JsValue class DummyXSNService extends XSNService { - override def genesisBlockhash: Blockhash = Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get + override def genesisBlockhash: Blockhash = + Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get override def getTransaction(txid: TransactionId): FutureApplicationResult[Transaction[TransactionVIN]] = ??? override def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue] = ??? override def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] = ??? diff --git a/server/test/com/xsn/explorer/helpers/FileBasedXSNService.scala b/server/test/com/xsn/explorer/helpers/FileBasedXSNService.scala index 92313ae3..0126ded0 100644 --- a/server/test/com/xsn/explorer/helpers/FileBasedXSNService.scala +++ b/server/test/com/xsn/explorer/helpers/FileBasedXSNService.scala @@ -11,8 +11,18 @@ import scala.concurrent.Future class FileBasedXSNService extends DummyXSNService { - private lazy val blockMap = BlockLoader.allRPC().map { block => block.hash -> block }.toMap - private lazy val transactionMap = TransactionLoader.all().map { tx => tx.id -> tx }.toMap + private lazy val blockMap = BlockLoader + .allRPC() + .map { block => + block.hash -> block + } + .toMap + private lazy val transactionMap = TransactionLoader + .all() + .map { tx => + tx.id -> tx + } + .toMap override def getBlock(blockhash: Blockhash): FutureApplicationResult[Block] = { val maybe = blockMap.get(blockhash) diff --git a/server/test/com/xsn/explorer/helpers/LedgerHelper.scala b/server/test/com/xsn/explorer/helpers/LedgerHelper.scala index 22d05eb6..a5dba85a 100644 --- a/server/test/com/xsn/explorer/helpers/LedgerHelper.scala +++ b/server/test/com/xsn/explorer/helpers/LedgerHelper.scala @@ -16,11 +16,10 @@ object LedgerHelper { ) def getTransactions(block: rpc.Block): List[Transaction.HasIO] = { - block - .transactions - .map(_.string) - .map(TransactionLoader.getWithValues) - .map(Transaction.fromRPC) - .map(_._1) + block.transactions + .map(_.string) + .map(TransactionLoader.getWithValues) + .map(Transaction.fromRPC) + .map(_._1) } } diff --git a/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala b/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala index af4db35c..31ec3a96 100644 --- a/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala +++ b/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala @@ -12,17 +12,38 @@ import com.xsn.explorer.models.values.{Address, Blockhash, TransactionId} class TransactionDummyDataHandler extends TransactionBlockingDataHandler { - override def getBy(address: Address, paginatedQuery: PaginatedQuery, ordering: FieldOrdering[TransactionField]): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? - - override def getBy(address: Address, limit: pagination.Limit, lastSeenTxid: Option[TransactionId], orderingCondition: OrderingCondition): ApplicationResult[List[Transaction.HasIO]] = ??? + override def getBy( + address: Address, + paginatedQuery: PaginatedQuery, + ordering: FieldOrdering[TransactionField] + ): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? + + override def getBy( + address: Address, + limit: pagination.Limit, + lastSeenTxid: Option[TransactionId], + orderingCondition: OrderingCondition + ): ApplicationResult[List[Transaction.HasIO]] = ??? override def getUnspentOutputs(address: Address): ApplicationResult[List[Transaction.Output]] = ??? override def getOutput(txid: TransactionId, index: Int): ApplicationResult[Transaction.Output] = ??? - override def getByBlockhash(blockhash: Blockhash, paginatedQuery: PaginatedQuery, ordering: FieldOrdering[TransactionField]): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? - - override def getByBlockhash(blockhash: Blockhash, limit: pagination.Limit, lastSeenTxid: Option[TransactionId]): ApplicationResult[List[TransactionWithValues]] = ??? - - override def getTransactionsWithIOBy(blockhash: Blockhash, limit: pagination.Limit, lastSeenTxid: Option[TransactionId]): ApplicationResult[List[Transaction.HasIO]] = ??? + override def getByBlockhash( + blockhash: Blockhash, + paginatedQuery: PaginatedQuery, + ordering: FieldOrdering[TransactionField] + ): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? + + override def getByBlockhash( + blockhash: Blockhash, + limit: pagination.Limit, + lastSeenTxid: Option[TransactionId] + ): ApplicationResult[List[TransactionWithValues]] = ??? + + override def getTransactionsWithIOBy( + blockhash: Blockhash, + limit: pagination.Limit, + lastSeenTxid: Option[TransactionId] + ): ApplicationResult[List[Transaction.HasIO]] = ??? } diff --git a/server/test/com/xsn/explorer/helpers/TransactionLoader.scala b/server/test/com/xsn/explorer/helpers/TransactionLoader.scala index 67f151be..65a73169 100644 --- a/server/test/com/xsn/explorer/helpers/TransactionLoader.scala +++ b/server/test/com/xsn/explorer/helpers/TransactionLoader.scala @@ -16,12 +16,11 @@ object TransactionLoader { def getWithValues(txid: String): Transaction[TransactionVIN.HasValues] = { val plain = json(txid).as[Transaction[TransactionVIN]] val newVIN = plain.vin.flatMap { vin => - get(vin.txid.string) - .vout - .find(_.n == vin.voutIndex) - .flatMap { prev => - prev.addresses.map { vin.withValues(prev.value, _) } - } + get(vin.txid.string).vout + .find(_.n == vin.voutIndex) + .flatMap { prev => + prev.addresses.map { vin.withValues(prev.value, _) } + } } plain.copy(vin = newVIN) @@ -40,9 +39,9 @@ object TransactionLoader { def all(): List[Transaction[TransactionVIN]] = { val uri = getClass.getResource(s"/$BasePath") new File(uri.getPath) - .listFiles() - .toList - .map(_.getName) - .map(get) + .listFiles() + .toList + .map(_.getName) + .map(get) } } diff --git a/server/test/com/xsn/explorer/models/AddressSpec.scala b/server/test/com/xsn/explorer/models/AddressSpec.scala index 2ba97577..17d2153a 100644 --- a/server/test/com/xsn/explorer/models/AddressSpec.scala +++ b/server/test/com/xsn/explorer/models/AddressSpec.scala @@ -9,16 +9,17 @@ class AddressSpec extends WordSpec with MustMatchers with OptionValues { "xsn legacy" -> "19Gfgd95swmT8jmktPK19mbYw9hiBGYV4", "P2WPKH" -> "bc1qzhayf65p2j4h3pfw22aujgr5w42xfqzx5uvddt", "bech32" -> "xc1qphyjl73szcnz3jfpjryljx8elwc6wpdqqccy3s8g57gw7e44hw4q2jqdds", - "btc address 1" -> "1111111111111111111114oLvT2", + "btc address 1" -> "1111111111111111111114oLvT2" ) "from" should { - addresses.foreach { case (tpe, input) => - s"allow $tpe" in { - val result = Address.from(input) - result.value.string mustEqual input - } + addresses.foreach { + case (tpe, input) => + s"allow $tpe" in { + val result = Address.from(input) + result.value.string mustEqual input + } } "reject an empty string" in { diff --git a/server/test/com/xsn/explorer/models/TPoSContractSpec.scala b/server/test/com/xsn/explorer/models/TPoSContractSpec.scala index 9cd9f9c7..79e29d44 100644 --- a/server/test/com/xsn/explorer/models/TPoSContractSpec.scala +++ b/server/test/com/xsn/explorer/models/TPoSContractSpec.scala @@ -13,7 +13,9 @@ class TPoSContractSpec extends WordSpec { val address1Hex = DatatypeConverter.printHexBinary(address1.string.getBytes()) val address2Hex = DatatypeConverter.printHexBinary(address2.string.getBytes()) val commission = "99" - val signature = "1f60a6a385a4e5163ffef65dd873f17452bb0d9f89da701ffcc5a0f72287273c0571485c29123fef880d2d8169cfdb884bf95a18a0b36461517acda390ce4cf441" + + val signature = + "1f60a6a385a4e5163ffef65dd873f17452bb0d9f89da701ffcc5a0f72287273c0571485c29123fef880d2d8169cfdb884bf95a18a0b36461517acda390ce4cf441" val failureCases = Map( "fail when the signature is missing" -> s"OP_RETURN $address1Hex $address2Hex $commission", @@ -34,17 +36,19 @@ class TPoSContractSpec extends WordSpec { val expected = TPoSContract.Details( owner = address1, merchant = address2, - merchantCommission = TPoSContract.Commission.from(100 - commission.toInt).get) + merchantCommission = TPoSContract.Commission.from(100 - commission.toInt).get + ) val result = TPoSContract.Details.fromOutputScriptASM(asm) result.value must be(expected) } - failureCases.foreach { case (test, input) => - test in { - val result = TPoSContract.Details.fromOutputScriptASM(input) - result must be(empty) - } + failureCases.foreach { + case (test, input) => + test in { + val result = TPoSContract.Details.fromOutputScriptASM(input) + result must be(empty) + } } } } diff --git a/server/test/com/xsn/explorer/models/persisted/TransactionSpec.scala b/server/test/com/xsn/explorer/models/persisted/TransactionSpec.scala index 201e62ba..02b6229c 100644 --- a/server/test/com/xsn/explorer/models/persisted/TransactionSpec.scala +++ b/server/test/com/xsn/explorer/models/persisted/TransactionSpec.scala @@ -22,16 +22,10 @@ class TransactionSpec extends WordSpec { val outputs = DataGenerator.randomOutputs(2) intercept[RuntimeException] { - Transaction.HasIO( - tx, - inputs = List.empty, - outputs = outputs) + Transaction.HasIO(tx, inputs = List.empty, outputs = outputs) } - val _ = Transaction.HasIO( - tx, - inputs = List.empty, - outputs = outputs.map(_.copy(txid = tx.id))) + val _ = Transaction.HasIO(tx, inputs = List.empty, outputs = outputs.map(_.copy(txid = tx.id))) } } @@ -41,11 +35,7 @@ class TransactionSpec extends WordSpec { val hex = HexString.from("00").get val vout = List( rpc.TransactionVOUT(0, 1, None), - rpc.TransactionVOUT(10, 2, Some(ScriptPubKey( - "nulldata", - "", - hex, - List(address)))), + rpc.TransactionVOUT(10, 2, Some(ScriptPubKey("nulldata", "", hex, List(address)))) ) val tx = rpc.Transaction[rpc.TransactionVIN.HasValues]( @@ -56,7 +46,8 @@ class TransactionSpec extends WordSpec { blocktime = 10L, confirmations = Confirmations(10), vin = List.empty, - vout = vout) + vout = vout + ) val expected = Transaction.Output(tx.id, 2, 10, address, hex) val (result, _) = persisted.Transaction.fromRPC(tx) @@ -66,15 +57,11 @@ class TransactionSpec extends WordSpec { "discard outputs with 0 value" in { val address = DataGenerator.randomAddress val hex = HexString.from("00").get - val script = ScriptPubKey( - "nulldata", - "", - hex, - List(address)) + val script = ScriptPubKey("nulldata", "", hex, List(address)) val vout = List( rpc.TransactionVOUT(0, 1, Some(script)), - rpc.TransactionVOUT(10, 2, Some(script)), + rpc.TransactionVOUT(10, 2, Some(script)) ) val tx = rpc.Transaction[rpc.TransactionVIN.HasValues]( @@ -85,7 +72,8 @@ class TransactionSpec extends WordSpec { blocktime = 10L, confirmations = Confirmations(10), vin = List.empty, - vout = vout) + vout = vout + ) val expected = Transaction.Output(tx.id, 2, 10, address, hex) val (result, _) = persisted.Transaction.fromRPC(tx) @@ -102,15 +90,18 @@ class TransactionSpec extends WordSpec { n = 0, value = 1 ) - val tx = rpc.Transaction( - id = DataGenerator.randomTransactionId, - size = Size(200), - blockhash = DataGenerator.randomBlockhash, - time = 10L, - blocktime = 10L, - confirmations = Confirmations(10), - vin = List(), - vout = List(collateral, voutWithContract)).copy[rpc.TransactionVIN.HasValues](vin = List.empty) + val tx = rpc + .Transaction( + id = DataGenerator.randomTransactionId, + size = Size(200), + blockhash = DataGenerator.randomBlockhash, + time = 10L, + blocktime = 10L, + confirmations = Confirmations(10), + vin = List(), + vout = List(collateral, voutWithContract) + ) + .copy[rpc.TransactionVIN.HasValues](vin = List.empty) val expected = TPoSContract( id = TPoSContract.Id(tx.id, collateral.n), @@ -127,7 +118,13 @@ class TransactionSpec extends WordSpec { val rpcTx = TransactionLoader.getWithValues("728e76d2d5f0513aabeca6fd7101878469052e39f42f7a9b979a63d7e87353c2") val expected = List( - Transaction.Output(rpcTx.id, 0, 5.60400000, Address.from("Xgg7QHQcsBPYygYPj1QhDcCmfKXa7sFd9b").get, HexString.from("2102a9f34e4bc8b77f6f99aab03646da75d770e4088fd38f1604e2b0f106e7314156ac").get), + Transaction.Output( + rpcTx.id, + 0, + 5.60400000, + Address.from("Xgg7QHQcsBPYygYPj1QhDcCmfKXa7sFd9b").get, + HexString.from("2102a9f34e4bc8b77f6f99aab03646da75d770e4088fd38f1604e2b0f106e7314156ac").get + ), Transaction.Output(rpcTx.id, 1, 1.40100000, List.empty, HexString.from("").get) ) diff --git a/server/test/com/xsn/explorer/models/values/HexStringSpec.scala b/server/test/com/xsn/explorer/models/values/HexStringSpec.scala index 2f71aecd..61aa4afa 100644 --- a/server/test/com/xsn/explorer/models/values/HexStringSpec.scala +++ b/server/test/com/xsn/explorer/models/values/HexStringSpec.scala @@ -6,13 +6,15 @@ class HexStringSpec extends WordSpec with MustMatchers with OptionValues { "from" should { "accept a valid hex" in { - val string = "0100000001d036c70b1df769fa3205f8ff4e361af84073aa14c89de80488048b6ae4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" + val string = + "0100000001d036c70b1df769fa3205f8ff4e361af84073aa14c89de80488048b6ae4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" val result = HexString.from(string) result.value.string mustEqual string } "accept a valid hex with mixed case" in { - val string = "0100000001d036c70b1df769fA3205f8fF4e361af84073aa14c89de80488048b6aE4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" + val string = + "0100000001d036c70b1df769fA3205f8fF4e361af84073aa14c89de80488048b6aE4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" val result = HexString.from(string) result.value.string mustEqual string } diff --git a/server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala b/server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala index 015e087b..213d7a91 100644 --- a/server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala +++ b/server/test/com/xsn/explorer/services/LedgerSynchronizerServiceSpec.scala @@ -101,7 +101,8 @@ class LedgerSynchronizerServiceSpec extends PostgresDataHandlerSpec with BeforeA genesis, block1.copy(nextBlockhash = Some(newBlock2.hash)), newBlock2.copy(nextBlockhash = Some(newBlock3.hash)), - newBlock3) + newBlock3 + ) val synchronizer = ledgerSynchronizerService(finalBlocks: _*) whenReady(synchronizer.synchronize(newBlock3.hash)) { result => @@ -126,7 +127,8 @@ class LedgerSynchronizerServiceSpec extends PostgresDataHandlerSpec with BeforeA block1.copy(nextBlockhash = Some(newBlock2.hash)), newBlock2.copy(nextBlockhash = Some(newBlock3.hash)), newBlock3.copy(nextBlockhash = Some(newBlock4.hash)), - newBlock4) + newBlock4 + ) val synchronizer = ledgerSynchronizerService(finalBlocks: _*) whenReady(synchronizer.synchronize(newBlock4.hash)) { result => @@ -178,22 +180,24 @@ class LedgerSynchronizerServiceSpec extends PostgresDataHandlerSpec with BeforeA private def createBlocks(synchronizer: LedgerSynchronizerService, blocks: Block*) = { blocks - .foreach { block => - whenReady(synchronizer.synchronize(block.hash)) { result => - result.isGood mustEqual true - } + .foreach { block => + whenReady(synchronizer.synchronize(block.hash)) { result => + result.isGood mustEqual true } + } } private def ledgerSynchronizerService(blocks: Block*): LedgerSynchronizerService = { val xsnService = new FileBasedXSNService { override def getBlock(blockhash: Blockhash): FutureApplicationResult[Block] = { blocks - .find(_.hash == blockhash) - .map { block => Future.successful(Good(cleanGenesisBlock(block))) } - .getOrElse { - Future.successful(Bad(BlockNotFoundError).accumulating) - } + .find(_.hash == blockhash) + .map { block => + Future.successful(Good(cleanGenesisBlock(block))) + } + .getOrElse { + Future.successful(Bad(BlockNotFoundError).accumulating) + } } override def getLatestBlock(): FutureApplicationResult[Block] = { @@ -232,6 +236,7 @@ class LedgerSynchronizerServiceSpec extends PostgresDataHandlerSpec with BeforeA blockService, transactionCollectorService, new LedgerFutureDataHandler(dataHandler)(Executors.databaseEC), - new BlockFutureDataHandler(blockDataHandler)(Executors.databaseEC)) + new BlockFutureDataHandler(blockDataHandler)(Executors.databaseEC) + ) } } diff --git a/server/test/com/xsn/explorer/services/TransactionCollectorServiceSpec.scala b/server/test/com/xsn/explorer/services/TransactionCollectorServiceSpec.scala index f4218f80..7120c5a4 100644 --- a/server/test/com/xsn/explorer/services/TransactionCollectorServiceSpec.scala +++ b/server/test/com/xsn/explorer/services/TransactionCollectorServiceSpec.scala @@ -22,7 +22,8 @@ class TransactionCollectorServiceSpec extends WordSpec { def create( xsnService: XSNService, - transactionDataHandler: TransactionBlockingDataHandler): TransactionCollectorService = { + transactionDataHandler: TransactionBlockingDataHandler + ): TransactionCollectorService = { val futureDataHandler = new TransactionFutureDataHandler(transactionDataHandler)(Executors.databaseEC) new TransactionCollectorService(xsnService, futureDataHandler) @@ -136,7 +137,7 @@ class TransactionCollectorServiceSpec extends WordSpec { val pending1 = { val x = DataGenerator.randomTransactionId - x-> Bad(TransactionError.NotFound(x)).accumulating + x -> Bad(TransactionError.NotFound(x)).accumulating } val pending1Tx = createTransaction(pending1._1, List.empty) @@ -161,7 +162,9 @@ class TransactionCollectorServiceSpec extends WordSpec { val service = create(xsnService, null) whenReady(service.completeRPCTransactionsSequentially(input)) { result => - val expected = firstHalf.flatMap(_._2.toOption) ::: List(pending1Tx) ::: secondHalf.flatMap(_._2.toOption) ::: List(pending2Tx) + val expected = firstHalf.flatMap(_._2.toOption) ::: List(pending1Tx) ::: secondHalf.flatMap(_._2.toOption) ::: List( + pending2Tx + ) result.toEither.right.value must be(expected) } } diff --git a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala index 2214c40e..54df2838 100644 --- a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala +++ b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala @@ -25,6 +25,7 @@ class XSNServiceRPCImplSpec extends WordSpec { val ws = mock[WSClient] val ec = Executors.externalServiceEC + val rpcConfig = new RPCConfig { override def password: RPCConfig.Password = RPCConfig.Password("pass") override def host: RPCConfig.Host = RPCConfig.Host("localhost") @@ -32,7 +33,8 @@ class XSNServiceRPCImplSpec extends WordSpec { } val explorerConfig = new ExplorerConfig { - override def genesisBlock: Blockhash = Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get + override def genesisBlock: Blockhash = + Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get override def liteVersionConfig: ExplorerConfig.LiteVersionConfig = ??? } @@ -495,8 +497,8 @@ class XSNServiceRPCImplSpec extends WordSpec { status = "WATCHDOG_EXPIRED", activeSeconds = 0, lastSeen = 1532897292, - Address.from("XqdmM7rop8Sdgn8UjyNh3Povc3rhNSXYw2").get), - + Address.from("XqdmM7rop8Sdgn8UjyNh3Povc3rhNSXYw2").get + ), Masternode( txid = TransactionId.from("b02f99d87194c9400ab147c070bf621770684906dedfbbe9ba5f3a35c26b8d01").get, ip = "45.32.148.13:62583", @@ -504,7 +506,8 @@ class XSNServiceRPCImplSpec extends WordSpec { status = "ENABLED", activeSeconds = 6010, lastSeen = 1532905050, - Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get) + Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get + ) ) val responseBody = createRPCSuccessfulResponse(Json.parse(content)) val json = Json.parse(responseBody) @@ -536,7 +539,8 @@ class XSNServiceRPCImplSpec extends WordSpec { status = "ENABLED", activeSeconds = 6010, lastSeen = 1532905050, - Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get) + Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get + ) val responseBody = createRPCSuccessfulResponse(Json.parse(content)) val json = Json.parse(responseBody) diff --git a/server/test/controllers/AddressesControllerSpec.scala b/server/test/controllers/AddressesControllerSpec.scala index d8c72430..c78e9f51 100644 --- a/server/test/controllers/AddressesControllerSpec.scala +++ b/server/test/controllers/AddressesControllerSpec.scala @@ -25,6 +25,7 @@ class AddressesControllerSpec extends MyAPISpec { val addressBalance = Balance(addressWithBalance, spent = 100, received = 200) val addressForUtxos = DataHelper.createAddress("XeNEPsgeWqNbrEGEN5vqv4wYcC3qQrqNyp") + val utxosResponse = List( Transaction.Output( address = createAddress("XeNEPsgeWqNbrEGEN5vqv4wYcC3qQrqNyp"), @@ -43,17 +44,23 @@ class AddressesControllerSpec extends MyAPISpec { ) val addressForTransactions = createAddress("XxQ7j37LfuXgsLd5DZAwFKhT3s2ZMkW86F") + val addressTransaction = TransactionWithValues( createTransactionId("92c51e4fe89466faa734d6207a7ef6115fa1dd33f7156b006fafc6bb85a79eb8"), createBlockhash("ad22f0dcea2fdaa357aac6eab00695cf07b487e34113598909f625c24629c981"), 12312312L, Size(1000), sent = 50, - received = 200) + received = 200 + ) private val customTransactionDataHandler = new TransactionDummyDataHandler { - override def getBy(address: Address, paginatedQuery: PaginatedQuery, ordering: FieldOrdering[TransactionField]): ApplicationResult[PaginatedResult[TransactionWithValues]] = { + override def getBy( + address: Address, + paginatedQuery: PaginatedQuery, + ordering: FieldOrdering[TransactionField] + ): ApplicationResult[PaginatedResult[TransactionWithValues]] = { if (address == addressForTransactions) { Good(PaginatedResult(paginatedQuery.offset, paginatedQuery.limit, Count(1), List(addressTransaction))) } else { @@ -81,9 +88,9 @@ class AddressesControllerSpec extends MyAPISpec { } override val application = guiceApplicationBuilder - .overrides(bind[TransactionBlockingDataHandler].to(customTransactionDataHandler)) - .overrides(bind[BalanceBlockingDataHandler].to(customBalanceDataHandler)) - .build() + .overrides(bind[TransactionBlockingDataHandler].to(customTransactionDataHandler)) + .overrides(bind[BalanceBlockingDataHandler].to(customBalanceDataHandler)) + .build() "GET /addresses/:address" should { def url(address: String) = s"/addresses/$address" diff --git a/server/test/controllers/BalancesControllerSpec.scala b/server/test/controllers/BalancesControllerSpec.scala index 3bb65ed6..bb063503 100644 --- a/server/test/controllers/BalancesControllerSpec.scala +++ b/server/test/controllers/BalancesControllerSpec.scala @@ -19,43 +19,44 @@ class BalancesControllerSpec extends MyAPISpec { Balance( address = DataHelper.createAddress("XxQ7j37LfuXgsLd5DZAwFKhT3s2ZMkW85F"), received = BigDecimal("1000"), - spent = BigDecimal("0")), - + spent = BigDecimal("0") + ), Balance( address = DataHelper.createAddress("Xbh5pJdBNm8J9PxnEmwVcuQKRmZZ7DkpcF"), received = BigDecimal("1000"), - spent = BigDecimal("100")), - + spent = BigDecimal("100") + ), Balance( address = DataHelper.createAddress("XfAATXtkRgCdMTrj2fxHvLsKLLmqAjhEAt"), received = BigDecimal("10000"), - spent = BigDecimal("1000")), - + spent = BigDecimal("1000") + ), Balance( address = DataHelper.createAddress("XiHW7SR56UPHeXKwcpeVsE4nUfkHv5RqE3"), received = BigDecimal("1000"), - spent = BigDecimal("500"))) - .sortBy(_.available) - .reverse + spent = BigDecimal("500") + ) + ).sortBy(_.available) + .reverse val dataHandler = new BalanceDummyDataHandler { - override def getNonZeroBalances(query: PaginatedQuery, ordering: FieldOrdering[BalanceField]): ApplicationResult[PaginatedResult[Balance]] = { + override def getNonZeroBalances( + query: PaginatedQuery, + ordering: FieldOrdering[BalanceField] + ): ApplicationResult[PaginatedResult[Balance]] = { val filtered = balances.filter(_.available > 0) val list = filtered.drop(query.offset.int).take(query.limit.int) - val result = PaginatedResult( - offset = query.offset, - limit = query.limit, - total = Count(filtered.size), - data = list) + val result = + PaginatedResult(offset = query.offset, limit = query.limit, total = Count(filtered.size), data = list) Good(result) } } val application = guiceApplicationBuilder - .overrides(bind[BalanceBlockingDataHandler].to(dataHandler)) - .build() + .overrides(bind[BalanceBlockingDataHandler].to(dataHandler)) + .build() "GET /balances" should { "get the richest addresses" in { diff --git a/server/test/controllers/BlocksControllerSpec.scala b/server/test/controllers/BlocksControllerSpec.scala index f5b4f3af..3b5d7f65 100644 --- a/server/test/controllers/BlocksControllerSpec.scala +++ b/server/test/controllers/BlocksControllerSpec.scala @@ -29,9 +29,9 @@ class BlocksControllerSpec extends MyAPISpec { private val transactionDataHandlerMock = mock[TransactionBlockingDataHandler] override val application = guiceApplicationBuilder - .overrides(bind[XSNService].to(customXSNService)) - .overrides(bind[TransactionBlockingDataHandler].to(transactionDataHandlerMock)) - .build() + .overrides(bind[XSNService].to(customXSNService)) + .overrides(bind[TransactionBlockingDataHandler].to(transactionDataHandlerMock)) + .build() "GET /blocks/:query" should { def url(query: String) = s"/blocks/$query" @@ -262,36 +262,30 @@ class BlocksControllerSpec extends MyAPISpec { val result = { val transactions = BlockLoader - .getRPC(blockhash.string) - .transactions - .map(_.string) - .map(TransactionLoader.get) - .map { tx => - TransactionWithValues( - id = tx.id, - blockhash = blockhash, - time = tx.time, - size = tx.size, - sent = tx.vin.collect { case x: TransactionVIN.HasValues => x }.map(_.value).sum, - received = tx.vout.map(_.value).sum - ) - } - - val page = PaginatedResult( - Offset(0), - Limit(10), - Count(transactions.size), - transactions.take(5)) + .getRPC(blockhash.string) + .transactions + .map(_.string) + .map(TransactionLoader.get) + .map { tx => + TransactionWithValues( + id = tx.id, + blockhash = blockhash, + time = tx.time, + size = tx.size, + sent = tx.vin.collect { case x: TransactionVIN.HasValues => x }.map(_.value).sum, + received = tx.vout.map(_.value).sum + ) + } + + val page = PaginatedResult(Offset(0), Limit(10), Count(transactions.size), transactions.take(5)) Good(page) } - when(transactionDataHandlerMock - .getByBlockhash( - eqTo(blockhash), - any[PaginatedQuery], - any[FieldOrdering[TransactionField]])) - .thenReturn(result) + when( + transactionDataHandlerMock + .getByBlockhash(eqTo(blockhash), any[PaginatedQuery], any[FieldOrdering[TransactionField]]) + ).thenReturn(result) val response = GET(s"/blocks/$blockhash/transactions") status(response) mustEqual OK @@ -313,19 +307,29 @@ class BlocksControllerSpec extends MyAPISpec { val tx = Transaction.HasIO( transaction = Transaction(txid, blockhash, 0, Size(1)), inputs = List( - Transaction.Input(fromTxid = DataGenerator.randomTransactionId, fromOutputIndex = 1, index = 0, value = 100, address = DataGenerator.randomAddress) + Transaction.Input( + fromTxid = DataGenerator.randomTransactionId, + fromOutputIndex = 1, + index = 0, + value = 100, + address = DataGenerator.randomAddress + ) ), outputs = List( - Transaction.Output(txid = txid, index = 0, value = 200, address = DataGenerator.randomAddress, DataGenerator.randomHexString(8)) + Transaction.Output( + txid = txid, + index = 0, + value = 200, + address = DataGenerator.randomAddress, + DataGenerator.randomHexString(8) + ) ) ) - when(transactionDataHandlerMock - .getTransactionsWithIOBy( - eqTo(blockhash), - eqTo(Limit(10)), - eqTo(Option.empty))) - .thenReturn(Good(List(tx))) + when( + transactionDataHandlerMock + .getTransactionsWithIOBy(eqTo(blockhash), eqTo(Limit(10)), eqTo(Option.empty)) + ).thenReturn(Good(List(tx))) val response = GET(s"/v2/blocks/$blockhash/light-wallet-transactions") diff --git a/server/test/controllers/HealthControllerSpec.scala b/server/test/controllers/HealthControllerSpec.scala index 200bd168..e30d9a55 100644 --- a/server/test/controllers/HealthControllerSpec.scala +++ b/server/test/controllers/HealthControllerSpec.scala @@ -15,4 +15,4 @@ class HealthControllerSpec extends MyAPISpec { status(response) mustEqual OK } } -} \ No newline at end of file +} diff --git a/server/test/controllers/MasternodesControllerSpec.scala b/server/test/controllers/MasternodesControllerSpec.scala index c1237a53..578bbd86 100644 --- a/server/test/controllers/MasternodesControllerSpec.scala +++ b/server/test/controllers/MasternodesControllerSpec.scala @@ -25,8 +25,8 @@ class MasternodesControllerSpec extends MyAPISpec { status = "WATCHDOG_EXPIRED", activeSeconds = 513323, lastSeen = 1524349009, - payee = Address.from("XqdmM7rop8Sdgn8UjyNh3Povc3rhNSXYw2").get), - + payee = Address.from("XqdmM7rop8Sdgn8UjyNh3Povc3rhNSXYw2").get + ), Masternode( txid = TransactionId.from("b02f99d87194c9400ab147c070bf621770684906dedfbbe9ba5f3a35c26b8d01").get, ip = "45.32.148.13:62583", @@ -34,7 +34,8 @@ class MasternodesControllerSpec extends MyAPISpec { status = "ENABLED", activeSeconds = 777344, lastSeen = 1524349028, - payee = Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get) + payee = Address.from("XdNDRAiMUC9KiVRzhCTg9w44jQRdCpCRe3").get + ) ) val masternode = masternodes.last @@ -54,8 +55,8 @@ class MasternodesControllerSpec extends MyAPISpec { } override val application = guiceApplicationBuilder - .overrides(bind[XSNService].to(xsnService)) - .build + .overrides(bind[XSNService].to(xsnService)) + .build "GET /masternodes" should { "return the masternodes" in { diff --git a/server/test/controllers/StatisticsControllerSpec.scala b/server/test/controllers/StatisticsControllerSpec.scala index 45056b81..f58ab8ba 100644 --- a/server/test/controllers/StatisticsControllerSpec.scala +++ b/server/test/controllers/StatisticsControllerSpec.scala @@ -20,7 +20,8 @@ class StatisticsControllerSpec extends MyAPISpec { blocks = 45454, transactions = 93548, totalSupply = Some(BigDecimal("154516849.91650322")), - circulatingSupply = Some(BigDecimal("78016849.91636708"))) + circulatingSupply = Some(BigDecimal("78016849.91636708")) + ) val dataHandler = new StatisticsBlockingDataHandler { override def getStatistics(): ApplicationResult[Statistics] = Good(stats) @@ -29,9 +30,9 @@ class StatisticsControllerSpec extends MyAPISpec { val xsnService = mock[XSNService] override val application = guiceApplicationBuilder - .overrides(bind[StatisticsBlockingDataHandler].to(dataHandler)) - .overrides(bind[XSNService].to(xsnService)) - .build() + .overrides(bind[StatisticsBlockingDataHandler].to(dataHandler)) + .overrides(bind[XSNService].to(xsnService)) + .build() "GET /stats" should { "return the server statistics" in { diff --git a/server/test/controllers/TransactionsControllerSpec.scala b/server/test/controllers/TransactionsControllerSpec.scala index 6e18fb66..6f7b1ee8 100644 --- a/server/test/controllers/TransactionsControllerSpec.scala +++ b/server/test/controllers/TransactionsControllerSpec.scala @@ -20,7 +20,8 @@ class TransactionsControllerSpec extends MyAPISpec { private val coinbaseTx = TransactionLoader.get("024aba1d535cfe5dd3ea465d46a828a57b00e1df012d7a2d158e0f7484173f7c") private val nonCoinbaseTx = TransactionLoader.get("0834641a7d30d8a2d2b451617599670445ee94ed7736e146c13be260c576c641") - private val severalInputsTx = TransactionLoader.get("a3c43d22bbba31a6e5c00f565cb9c5a1a365407df4cc90efa8a865656b52c0eb") + private val severalInputsTx = + TransactionLoader.get("a3c43d22bbba31a6e5c00f565cb9c5a1a365407df4cc90efa8a865656b52c0eb") private val customXSNService = new FileBasedXSNService @@ -60,12 +61,15 @@ class TransactionsControllerSpec extends MyAPISpec { } "return non-coinbase transaction" in { - val input = List( - TransactionValue( - createAddress("XgEGH3y7RfeKEdn2hkYEvBnrnmGBr7zvjL"), - BigDecimal("2343749.965625"))) + val input = + List(TransactionValue(createAddress("XgEGH3y7RfeKEdn2hkYEvBnrnmGBr7zvjL"), BigDecimal("2343749.965625"))) .map { v => - rpc.TransactionVIN.HasValues(createTransactionId("024aba1d535cfe5dd3ea465d46a828a57b00e1df012d7a2d158e0f7484173f7c"), 0, v.value, v.addresses) + rpc.TransactionVIN.HasValues( + createTransactionId("024aba1d535cfe5dd3ea465d46a828a57b00e1df012d7a2d158e0f7484173f7c"), + 0, + v.value, + v.addresses + ) } val tx = nonCoinbaseTx.copy(vin = input) @@ -103,9 +107,8 @@ class TransactionsControllerSpec extends MyAPISpec { "return a transaction with several inputs" in { val tx = severalInputsTx - val inputValue = TransactionValue( - createAddress("XgEGH3y7RfeKEdn2hkYEvBnrnmGBr7zvjL"), - BigDecimal("73242.18642578")) + val inputValue = + TransactionValue(createAddress("XgEGH3y7RfeKEdn2hkYEvBnrnmGBr7zvjL"), BigDecimal("73242.18642578")) val response = GET(url(tx.id.string)) diff --git a/server/test/controllers/common/MyAPISpec.scala b/server/test/controllers/common/MyAPISpec.scala index 5ad66d00..447924e6 100644 --- a/server/test/controllers/common/MyAPISpec.scala +++ b/server/test/controllers/common/MyAPISpec.scala @@ -44,7 +44,8 @@ trait MyAPISpec extends PlayAPISpec { Configuration.load(env) ++ Configuration.from(map) } - override val guiceApplicationBuilder: GuiceApplicationBuilder = GuiceApplicationBuilder(loadConfiguration = loadConfigWithoutEvolutions) + override val guiceApplicationBuilder: GuiceApplicationBuilder = + GuiceApplicationBuilder(loadConfiguration = loadConfigWithoutEvolutions) .in(Mode.Test) .disable(classOf[PollerSynchronizerModule]) .overrides(bind[Database].to(dummyDB))