From 45824b5a42cd30ffc73a80664f4cb2bae022a6dd Mon Sep 17 00:00:00 2001 From: bagf Date: Thu, 18 Jul 2019 04:00:36 +0200 Subject: [PATCH] Tests wip Signed-off-by: bagf --- akka/src/test/resources/application.conf | 37 +++++++ .../scala/net/cimadai/iroha/IrohaSpec.scala | 97 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 akka/src/test/resources/application.conf create mode 100644 akka/src/test/scala/net/cimadai/iroha/IrohaSpec.scala diff --git a/akka/src/test/resources/application.conf b/akka/src/test/resources/application.conf new file mode 100644 index 0000000..5a1b3ca --- /dev/null +++ b/akka/src/test/resources/application.conf @@ -0,0 +1,37 @@ +akka.grpc.client { + iroha { + # Host to use if service-discovery-mechanism is set to static + host = "127.0.0.1" + + service-discovery { + mechanism = "static" + # Service name to use if a service-discovery.mechanism other than static + service-name = "" + # See https://developer.lightbend.com/docs/akka-management/current/discovery/index.html for meanings for each mechanism + # if blank then not passed to the lookup + port-name = "" + protocol = "" + + # timeout for service discovery resolving + resolve-timeout = 1s + } + + # port to use if service-discovery-mechism is static or service discovery does not return a port + port = 50051 + + deadline = infinite + override-authority = "" + user-agent = "" + # Pulls default configuration from ssl-config-core's reference.conf + # ssl-config = ${ssl-config} + use-tls = false + + # TODO: Enforce HTTP/2 TLS restrictions: https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-9.2 + connection-attempts = -1 + + # Service discovery mechamism to use. The default is to use a static host + # and port that will be resolved via DNS. + # Any of the mechanisms described [here](https://developer.lightbend.com/docs/akka-management/current/discovery/index.html) can be used + # including Kubernetes, Consul, AWS API + } +} diff --git a/akka/src/test/scala/net/cimadai/iroha/IrohaSpec.scala b/akka/src/test/scala/net/cimadai/iroha/IrohaSpec.scala new file mode 100644 index 0000000..7fc046f --- /dev/null +++ b/akka/src/test/scala/net/cimadai/iroha/IrohaSpec.scala @@ -0,0 +1,97 @@ +package net.cimadai.iroha + +import java.security.KeyPair + +import iroha.protocol.Query.Payload.Query +import org.scalatest.concurrent.{Eventually, ScalaFutures} +import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers} +import akka.{Done, NotUsed} +import akka.actor.ActorSystem +import akka.grpc.GrpcClientSettings +import akka.stream.ActorMaterializer +import akka.stream.scaladsl.{Sink, Source} +import iroha.protocol.{CommandService_v1, CommandService_v1Client, QueryService_v1, QueryService_v1Client, Transaction, TxList, TxStatusRequest} +import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3 + +import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.util.{Failure, Success} + +class IrohaSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with Eventually with ScalaFutures { + implicit val sys = ActorSystem("IrohaSpec") + implicit val mat = ActorMaterializer() + implicit val ec = sys.dispatcher + + // Take details how to connect to the service from the config. + private val clientSettings = GrpcClientSettings.fromConfig("iroha") + // Create a client-side stub for the service + private val commandClient: CommandService_v1 = CommandService_v1Client(clientSettings) + private val queryClient: QueryService_v1 = QueryService_v1Client(clientSettings) + private val crypto = new Ed25519Sha3() + + + "IrohaSpec" when { + "GetAccount" should { + "query admin account" in { + import iroha.protocol.Query.Payload.Query.GetAccount + import iroha.protocol.QueryPayloadMeta + import iroha.protocol.Query + import iroha.protocol.Query.Payload + val createdTime = System.currentTimeMillis() + val payloadMeta = QueryPayloadMeta( + createdTime = createdTime, + creatorAccountId = "admin@test", + queryCounter = 1 + ) + val pk = Utils.parseHexKeypair( + "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910", + "f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70" + ) + val p = Payload( + Some(payloadMeta), + GetAccount(iroha.protocol.GetAccount("admin@test")) + ) + + val q = Query(Some(p)) + val sig = Utils.sign(q, pk) + + queryClient.find(q.withSignature(sig)).map { r => + println(r) + assert(r.response.isAccountResponse) + } + } + } + "AddAsset" should { + "add asset to admin account" in { + import iroha.protocol.Command + import iroha.protocol.Command.Command.AddAssetQuantity + import iroha.protocol.Transaction.Payload + import iroha.protocol.Transaction.Payload.ReducedPayload + val createdTime = System.currentTimeMillis() + val command = Command( + AddAssetQuantity(iroha.protocol.AddAssetQuantity("coin#test", "100.0")) + ) + val pk = Utils.parseHexKeypair( + "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910", + "f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70" + ) + val tx = Transaction(Some( + Payload( + Some(ReducedPayload(Seq(command), "admin@test", createdTime, 1)) + ) + )) +// val pload = Utils.createTxOrderedBatch(Seq(tx), pk) +// commandClient.listTorii(TxList(pload)).flatMap { _ => + commandClient.torii(tx.withSignatures(Seq(Utils.sign(tx.getPayload, pk)))).flatMap { _ => + Thread.sleep(2000) + commandClient.statusStream(TxStatusRequest(Utils.toHex(Utils.hash(tx.getPayload)))) + .runWith(Sink.foreach(println)) + .map { + _ => assert(true) + } + } + } + } + } +} +