Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/iroha2-dev' into update/MVP
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jan 31, 2025
2 parents e170d5b + a3397a7 commit 8556492
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/iroha2-allure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ on:
ALLURE_USERNAME:
description: "ALLURE_USERNAME service parameter. Leave blank"
required: false
repository_dispatch:
types: [allure-upload-trigger]

env:
IROHA_IMAGE_TAG: "dev"
ALLURE_RESULTS: "${{ github.workspace }}/modules/client/build/allure-results"
ALLURE_JOB_RUN_ID: ${{ github.event.inputs.ALLURE_JOB_RUN_ID }}

Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/iroha2-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ name: Iroha2-java pull requests workflow
on:
pull_request:
branches: [ iroha2-dev, iroha2-main ]

jobs:
build:
runs-on: self-hosted

runs-on: [self-hosted, Linux, iroha2]
env:
IROHA_IMAGE_TAG: "2.0.0-pre-rc.22.2" # Place "dev" to run on the last iroha
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -27,7 +29,7 @@ jobs:
run: ./gradlew build --info
- name: Upload build reports
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-reports
path: /home/runner/work/iroha-java/iroha-java/**/index.html
Expand Down
29 changes: 24 additions & 5 deletions .github/workflows/iroha2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name: Iroha2-java main branch workflow
on:
push:
branches: [ iroha2-dev, iroha2-main ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

runs-on: [self-hosted, Linux, iroha2]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -23,8 +24,26 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew build
- name: Build with Gradle & Sonarqube analysis
run: |
./gradlew build
./gradlew jacocoTestReport
./gradlew sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }}
- name: DefectDojo
if: always()
uses: C4tWithShell/[email protected]
with:
token: ${{ secrets.DEFECTOJO_TOKEN }}
defectdojo_url: ${{ secrets.DEFECTOJO_URL }}
product_type: iroha2
engagement: ${{ github.ref_name }}
tools: "SonarQube API Import,Github Vulnerability Scan"
sonar_projectKey: iroha2-java
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
product: ${{ github.repository }}
environment: Test
reports: '{"Github Vulnerability Scan": "github.json"}'
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
Expand Down
37 changes: 33 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ plugins {
id 'org.jmailen.kotlinter' version "$kotlinLinterVer"
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.sonarqube' version "5.1.0.4882"
id 'jacoco'
}

allprojects {
Expand All @@ -30,6 +32,7 @@ subprojects {
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jmailen.kotlinter'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'

publishing {
publications {
Expand All @@ -53,10 +56,6 @@ subprojects {
group = 'jp.co.soramitsu.iroha2-java'
version = 'git rev-parse --short HEAD'.execute().text.trim()

test {
useJUnitPlatform()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
Expand Down Expand Up @@ -96,6 +95,36 @@ subprojects {
// uncomment to produce shadowJar build by default
// it is disabled by default to publish original version by CI, not a fat jar
tasks.shadowJar.enabled = false

test {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
}
}

plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}

sonar {
properties {
property "sonar.projectKey", "iroha-java"
property "sonar.host.url", "https://sonar.katana.soramitsu.co.jp"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.projectName", "${project.group}:${rootProject.name}.${project.name}"
property "sonar.sources", "${project.projectDir}/src/main/kotlin"
// exclude projects with no tests
if (project.name != "codegen" && project.name != "model" && project.name != "tutorial") {
property "sonar.tests", "${project.projectDir}/src/test"
}
property "sonar.java.test.binaries", "${project.projectDir}/build/test-results/test/binary"
property "sonar.junit.reportPaths", "${project.projectDir}/build/test-results/test/"
}
}
}

task allShadowJars {
Expand Down
21 changes: 21 additions & 0 deletions examples/tutorial/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
val ktorVer = project.properties["ktorVer"] as String

dependencies {
implementation(project(":admin-client"))

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
implementation("io.ktor:ktor-client-logging:$ktorVer")
}

tasks.jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
mustRunAfter(":test-tools:jacocoTestReport")
}

tasks.jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
mustRunAfter(":test-tools:jacocoTestReport")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun main(): Unit = runBlocking {
"CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03",
"CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53",
)
val client = AdminIroha2Client(listOf(URI(apiUrl).toURL()), chainId, admin, adminKeyPair, log = true)
val client = AdminIroha2Client(listOf(URI(apiUrl).toURL()), chainId, admin, adminKeyPair)
val query = Query(client, admin, adminKeyPair)
query.findAllDomains()
.also { println("ALL DOMAINS: ${it.map { d -> d.id.asString() }}") }
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ testContainersVer=1.20.3
# logging
logbackVer=1.5.12
org.gradle.jvmargs=-XX:MetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
systemProp.sonar.host.url=https://sonar.katana.soramitsu.co.jp
1 change: 1 addition & 0 deletions modules/admin-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies {

implementation "io.ktor:ktor-client-core:$ktorVer"
implementation "io.ktor:ktor-client-cio:$ktorVer"
implementation "io.ktor:ktor-client-logging:$ktorVer"

testApi project(":test-tools")
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.iroha2

import io.ktor.client.plugins.logging.LogLevel
import jp.co.soramitsu.iroha2.generated.AccountId
import kotlinx.coroutines.future.future
import java.net.URL
Expand All @@ -15,9 +16,9 @@ class AdminIroha2AsyncClient @JvmOverloads constructor(
override val chain: UUID,
override val authority: AccountId,
override val keyPair: KeyPair,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
log: Boolean = false,
) : AdminIroha2Client(apiURL, chain, authority, keyPair, credentials, log) {
) : AdminIroha2Client(apiURL, chain, authority, keyPair, credentials, httpLogLevel) {

/**
* Send health check request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jp.co.soramitsu.iroha2

import io.ktor.client.call.body
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.request.get
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
Expand All @@ -23,9 +24,9 @@ open class AdminIroha2Client(
override val authority: AccountId,
override val keyPair: KeyPair,
credentials: String? = null,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
private val balancingHealthCheck: Boolean = true,
) : Iroha2Client(apiURL, chain, authority, keyPair, credentials, log) {
) : Iroha2Client(apiURL, chain, authority, keyPair, credentials, httpLogLevel) {

/**
* Send metrics request
Expand Down
4 changes: 4 additions & 0 deletions modules/block/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ dependencies {

testImplementation "com.google.crypto.tink:tink:$googleTinkVer"
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
}
5 changes: 5 additions & 0 deletions modules/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ dependencies {
testImplementation("io.qameta.allure:allure-testng:2.29.0")
testImplementation "org.testcontainers:testcontainers:$testContainersVer"
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.iroha2.client

import io.ktor.client.plugins.logging.LogLevel
import jp.co.soramitsu.iroha2.generated.AccountId
import jp.co.soramitsu.iroha2.generated.SignedTransaction
import jp.co.soramitsu.iroha2.query.QueryAndExtractor
Expand All @@ -21,11 +22,11 @@ class Iroha2AsyncClient @JvmOverloads constructor(
override val chain: UUID,
override val authority: AccountId,
override val keyPair: KeyPair,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
log: Boolean = false,
eventReadTimeoutInMills: Long = 250,
eventReadMaxAttempts: Int = 10,
) : Iroha2Client(apiURL, chain, authority, keyPair, credentials, log, eventReadTimeoutInMills, eventReadMaxAttempts) {
) : Iroha2Client(apiURL, chain, authority, keyPair, credentials, httpLogLevel, eventReadTimeoutInMills, eventReadMaxAttempts) {

/**
* Send a request to Iroha2 and extract payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.client.plugins.websocket.webSocket
Expand Down Expand Up @@ -89,7 +90,7 @@ open class Iroha2Client(
open val authority: AccountId,
open val keyPair: KeyPair,
open val credentials: String? = null,
open val log: Boolean = true,
open val httpLogLevel: LogLevel = LogLevel.NONE,
open val eventReadTimeoutInMills: Long = 250,
open val eventReadMaxAttempts: Int = 10,
override val coroutineContext: CoroutineContext = Dispatchers.IO + SupervisorJob(),
Expand All @@ -114,8 +115,8 @@ open class Iroha2Client(
open val client by lazy {
HttpClient(CIO) {
expectSuccess = true
if (log) {
install(Logging)
install(Logging) {
level = httpLogLevel
}
install(WebSockets)
install(ContentNegotiation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExampleTest {
this.genesis = DefaultGenesis()
}.also { it.start() }

val client = Iroha2Client(listOf(container.getApiUrl()), container.config.chain, ALICE_ACCOUNT_ID, ALICE_KEYPAIR, log = true)
val client = Iroha2Client(listOf(container.getApiUrl()), container.config.chain, ALICE_ACCOUNT_ID, ALICE_KEYPAIR)

val newAssetDefinitionId = "new_asset_definition#wonderland".asAssetDefinitionId()
client.submit(Register.assetDefinition(newAssetDefinitionId, AssetType.Store())).also { d ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GenesisTest : IrohaTest<Iroha2Client>() {
this.genesisPath = path
}.also { it.start() }

val client = Iroha2Client(listOf(container.getApiUrl()), container.config.chain, ALICE_ACCOUNT_ID, ALICE_KEYPAIR, log = true)
val client = Iroha2Client(listOf(container.getApiUrl()), container.config.chain, ALICE_ACCOUNT_ID, ALICE_KEYPAIR)
client.checkAliceAndBobExists()
}

Expand Down
6 changes: 6 additions & 0 deletions modules/codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ task generate(type: JavaExec) {
args "schemaFileName=schema.json"
finalizedBy ':model:formatKotlin'
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
}
7 changes: 7 additions & 0 deletions modules/model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ dependencies {
implementation "org.bouncycastle:bcprov-jdk15on:$bouncyCastleVer"
api "net.i2p.crypto:eddsa:$i2pCryptoEddsa"
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
}
9 changes: 9 additions & 0 deletions modules/test-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies {

implementation "org.testcontainers:testcontainers:$testContainersVer"

implementation "io.ktor:ktor-client-logging:$ktorVer"
implementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVer"
implementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVer"
Expand All @@ -17,3 +18,11 @@ dependencies {

testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ open class IrohaContainer : GenericContainer<IrohaContainer> {
private fun String.readStatusBlocks() = JSON_SERDE.readTree(this).get("blocks")?.doubleValue()

companion object {
private fun IrohaConfig.getFullImageName() = when (this.imageTag.contains("sha256")) {
true -> "${this.imageName}@${this.imageTag}"
false -> "${this.imageName}:${this.imageTag}"
}.let { DockerImageName.parse(it) }
private fun IrohaConfig.getFullImageName(): DockerImageName {
val imageTag = System.getenv("IROHA_IMAGE_TAG") ?: DEFAULT_IMAGE_TAG
return when (imageTag.contains("sha256")) {
true -> "${this.imageName}@$imageTag"
false -> "${this.imageName}:$imageTag"
}.let { DockerImageName.parse(it) }
}

const val NETWORK_ALIAS = "iroha"
const val DEFAULT_IMAGE_TAG = "dev"
Expand Down
Loading

0 comments on commit 8556492

Please sign in to comment.