Skip to content

Commit

Permalink
server: Let scalafmt format the test sources
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Jun 5, 2019
1 parent 5767ab2 commit 87c55df
Show file tree
Hide file tree
Showing 34 changed files with 486 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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() = {
Expand All @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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)

Expand All @@ -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))

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand All @@ -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()
}
}
}
Loading

0 comments on commit 87c55df

Please sign in to comment.