Skip to content

Commit

Permalink
Add height to transaction info
Browse files Browse the repository at this point in the history
close #104
  • Loading branch information
catena2w committed Jun 9, 2016
1 parent a024f95 commit b9c40ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -72,7 +72,7 @@ case class TransactionsApiRoute(override val application: Application)(implicit
Try {
val block = application.blockStorage.history.asInstanceOf[StoredBlockchain].blockAt(h).get
val tx = block.transactions.filter(_.signature sameElements sig).head
tx.json
tx.json + ("height" -> Json.toJson(h))
}.getOrElse(Json.obj("status" -> "error", "details" -> "Internal error"))
case None => Json.obj("status" -> "error", "details" -> "Transaction is not in blockchain")
}
Expand Down
Expand Up @@ -23,7 +23,7 @@ case class GenesisTransaction(override val recipient: Account,
override lazy val creator: Option[Account] = None

override lazy val json: JsObject =
jsonBase() ++ Json.obj("recipient" -> recipient.address, "amount" -> amount.toString)
jsonBase() ++ Json.obj("recipient" -> recipient.address, "amount" -> amount)

override lazy val bytes: Array[Byte] = {
val typeBytes = Array(TransactionType.GenesisTransaction.id.toByte)
Expand Down
Expand Up @@ -2,6 +2,8 @@ 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

class TransactionsAPISpecification extends FunSuite with Matchers with TransactionTestingCommons {
Expand Down Expand Up @@ -35,8 +37,19 @@ class TransactionsAPISpecification extends FunSuite with Matchers with Transacti
}
}

test("/transactions/info/{signature} API route") {
val genesisTx = Block.genesis().transactions.head
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[String].replace("\"", "").toLong should be > 0L)
(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)
Expand Down

0 comments on commit b9c40ab

Please sign in to comment.