<commit_before>package com.wavesplatform.http

import com.wavesplatform.http.ApiMarshallers._
import org.scalacheck.Gen
import org.scalamock.scalatest.MockFactory
import org.scalatest.Matchers
import org.scalatest.prop.PropertyChecks
import play.api.libs.json._
import scorex.api.http.TransactionsApiRoute
import scorex.crypto.encode.Base58
import scorex.transaction._

class TransactionsRouteSpec extends RouteSpec("/transactions")
  with RestAPISettingsHelper with MockFactory with Matchers with TransactionGen with PropertyChecks {

  private val history = mock[History]
  private val state = mock[State]
  private val stm = mock[TransactionModule]
  private val route = TransactionsApiRoute(restAPISettings, state, history, stm).route

  private val txGen = for {
    tr <- transferGenerator
    is <- issueGenerator
    al <- createAliasGenerator
    le <- leaseGenerator
    cl <- leaseCancelGenerator
    tx <- Gen.oneOf(tr, is, al, le, cl)
  } yield tx

  routePath("/address/{address}/limit/{limit}") in {
    // todo: check invalid address
    // todo: check invalid limit
  }
  routePath("/info/{signature}") in {
    // todo: check invalid signature
    // todo: check empty signature

  }

  routePath("/unconfirmed") in {
    val g = for {
      i <- Gen.chooseNum(0, 20)
      t <- Gen.listOfN(i, txGen)
    } yield t

    forAll(g) { txs =>
      (stm.unconfirmedTxs _).expects().returning(txs).once()
      Get(routePath("/unconfirmed")) ~> route ~> check {
        val resp = responseAs[Seq[JsValue]]
        for ((r, t) <- resp.zip(txs)) {
          (r \ "signature").as[String] shouldEqual Base58.encode(t.signature)
        }
      }
    }
  }
}<commit_msg>Implemented most of the tests<commit_after>package com.wavesplatform.http

import com.wavesplatform.TransactionGen
import com.wavesplatform.http.ApiMarshallers._
import org.scalacheck.{Gen, Shrink}
import org.scalamock.scalatest.MockFactory
import org.scalatest.Matchers
import org.scalatest.prop.PropertyChecks
import play.api.libs.json._
import scorex.api.http.{InvalidSignature, TransactionsApiRoute}
import scorex.crypto.encode.Base58
import scorex.transaction._

class TransactionsRouteSpec extends RouteSpec("/transactions")
  with RestAPISettingsHelper with MockFactory with Matchers with TransactionGen with PropertyChecks {

  private val history = mock[History]
  private val state = mock[State]
  private val stm = mock[TransactionModule]
  private val route = TransactionsApiRoute(restAPISettings, state, history, stm).route

  private implicit def noShrink[A]: Shrink[A] = Shrink(_ => Stream.empty)

  routePath("/address/{address}/limit/{limit}") in {
    // todo: check invalid address
    // todo: check invalid limit

  }

  routePath("/info/{signature}") in {
    forAll(Gen.alphaNumStr.map(_ + "O")) { invalidBase58 =>
      Get(routePath(s"/info/$invalidBase58")) ~> route should produce(InvalidSignature)
    }

    Get(routePath("/info/")) ~> route should produce(InvalidSignature)

    val txAvailability = for {
      tx <- randomTransactionGen
      height <- Gen.option(Gen.posNum[Int])
    } yield (tx, height)

    def sameSignature(target: Array[Byte])(actual: Array[Byte]): Boolean = target sameElements actual

    forAll(txAvailability) {
      case (tx, height) =>
        (state.included _).expects(where(sameSignature(tx.signature) _)).returning(height).once()
        height.foreach { h => (history.blockAt _).expects(h).returning(None).once() }
        val result = Get(routePath(s"/info/${Base58.encode(tx.signature)}")) ~> route ~> runRoute
    }
  }

  routePath("/unconfirmed") in {
    val g = for {
      i <- Gen.chooseNum(0, 20)
      t <- Gen.listOfN(i, randomTransactionGen)
    } yield t

    forAll(g) { txs =>
      (stm.unconfirmedTxs _).expects().returning(txs).once()
      Get(routePath("/unconfirmed")) ~> route ~> check {
        val resp = responseAs[Seq[JsValue]]
        for ((r, t) <- resp.zip(txs)) {
          (r \ "signature").as[String] shouldEqual Base58.encode(t.signature)
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1255250803063998, 'fraction_numerical': 0.004941932295527552, 'mean_word_length': 3.5688487584650113, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6541050', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1230, 'n_words': 282}