Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit d2af580

Browse files
committed
Tests wip
Signed-off-by: bagf <[email protected]>
1 parent 5802345 commit d2af580

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
akka.grpc.client {
2+
iroha {
3+
# Host to use if service-discovery-mechanism is set to static
4+
host = "127.0.0.1"
5+
6+
service-discovery {
7+
mechanism = "static"
8+
# Service name to use if a service-discovery.mechanism other than static
9+
service-name = ""
10+
# See https://developer.lightbend.com/docs/akka-management/current/discovery/index.html for meanings for each mechanism
11+
# if blank then not passed to the lookup
12+
port-name = ""
13+
protocol = ""
14+
15+
# timeout for service discovery resolving
16+
resolve-timeout = 1s
17+
}
18+
19+
# port to use if service-discovery-mechism is static or service discovery does not return a port
20+
port = 50051
21+
22+
deadline = infinite
23+
override-authority = ""
24+
user-agent = ""
25+
# Pulls default configuration from ssl-config-core's reference.conf
26+
# ssl-config = ${ssl-config}
27+
use-tls = false
28+
29+
# TODO: Enforce HTTP/2 TLS restrictions: https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-9.2
30+
connection-attempts = -1
31+
32+
# Service discovery mechamism to use. The default is to use a static host
33+
# and port that will be resolved via DNS.
34+
# Any of the mechanisms described [here](https://developer.lightbend.com/docs/akka-management/current/discovery/index.html) can be used
35+
# including Kubernetes, Consul, AWS API
36+
}
37+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package net.cimadai.iroha
2+
3+
import java.security.KeyPair
4+
5+
import iroha.protocol.Query.Payload.Query
6+
import org.scalatest.concurrent.{Eventually, ScalaFutures}
7+
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
8+
import akka.{Done, NotUsed}
9+
import akka.actor.ActorSystem
10+
import akka.grpc.GrpcClientSettings
11+
import akka.stream.ActorMaterializer
12+
import akka.stream.scaladsl.{Sink, Source}
13+
import iroha.protocol.{CommandService_v1, CommandService_v1Client, QueryService_v1, QueryService_v1Client, Transaction, TxList, TxStatusRequest}
14+
import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3
15+
16+
import scala.concurrent.Future
17+
import scala.concurrent.duration._
18+
import scala.util.{Failure, Success}
19+
20+
class IrohaSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with Eventually with ScalaFutures {
21+
implicit val sys = ActorSystem("IrohaSpec")
22+
implicit val mat = ActorMaterializer()
23+
implicit val ec = sys.dispatcher
24+
25+
// Take details how to connect to the service from the config.
26+
private val clientSettings = GrpcClientSettings.fromConfig("iroha")
27+
// Create a client-side stub for the service
28+
private val commandClient: CommandService_v1 = CommandService_v1Client(clientSettings)
29+
private val queryClient: QueryService_v1 = QueryService_v1Client(clientSettings)
30+
private val crypto = new Ed25519Sha3()
31+
32+
33+
"IrohaSpec" when {
34+
"GetAccount" should {
35+
"query admin account" in {
36+
import iroha.protocol.Query.Payload.Query.GetAccount
37+
import iroha.protocol.QueryPayloadMeta
38+
import iroha.protocol.Query
39+
import iroha.protocol.Query.Payload
40+
val createdTime = System.currentTimeMillis()
41+
val payloadMeta = QueryPayloadMeta(
42+
createdTime = createdTime,
43+
creatorAccountId = "admin@test",
44+
queryCounter = 1
45+
)
46+
val pk = Utils.parseHexKeypair(
47+
"313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910",
48+
"f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70"
49+
)
50+
val p = Payload(
51+
Some(payloadMeta),
52+
GetAccount(iroha.protocol.GetAccount("admin@test"))
53+
)
54+
55+
val q = Query(Some(p))
56+
val sig = Utils.sign(q, pk)
57+
58+
queryClient.find(q.withSignature(sig)).map { r =>
59+
println(r)
60+
assert(r.response.isAccountResponse)
61+
}
62+
}
63+
}
64+
"AddAsset" should {
65+
"add asset to admin account" in {
66+
import iroha.protocol.Command
67+
import iroha.protocol.Command.Command.AddAssetQuantity
68+
import iroha.protocol.Transaction.Payload
69+
import iroha.protocol.Transaction.Payload.ReducedPayload
70+
val createdTime = System.currentTimeMillis()
71+
val command = Command(
72+
AddAssetQuantity(iroha.protocol.AddAssetQuantity("coin#test", "100.0"))
73+
)
74+
val pk = Utils.parseHexKeypair(
75+
"313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910",
76+
"f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70"
77+
)
78+
val tx = Transaction(Some(
79+
Payload(
80+
Some(ReducedPayload(Seq(command), "admin@test", createdTime, 1))
81+
)
82+
))
83+
// val pload = Utils.createTxOrderedBatch(Seq(tx), pk)
84+
// commandClient.listTorii(TxList(pload)).flatMap { _ =>
85+
commandClient.torii(tx.withSignatures(Seq(Utils.sign(tx.getPayload, pk)))).flatMap { _ =>
86+
Thread.sleep(2000)
87+
commandClient.statusStream(TxStatusRequest(Utils.toHex(Utils.hash(tx.getPayload))))
88+
.runWith(Sink.foreach(println))
89+
.map {
90+
_ => assert(true)
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+

0 commit comments

Comments
 (0)