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

Migrating SDK examples repo into multi-module project structure #62

Merged
merged 59 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b59c1dc
Setting up multi-module project structure
lealobanov Jul 10, 2024
cadd0d6
Setting up multi-module project structure
lealobanov Jul 10, 2024
36d1954
Updates to GH actions workflows
lealobanov Jul 12, 2024
3e3e9a5
Linting kotlin-example
lealobanov Jul 12, 2024
56bc4bc
Debugging GH actions
lealobanov Jul 12, 2024
e15455a
Debugging GH actions
lealobanov Jul 12, 2024
9073a9f
Debugging GH actions
lealobanov Jul 13, 2024
c1195e6
Debugging GH actions
lealobanov Jul 13, 2024
78b9ff4
Debugging GH actions
lealobanov Jul 13, 2024
efde813
Debugging GH actions
lealobanov Jul 13, 2024
cc41ae5
Debugging GH actions
lealobanov Jul 13, 2024
ab2ec53
Debugging GH actions
lealobanov Jul 13, 2024
7889700
Debugging GH actions
lealobanov Jul 13, 2024
b51bd0a
Debugging GH actions
lealobanov Jul 13, 2024
269900f
Debugging GH actions
lealobanov Jul 13, 2024
2edee7e
Debugging GH actions
lealobanov Jul 13, 2024
7d420d8
Debugging GH actions
lealobanov Jul 13, 2024
a30ba90
Setting up java-example module
lealobanov Jul 13, 2024
44641ed
Setting up java-example module
lealobanov Jul 13, 2024
b769cd9
Functional flow.json
lealobanov Jul 13, 2024
1521184
Create GH action for java examples
lealobanov Jul 13, 2024
27214db
Fix java example tests
lealobanov Jul 16, 2024
eb77e0e
Fix java example tests
lealobanov Jul 16, 2024
743df77
Fix java example tests
lealobanov Jul 16, 2024
f1f37f6
Fix java example tests
lealobanov Jul 16, 2024
7571804
Fix kotlin example tests
lealobanov Jul 16, 2024
f9fea75
Updating documentation
lealobanov Jul 17, 2024
36d8b11
Updating documentation
lealobanov Jul 17, 2024
93fe558
Updating documentation
lealobanov Jul 17, 2024
ce46f1e
Updating documentation
lealobanov Jul 17, 2024
5dabb4d
Updating documentation
lealobanov Jul 17, 2024
a6b402a
Updating GH actions
lealobanov Jul 17, 2024
ca99408
Updating GH actions
lealobanov Jul 17, 2024
83dd72d
Setting up script loader for Cadence scripts
lealobanov Jul 18, 2024
a01d9f6
Setting up script loader for Cadence scripts
lealobanov Jul 18, 2024
6adb589
Setting up script loader for Cadence scripts
lealobanov Jul 18, 2024
a85db2b
Refactor
lealobanov Jul 18, 2024
f0d2c9d
Refactor
lealobanov Jul 18, 2024
7bd366a
Refactor
lealobanov Jul 18, 2024
e8122ac
Update JSON Cadence tests to load from external snippets
lealobanov Jul 18, 2024
f91293a
Update JSON Cadence tests to load from external snippets
lealobanov Jul 18, 2024
e48867a
Linting
lealobanov Jul 18, 2024
0ede393
Debugging tests
lealobanov Jul 18, 2024
f4238a2
Minor typo
franklywatson Jul 19, 2024
4c47f74
Merge pull request #64 from onflow/cadence-files
lealobanov Jul 19, 2024
0f58b07
Update NOTICE
lealobanov Jul 19, 2024
5ae4a45
Update NOTICE
lealobanov Jul 19, 2024
688473e
Delete NOTICE file
lealobanov Jul 19, 2024
202207e
Delete NOTICE file
lealobanov Jul 19, 2024
ba14488
Refactor class names
lealobanov Jul 19, 2024
880952c
Refactor class names
lealobanov Jul 19, 2024
d37c3e2
Update sdk/src/test/kotlin/org/onflow/flow/sdk/TestUtils.kt
lealobanov Jul 19, 2024
920b506
Update sdk/src/intTest/org/onflow/flow/sdk/IntegrationTestUtils.kt
lealobanov Jul 19, 2024
88089d8
Debugging examples tests
lealobanov Jul 19, 2024
2f48d33
Merge remote-tracking branch 'origin/examples' into examples
lealobanov Jul 19, 2024
c99ff47
Debugging examples tests
lealobanov Jul 19, 2024
7adc8d9
Debugging examples tests, update git ignore
lealobanov Jul 19, 2024
0d66957
Debugging examples tests, update git ignore
lealobanov Jul 19, 2024
36dfe1e
Merge branch 'main' of https://github.com/onflow/flow-jvm-sdk into ex…
lealobanov Jul 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/ci-examples-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build SDK Examples Pull Request
on: pull_request

jobs:
build:
name: Build pull request
runs-on: ubuntu-latest
env:
JAVA_OPTS: -Xmx2g -Dorg.gradle.daemon=false
#services:
# flow-emulator:
# image: gcr.io/flow-container-registry/emulator
# env:
# FLOW_VERBOSE: true
# FLOW_PORT: 3569
# FLOW_INTERVAL: 5s
# FLOW_PERSIST: false
# ports:
# - 3569:3569
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v2
with:
java-version: '21'
java-package: jdk
distribution: 'adopt'

- name: Install flow emulator
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

- name: Make gradle executable
run: chmod +x ./gradlew

- name: Build
id: build
run: ./gradlew --warning-mode all check build -x test -x integrationTest

- name: Start emulator
id: start_emulator
if: ${{ steps.build.outcome == 'success' }}
run: |
nohup flow emulator start -v --persist > flow-emulator.log 2>&1 &

- name: Wait for emulator to start
id: wait_for_emulator
if: ${{ steps.start_emulator.outcome == 'success' }}
run: sleep 15

- name: Run Java Example Unit Tests
id: unit_test
if: ${{ steps.wait_for_emulator.outcome == 'success' }}
run: ./gradlew --no-daemon --max-workers=2 --warning-mode=all :java-example:test -i --continue --stacktrace

- name: Run Kotlin Example Unit Tests
id: unit_test_2
if: ${{ steps.wait_for_emulator.outcome == 'success' }}
run: ./gradlew --no-daemon --max-workers=2 --warning-mode=all :kotlin-example:test -i --continue --stacktrace

- name: Publish SDK Examples Unit Test Results
uses: EnricoMi/[email protected]
if: always()
with:
check_name: "SDK Examples Unit Test Results"
files: "**/test-results/test/**/*.xml"
seconds_between_github_writes: 5
secondary_rate_limit_wait_seconds: 120
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

- name: Make gradle executable
run: chmod +x ./gradlew
run: chmod +x ./sdk/gradlew

- name: Build
id: build
Expand All @@ -60,4 +60,4 @@ jobs:
./gradlew \
-Psigning.key="${{ secrets.FLOW_JVM_SDK_SIGNING_KEY }}" \
-Psigning.password="${{ secrets.FLOW_JVM_SDK_SIGNING_PASSWORD }}" \
publishAndReleaseToMavenCentral --no-configuration-cache
:sdk:publishAndReleaseToMavenCentral --no-configuration-cache
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

- name: Make gradle executable
run: chmod +x ./gradlew
run: chmod +x ./sdk/gradlew

- name: Build
id: build
Expand All @@ -60,4 +60,4 @@ jobs:
./gradlew \
-Psigning.key="${{ secrets.FLOW_JVM_SDK_SIGNING_KEY }}" \
-Psigning.password="${{ secrets.FLOW_JVM_SDK_SIGNING_PASSWORD }}" \
publishToMavenCentral --no-configuration-cache
:sdk:publishToMavenCentral --no-configuration-cache
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

- name: Make gradle executable
run: chmod +x ./gradlew
run: chmod +x ./sdk/gradlew

- name: Build
id: build
Expand All @@ -48,7 +48,7 @@ jobs:
if: ${{ steps.build.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all test --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:test --continue --stacktrace

- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
Expand All @@ -63,7 +63,7 @@ jobs:
if: ${{ steps.unit_test.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all integrationTest --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:integrationTest --continue --stacktrace

- name: Publish Integration Test Results
uses: EnricoMi/[email protected]
Expand All @@ -90,5 +90,5 @@ jobs:
./gradlew \
-Psigning.key="${{ secrets.FLOW_JVM_SDK_SIGNING_KEY }}" \
-Psigning.password="${{ secrets.FLOW_JVM_SDK_SIGNING_PASSWORD }}" \
publishAndReleaseToMavenCentral --no-configuration-cache
:sdk:publishAndReleaseToMavenCentral --no-configuration-cache

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

- name: Make gradle executable
run: chmod +x ./gradlew
run: chmod +x ./sdk/gradlew

- name: Build
id: build
Expand All @@ -49,7 +49,7 @@ jobs:
if: ${{ steps.build.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all test --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:test --continue --stacktrace

- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
Expand All @@ -64,7 +64,7 @@ jobs:
if: ${{ steps.unit_test.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all integrationTest --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:integrationTest --continue --stacktrace

- name: Publish Integration Test Results
uses: EnricoMi/[email protected]
Expand All @@ -91,4 +91,4 @@ jobs:
./gradlew \
-Psigning.key="${{ secrets.FLOW_JVM_SDK_SIGNING_KEY }}" \
-Psigning.password="${{ secrets.FLOW_JVM_SDK_SIGNING_PASSWORD }}" \
publishToMavenCentral --no-configuration-cache
:sdk:publishToMavenCentral --no-configuration-cache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Pull Request
name: Build SDK Pull Request
on: pull_request

jobs:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
if: ${{ steps.build.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all test --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:test --continue --stacktrace

- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
Expand All @@ -58,7 +58,7 @@ jobs:
if: ${{ steps.unit_test.outcome == 'success' }}
run: |
export PATH="$HOME/.local/bin:$PATH"
./gradlew --no-daemon --max-workers=2 --warning-mode=all integrationTest --continue --stacktrace
./gradlew --no-daemon --max-workers=2 --warning-mode=all :sdk:integrationTest --continue --stacktrace

- name: Publish Integration Test Results
uses: EnricoMi/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
.gradle
.idea
gradle.properties
sdk/gradle.properties
flowdb
4 changes: 0 additions & 4 deletions NOTICE

This file was deleted.

160 changes: 8 additions & 152 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,162 +13,18 @@ At the moment, this SDK includes the following features:
- [x] Marshalling & unmarshalling of [JSON-Cadence](https://docs.onflow.org/cadence/json-cadence-spec/)
- [x] DSL for creating, signing, and sending transactions and scripts

## Installation
## Repository modules

Use the configuration below to add this
SDK to your project using Maven or Gradle.
This repository is organized as a multi-module project, consisting of the following modules:

### Maven
### SDK
The core module that includes all the necessary tools and libraries to interact with the Flow blockchain. This module provides the main functionalities such as transaction preparation, signing, and interaction with the Flow Access API.

```xml
<!--
the following repository is required because the trusted data framework
is not available on maven central.
-->
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
### Java Example
This module contains example implementations demonstrating how to use the Flow JVM SDK in a Java application. It includes sample code for various use cases, making it easier for developers to understand and integrate the SDK into their Java projects.

<dependency>
<groupId>org.onflow</groupId>
<artifactId>flow-jvm-sdk</artifactId>
<version>[VERSION HERE]</version>
</dependency>
```

### Gradle

```groovy
repositories {
...
/*
the following repository is required because the trusted data framework
is not available on maven central.
*/
maven { url 'https://jitpack.io' }
}

dependencies {
api("org.onflow:flow-jvm-sdk:[VERSION HERE]")
}
```

### Gradle (with test extensions)

```groovy
plugins {
...
id("java-test-fixtures")
}

repositories {
...
/*
the following repository is required because the trusted data framework
is not available on maven central.
*/
maven { url 'https://jitpack.io' }
}

dependencies {
api("org.onflow:flow-jvm-sdk:[VERSION HERE]")
testFixturesApi(testFixtures("org.onflow:flow-jvm-sdk:[VERSION HERE]"))
}
```

The jitpack.io repository is necessary to access some of the dependencies of this library that are not available on Maven Central.

## Example usage

Check out the [example repository](https://github.com/onflow/flow-java-client-example) for an example
of how to use this SDK in a Java application.

## Integration tests

Tests annotated with `FlowEmulatorTest` depend on the [Flow Emulator](https://github.com/onflow/flow-emulator), which is part of the [Flow CLI](https://github.com/onflow/flow-cli) to be installed on your machine.

The`FlowEmulatorTest` extension may be used by consumers of this library as well to streamline unit tests that interact
with the FLOW blockchian. The `FlowEmulatorTest` extension uses the local flow emulator to prepare the test environment
for unit and integration tests. For example:

Setup dependency on the SDK:
```gradle
plugins {
id("java-test-fixtures")
}

repositories {
/*
the following repository is required because the trusted data framework
is not available on maven central.
*/
maven { url 'https://jitpack.io' }
}

dependencies {
api("org.onflow:flow-jvm-sdk:[VERSION HERE]")

// this allows for using the test extension
testFixturesApi(testFixtures("org.onflow:flow-jvm-sdk:[VERSION HERE]"))
}
```

Write your blockchain tests:
```kotlin
@FlowEmulatorTest
class TransactionTest {

@FlowTestClient
lateinit var accessAPI: FlowAccessApi

@FlowServiceAccountCredentials
lateinit var serviceAccount: TestAccount

@Test
fun `Test something on the emnulator`() {
val result = accessAPI.simpleFlowTransaction(
serviceAccount.flowAddress,
serviceAccount.signer
) {
script {
"""
transaction(publicKey: String) {
prepare(signer: AuthAccount) {
let account = AuthAccount(payer: signer)
account.addPublicKey(publicKey.decodeHex())
}
}
"""
}
arguments {
arg { string(newAccountPublicKey.encoded.bytesToHex()) }
}
}.sendAndWaitForSeal()
.throwOnError()
assertThat(result.status).isEqualTo(FlowTransactionStatus.SEALED)
}

}
```

There are two ways to test using the emulator:

- `@FlowEmulatorProjectTest` - this uses a `flow.json` file that has your configuration in it
- `@FlowEmulatorTest` - this creates a fresh and temporary flow configuration for each test

Also, the following annotations are available in tests as helpers:

- `@FlowTestClient` - used to inject a `FlowAccessApi` or `AsyncFlowAccessApi` into your tests
- `@FlowServiceAccountCredentials` - used to inject a `TestAccount` instance into your tests that contain
the flow service account credentials
- `@FlowTestAccount` - used to automatically create an account in the emulator and inject a `TestAccount` instance
containing the new account's credentials.

See [ProjectTestExtensionsTest](src/test/kotlin/com/nftco/flow/sdk/ProjectTestExtensionsTest.kt) and
[TestExtensionsTest](src/test/kotlin/com/nftco/flow/sdk/TestExtensionsTest.kt) for examples.
### Kotlin Example
Similar to the Java Example module, this module provides sample implementations in Kotlin. It showcases how to leverage the SDK's capabilities in a Kotlin environment.

## Contribute to this SDK

Expand Down
Loading
Loading