|
| 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