From 8861b9cbdd3b1f743e32d85b9fc9fcdfbedb1458 Mon Sep 17 00:00:00 2001 From: Matthijs van den Bos Date: Wed, 9 Nov 2022 11:14:16 +0100 Subject: [PATCH] Always publish ZKFlow locally for sample --- .ci/azure-pipelines-scheduled.yml | 2 +- .ci/azure-pipelines.yml | 2 +- .github/workflows/on-push.yml | 2 +- .github/workflows/on-tag-publish.yml | 49 ----------------- .github/workflows/scheduled-all.yml | 2 +- README.md | 52 ++++++++----------- bin/pre-push-checks | 2 +- sample-zkdapp/bin/run_issuer_for_rpc.sh | 2 + sample-zkdapp/bin/run_notary_for_rpc.sh | 2 + sample-zkdapp/build.gradle.kts | 22 +++++++- sample-zkdapp/config/test/log4j2.xml | 42 --------------- .../config/test/logging-test.properties | 9 ---- 12 files changed, 52 insertions(+), 136 deletions(-) delete mode 100644 .github/workflows/on-tag-publish.yml delete mode 100644 sample-zkdapp/config/test/log4j2.xml delete mode 100644 sample-zkdapp/config/test/logging-test.properties diff --git a/.ci/azure-pipelines-scheduled.yml b/.ci/azure-pipelines-scheduled.yml index af3d318c8..0b960a9bb 100644 --- a/.ci/azure-pipelines-scheduled.yml +++ b/.ci/azure-pipelines-scheduled.yml @@ -47,7 +47,7 @@ steps: publishJUnitResults: true testResultsFiles: '**/TEST-*.xml' # codeCoverageToolOption: JaCoCo # Broken because it expects hardcoded 'build.gradle' instead of 'build.gradle.kts' - tasks: 'clean cleanTest check test testReport jacocoRootReport checkLicense' + tasks: 'clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain' options: '--no-build-cache --rerun-tasks --no-daemon --no-parallel' env: GITHUB_USERNAME: $(github.username) diff --git a/.ci/azure-pipelines.yml b/.ci/azure-pipelines.yml index c53fef6e2..81d2a471c 100644 --- a/.ci/azure-pipelines.yml +++ b/.ci/azure-pipelines.yml @@ -55,7 +55,7 @@ steps: jdkArchitectureOption: 'x64' publishJUnitResults: true testResultsFiles: '**/TEST-*.xml' - tasks: 'clean cleanTest check test testReport jacocoRootReport checkLicense' + tasks: 'clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain' # options: '--stacktrace --info --build-cache' options: '--no-build-cache --rerun-tasks --no-daemon --no-parallel --stacktrace --info ' env: diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index f0e094d3e..4fb6c047a 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -55,7 +55,7 @@ jobs: echo "$GITHUB_WORKSPACE/zinc-linux/" >> $GITHUB_PATH - name: Build with Gradle - run: ./gradlew clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain publishToMavenLocal --no-build-cache --rerun-tasks --no-daemon --no-parallel --stacktrace --info + run: ./gradlew clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain --no-build-cache --rerun-tasks --no-daemon --no-parallel --stacktrace --info env: GITHUB_USERNAME: ${{ github.actor }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/on-tag-publish.yml b/.github/workflows/on-tag-publish.yml deleted file mode 100644 index e656ebe26..000000000 --- a/.github/workflows/on-tag-publish.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Publish artifacts on tag - -on: - push: - tags: - - 'release/**' - workflow_dispatch: - -jobs: - publish: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Git info - id: git_info - run: | - echo ::set-output name=RELEASE_VERSION::${GITHUB_REF#refs/tags/release/} - - - name: Set up JDK 8.0.232 - uses: actions/setup-java@v1 - with: - java-version: 8.0.232 - java-package: jdk - - # Build cache - - name: Cache Gradle Cache - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}-${{ hashFiles('**/gradle.properties') }} - # An ordered list of keys to use for restoring the cache if no cache hit occurred for key - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Cache gradle wrapper - uses: actions/cache@v2 - with: - path: ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} - - - - name: Publish to GitHub Packages (should never fail) - run: ./gradlew -Pversion=$GIT_RELEASE_VERSION publish --continue --build-cache --parallel - env: - GIT_RELEASE_VERSION: ${{ steps.git_info.outputs.RELEASE_VERSION }} - GITHUB_USERNAME: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/scheduled-all.yml b/.github/workflows/scheduled-all.yml index 9088909b4..15b240810 100644 --- a/.github/workflows/scheduled-all.yml +++ b/.github/workflows/scheduled-all.yml @@ -55,7 +55,7 @@ jobs: echo "$GITHUB_WORKSPACE/zinc-linux/" >> $GITHUB_PATH - name: Build with Gradle - run: ./gradlew clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain publishToMavenLocal --no-build-cache --rerun-tasks --no-daemon --no-parallel --stacktrace --info + run: ./gradlew clean cleanTest check test testReport jacocoRootReport checkLicense spotBugsMain --no-build-cache --rerun-tasks --no-daemon --no-parallel --stacktrace --info env: GITHUB_USERNAME: ${{ github.actor }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index e66aa75b3..bb91c1af2 100644 --- a/README.md +++ b/README.md @@ -19,35 +19,47 @@ Features: To learn more about ZKFlow internals, there is a [docs](docs) directory in this repo. In addition to the [ZKFLow white paper](docs/ZKFlow_whitepaper.pdf), it contains technical documentation in Markdown and PDF format. There is also plenty of documentation throughout the code itself, explaining logic or rationale. Finally, the many test cases will also explain a lot about expected behaviour. -## Testing ZKFlow with the sample CorDapp or with your own CorDapp +## Running the sample ZKDapp -The ZKFlow jars are currently not deployed to one of the Maven/Gradle repositories. This means it can not be used directly by CorDapps. Instead, run the tests for ZKFlow and the `sample-zkdapp` to see it in action. +The sample ZKDapp demonstrates how a basic token contract can be adapted to work with ZKFlow. The contract tests and flow tests show the expected behaviour. Please make sure you have satisfied all [prerequisites](#prerequisites) before you execute the following: ```bash -$ cd sample-zkdapp +$ cd zkflow/sample-zkdapp $ ./gradlew test ``` -If you want to test ZKFlow with your own CorDapp, please do the following: +## Running your own CorDapp with ZKFlow -* Copy you CorDapp to the zkflow project, similar to `sample-zkdapp` -* Add `includeBuild("..")` to your `settings.gradle`. This will give your CorDapp access to undeployed ZKFlow artifacts -* Enable the ZKFlow Gradle plugin on your CorDapp in your `build.gradle.kts`. Note that it needs no version because of `includeBuild("..")`: +> [i] This assumes you use the Kotlin DSL for your Gradle build files. If you do not, change accordingly for the Groovy DSL. The changes should be identical except for syntax. + +The ZKFlow jars are currently not deployed to one of the public Maven/Gradle repositories. If you want to test ZKFlow with your own CorDapp, please make the following changes to your build file: + +* Make sure that ZKFlow is published to your local Maven repository by running `./gradlew publishToMavenLocal` in the ZKFlow directory. +* Add the `mavenLocal()` repository to your repositories for Gradle plugins (probably in the `pluginManagement` block in your `settings.gradle.kts`) and to your repositories for normal Gradle dependencies in your `build.gradle.kts`. +* Enable the ZKFlow Gradle plugin on your CorDapp in your `build.gradle.kts`. ```kotlin plugins { - id("com.ing.zkflow.gradle-plugin") + id("com.ing.zkflow.gradle-plugin") version "1.0-SNAPSHOT" } ``` * To be able to use ZKFlow's contract test DSL and other convenience functions, add `testImplementation("com.ing.zkflow:test-utils:1.0-SNAPSHOT")` to your `dependencies` block in `build.gradle.kts`. -* Finally, adapt your contracts, states, commands, contract tests and flow tests to work with ZKFlow. You can inspect `sample-zkdapp` to see how you can make those adaptations. Please note that some significant changes to your state class definitions may be required. + +Not you are ready to adapt your contracts, states, commands, contract tests and flow tests to work with ZKFlow. You can inspect `sample-zkdapp` to see how you can make those adaptations. Please note that some significant changes to your state class definitions may be required. + +Not recommended, but feel free to run it immediately as-is and let ZKFlow tell you what should be added to your classes. + +## Troubleshooting the sample ZKDapp or your own ZKDapp + +Build issues: +- `java.lang.IllegalArgumentException: Cannot find circuit manifest`: This should not happen during normal development flow, but it can be solved by running `./gradlew generateZincCircuits --rerun-tasks` in your ZKDapp. ## Running ZKFlow tests If you want to make changes to ZKFlow itself, you need to be able to run its tests. -This is as simple as running `./gradlew test` in the ZKFlow root directlty. It will run all tests, including integration tests. +This is as simple as running `./gradlew test` in the ZKFlow root directly. It will run all tests, including integration tests. Please make sure you have satisfied all [prerequisites](#prerequisites) before running the tests. ## Prerequisites for running ZKFlow @@ -71,26 +83,6 @@ $ cargo b --release Built binaries will be stored in `./target/release`. Move the `zargo`, `znc` and `zvm` binaries to a directory you prefer and add it to your systems PATH. `/usr/local/bin` has been known to work. Then you can delete sources. -#### Zinc on internal Azure Pipelines - -If you make changes to Zinc and create a new tag, please ensure that the [copy of the binaries](./.ci/lib/zinc-linux.tar.gz) in for Azure Pipelines is updated to be that version. Please note that these binaries should be compiled on/for linux, so they can run on the Azure Pipelines agents. - -For GitHub Actions, this is not required, as that build automatically downloads and installs the correct Zinc binaries. - -### Gradle - -Typically, Gradle does not require any specific changes, but you might encounter the following error during the build (path can be different): - -```bash -Caused by: java.io.IOException: Cannot run program "zargo" (in directory "/Users/mq23re/Developer/zk-notary/prover/circuits/create"): error=2, No such file or directory -``` - -To fix it, run the command below from the project directory. It will stop daemon, thus it will clear cache, which can help to resolve the issue. - -```bash -./gradlew --stop -``` - ## Contributing to ZKFlow If you want to make changes to ZKFlow, great! We welcome pull requests at any time. If you decide to create a PR, please keep the [contributing guidelines](CONTRIBUTING.md) in mind. \ No newline at end of file diff --git a/bin/pre-push-checks b/bin/pre-push-checks index 49de4e8e8..ee9236a74 100755 --- a/bin/pre-push-checks +++ b/bin/pre-push-checks @@ -36,7 +36,7 @@ fi fail_all_if_failed \ "Build with Gradle" \ - "./gradlew $clean check test testReport jacocoRootReport checkLicense spotBugsMain publishToMavenLocal --stacktrace" + "./gradlew $clean check test testReport jacocoRootReport checkLicense spotBugsMain --stacktrace --info" fail_all_if_failed \ "sample-zkdapp - Build with Gradle" \ diff --git a/sample-zkdapp/bin/run_issuer_for_rpc.sh b/sample-zkdapp/bin/run_issuer_for_rpc.sh index 9f2168d20..65de4358a 100755 --- a/sample-zkdapp/bin/run_issuer_for_rpc.sh +++ b/sample-zkdapp/bin/run_issuer_for_rpc.sh @@ -1,3 +1,5 @@ +# This script assumes that ./gradlew deployNodes was run first. + cd build/nodes/Issuer || exit nohup java -Dexperimental.corda.customSerializationScheme=com.ing.zkflow.common.serialization.BFLSerializationScheme \ diff --git a/sample-zkdapp/bin/run_notary_for_rpc.sh b/sample-zkdapp/bin/run_notary_for_rpc.sh index 5a5173efd..19e2f3c0c 100755 --- a/sample-zkdapp/bin/run_notary_for_rpc.sh +++ b/sample-zkdapp/bin/run_notary_for_rpc.sh @@ -1,3 +1,5 @@ +# This script assumes that ./gradlew deployNodes was run first. + cd build/nodes/ZKNotary || exit nohup java -Dexperimental.corda.customSerializationScheme=com.ing.zkflow.common.serialization.BFLSerializationScheme \ diff --git a/sample-zkdapp/build.gradle.kts b/sample-zkdapp/build.gradle.kts index 79c36034b..c548c6598 100644 --- a/sample-zkdapp/build.gradle.kts +++ b/sample-zkdapp/build.gradle.kts @@ -1,4 +1,13 @@ buildscript { + // Please note that this is only required because the ZKFlow artifacts are currently not published to a public maven repository. + // For that reason, we always ensure that the latest version of ZKFlow is published locally before running the CorDapp build. + println("ENSURING LATEST ZKFLOW IS PUBLISHED TO LOCAL MAVEN REPOSITORY...") + exec { + workingDir = projectDir.parentFile + executable = "./gradlew" + args("publishToMavenLocal") + } + extra.apply{ set("corda_release_version", "4.8.5") } @@ -113,4 +122,15 @@ tasks.register("deployNodes") { } rpcUsers = listOf(mapOf( Pair("user", "user1"), Pair("password", "test"), Pair("permissions", listOf("ALL")))) } -} \ No newline at end of file +} + +// tasks.withType() { +// doFirst { +// println("ENSURING LATEST ZKFLOW IS PUBLISHED TO LOCAL MAVEN REPOSITORY...") +// exec { +// workingDir = projectDir.parentFile +// executable = "./gradlew" +// args("publishToMavenLocal") +// } +// } +// } \ No newline at end of file diff --git a/sample-zkdapp/config/test/log4j2.xml b/sample-zkdapp/config/test/log4j2.xml deleted file mode 100644 index ad0b76180..000000000 --- a/sample-zkdapp/config/test/log4j2.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - %highlight{[%level{length=1}] %-5r %-0.50c{1} - %msg}{TRACE=dim white,INFO=normal}%n - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sample-zkdapp/config/test/logging-test.properties b/sample-zkdapp/config/test/logging-test.properties deleted file mode 100644 index 114ce700b..000000000 --- a/sample-zkdapp/config/test/logging-test.properties +++ /dev/null @@ -1,9 +0,0 @@ -# This file determines for the standard java.util.logging how and what is logged to the console -handlers=java.util.logging.ConsoleHandler - -# Base logging threshold -.level=INFO - -# Threshold for specific packages/classes -org.junit.platform.launcher.level=WARNING -org.junit.jupiter.engine.config.level=WARNING