<commit_before>package scorex.lagonaki.integration.api

import org.scalatest.{FunSuite, Matchers}
import play.api.libs.json.JsValue
import scorex.block.Block
import scorex.crypto.encode.Base58
import scorex.lagonaki.TransactionTestingCommons
import scorex.transaction.GenesisTransaction
import scorex.lagonaki.integration.TestLock

class TransactionsAPISpecification extends FunSuite with TestLock with Matchers with TransactionTestingCommons {

  import scorex.lagonaki.TestingCommons._

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

    if (application.wallet.privateKeyAccounts().size < 10) application.wallet.generateNewAccounts(10)
  }

  def addresses = accounts.map(_.address)

  test("/transactions/unconfirmed API route") {
    (1 to 20) foreach (i => genValidTransaction())
    val unconfirmed = transactionModule.utxStorage.all()
    unconfirmed.size should be > 0
    val tr = GET.request("/transactions/unconfirmed")
    (tr \\ "signature").toList.size shouldBe unconfirmed.size
  }

  test("/transactions/address/{address} API route") {
    addresses.foreach { a =>
      checkTransactionList(GET.request(s"/transactions/address/$a"))
    }
  }

  test("/transactions/address/{address}/limit/{limit} API route") {
    addresses.foreach { a =>
      val tr = GET.request(s"/transactions/address/$a/limit/2")
      (tr \\ "amount").toList.size should be <= 2
      checkTransactionList(tr)
    }
  }

  test("/transactions/info/{signature} API route") {
    val genesisTx = Block.genesis().transactions.head.asInstanceOf[GenesisTransaction]
    val tr = GET.request(s"/transactions/info/${Base58.encode(genesisTx.signature)}")
    (tr \ "signature").as[String] shouldBe Base58.encode(genesisTx.signature)
    (tr \ "type").as[Int] shouldBe 1
    (tr \ "fee").as[Int] shouldBe 0
    (tr \ "amount").as[Long] should be > 0L
    (tr \ "height").as[Int] shouldBe 1
    (tr \ "recipient").as[String] shouldBe genesisTx.recipient.address
  }

  def checkTransactionList(tr: JsValue): Unit = {
    (tr \\ "amount").toList.foreach(amount => amount.as[Long] should be > 0L)
    (tr \\ "fee").toList.foreach(amount => amount.as[Long] should be >= 0L)
    (tr \\ "type").toList.foreach(amount => amount.as[Int] should be >= 0)
    (tr \\ "timestamp").toList.foreach(amount => amount.as[Long] should be >= 0L)<commit_msg>fix tests<commit_after>package scorex.lagonaki.integration.api

import org.scalatest.{FunSuite, Matchers}
import play.api.libs.json.JsValue
import scorex.block.Block
import scorex.crypto.encode.Base58
import scorex.lagonaki.TransactionTestingCommons
import scorex.transaction.GenesisTransaction
import scorex.lagonaki.integration.TestLock

class TransactionsAPISpecification extends FunSuite with TestLock with Matchers with TransactionTestingCommons {

  import scorex.lagonaki.TestingCommons._

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

    if (application.wallet.privateKeyAccounts().size < 10) application.wallet.generateNewAccounts(10)
  }

  def addresses = accounts.map(_.address)

  test("/transactions/unconfirmed API route") {
    (1 to 20) foreach (i => genValidTransaction())
    val unconfirmed = transactionModule.utxStorage.all()
    unconfirmed.size should be > 0
    val tr = GET.request("/transactions/unconfirmed")
    (tr \\ "signature").toList.size shouldBe unconfirmed.size
  }

  test("/transactions/address/{address}/limit/{limit} API route") {
    addresses.foreach { a =>
      val tr = GET.request(s"/transactions/address/$a/limit/2")
      (tr \\ "amount").toList.size should be <= 2
      checkTransactionList(tr)
    }
  }

  test("/transactions/info/{signature} API route") {
    val genesisTx = Block.genesis().transactions.head.asInstanceOf[GenesisTransaction]
    val tr = GET.request(s"/transactions/info/${Base58.encode(genesisTx.signature)}")
    (tr \ "signature").as[String] shouldBe Base58.encode(genesisTx.signature)
    (tr \ "type").as[Int] shouldBe 1
    (tr \ "fee").as[Int] shouldBe 0
    (tr \ "amount").as[Long] should be > 0L
    (tr \ "height").as[Int] shouldBe 1
    (tr \ "recipient").as[String] shouldBe genesisTx.recipient.address
  }

  def checkTransactionList(tr: JsValue): Unit = {
    (tr \\ "amount").toList.foreach(amount => amount.as[Long] should be > 0L)
    (tr \\ "fee").toList.foreach(amount => amount.as[Long] should be >= 0L)
    (tr \\ "type").toList.foreach(amount => amount.as[Int] should be >= 0)
    (tr \\ "timestamp").toList.foreach(amount => amount.as[Long] should be >= 0L)
{'fraction_non_alphanumeric': 0.14083572849878398, 'fraction_numerical': 0.010612425381384037, 'mean_word_length': 4.026666666666666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3876318', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1397, 'n_words': 288}