|
|
@ -1,16 +1,17 @@ |
|
|
|
package controllers |
|
|
|
|
|
|
|
import com.alexitc.playsonify.PublicErrorRenderer |
|
|
|
import com.alexitc.playsonify.core.FutureApplicationResult |
|
|
|
import com.alexitc.playsonify.core.{ApplicationResult, FutureApplicationResult} |
|
|
|
import com.xsn.explorer.data.TransactionBlockingDataHandler |
|
|
|
import com.xsn.explorer.errors.TransactionNotFoundError |
|
|
|
import com.xsn.explorer.helpers.{DataHelper, DummyXSNService, TransactionLoader} |
|
|
|
import com.xsn.explorer.helpers.{DataHelper, DummyXSNService, TransactionDummyDataHandler, TransactionLoader} |
|
|
|
import com.xsn.explorer.models._ |
|
|
|
import com.xsn.explorer.models.rpc.Transaction |
|
|
|
import com.xsn.explorer.services.XSNService |
|
|
|
import controllers.common.MyAPISpec |
|
|
|
import org.scalactic.{Bad, Good} |
|
|
|
import org.scalactic.{Bad, Every, Good} |
|
|
|
import play.api.inject.bind |
|
|
|
import play.api.libs.json.JsValue |
|
|
|
import play.api.libs.json.{JsValue, Json} |
|
|
|
import play.api.test.Helpers._ |
|
|
|
|
|
|
|
import scala.concurrent.Future |
|
|
@ -23,6 +24,10 @@ class TransactionsControllerSpec extends MyAPISpec { |
|
|
|
val nonCoinbaseTx = TransactionLoader.get("0834641a7d30d8a2d2b451617599670445ee94ed7736e146c13be260c576c641") |
|
|
|
val nonCoinbasePreviousTx = TransactionLoader.get("585cec5009c8ca19e83e33d282a6a8de65eb2ca007b54d6572167703768967d9") |
|
|
|
val severalInputsTx = TransactionLoader.get("a3c43d22bbba31a6e5c00f565cb9c5a1a365407df4cc90efa8a865656b52c0eb") |
|
|
|
val firstAddress = createAddress("fygsydgfygsdyfgsdyg") |
|
|
|
val secondAddress = createAddress("56wedf5wedweedw") |
|
|
|
val firstTxId = DataHelper.createTransactionId("a3c43d223658a8656a31a6e5c407df4bbb0f565cb9c5a1acc90efa056b52c0eb") |
|
|
|
val secondTxId = DataHelper.createTransactionId("8a865656b5a3c43d22b00f565cb9c5a1a3bba31a6e5c65407df4cc90efa2c0eb") |
|
|
|
|
|
|
|
val customXSNService = new DummyXSNService { |
|
|
|
val map = Map( |
|
|
@ -54,9 +59,23 @@ class TransactionsControllerSpec extends MyAPISpec { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
val transactionDataHandler = new TransactionDummyDataHandler { |
|
|
|
|
|
|
|
val map: Map[Address, TransactionId] = Map(firstAddress -> firstTxId, secondAddress -> secondTxId) |
|
|
|
|
|
|
|
override def getLatestTransactionBy(addresses: Every[Address]): ApplicationResult[Map[String, String]] = { |
|
|
|
val result = map |
|
|
|
.filterKeys(addresses contains _) |
|
|
|
.map( x => x._1.string -> x._2.string ) |
|
|
|
|
|
|
|
Good(result) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
override val application = guiceApplicationBuilder |
|
|
|
.overrides(bind[XSNService].to(customXSNService)) |
|
|
|
.build() |
|
|
|
.overrides(bind[XSNService].to(customXSNService)) |
|
|
|
.overrides(bind[TransactionBlockingDataHandler].to(transactionDataHandler)) |
|
|
|
.build() |
|
|
|
|
|
|
|
"GET /transactions/:txid" should { |
|
|
|
def url(txid: String) = s"/transactions/$txid" |
|
|
@ -205,4 +224,39 @@ class TransactionsControllerSpec extends MyAPISpec { |
|
|
|
json mustEqual expected |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
"POST /transactions/latest" should { |
|
|
|
def url = s"/transactions/latest" |
|
|
|
|
|
|
|
"return the latest transactions for the addresses" in { |
|
|
|
|
|
|
|
val body = List(firstAddress.string, secondAddress.string, "3rdaddress") |
|
|
|
.map(x => s""" "$x" """) |
|
|
|
.mkString("[", ",", "]") |
|
|
|
val expected = Json.obj(firstAddress.string -> firstTxId, secondAddress.string -> secondTxId) |
|
|
|
|
|
|
|
val response = POST(url, Some(body)) |
|
|
|
|
|
|
|
status(response) mustEqual OK |
|
|
|
val json = contentAsJson(response) |
|
|
|
json mustEqual expected |
|
|
|
} |
|
|
|
|
|
|
|
"fail while passing no addresses" in { |
|
|
|
val body = """[]""" |
|
|
|
val response = POST(url, Some(body)) |
|
|
|
|
|
|
|
status(response) mustEqual BAD_REQUEST |
|
|
|
|
|
|
|
val json = contentAsJson(response) |
|
|
|
val errorList = (json \ "errors").as[List[JsValue]] |
|
|
|
|
|
|
|
errorList.size mustEqual 1 |
|
|
|
val error = errorList.head |
|
|
|
|
|
|
|
(error \ "type").as[String] mustEqual PublicErrorRenderer.FieldValidationErrorType |
|
|
|
(error \ "field").as[String].nonEmpty mustEqual false |
|
|
|
(error \ "message").as[String].nonEmpty mustEqual true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|