Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,25 @@ jobs:
- name: Run Dart tests
run: nix develop -L .#bindings --command just test-dart

kotlin-binding-tests:
name: "Kotlin binding tests"
runs-on: self-hosted
timeout-minutes: 30
needs: pre-commit-checks
steps:
- name: checkout
uses: actions/checkout@v4
- uses: cachix/cachix-action@v16
with:
name: cashudevkit
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
useDaemon: false
continue-on-error: true
- name: Build native library and generate bindings
run: nix develop -L .#bindings --command just binding-kotlin
- name: Run Kotlin tests
run: nix develop -L .#bindings --command just test-kotlin
Comment thread
crodas marked this conversation as resolved.
Comment thread
thesimplekid marked this conversation as resolved.

swift-binding-tests:
name: "Swift binding tests"
runs-on: macos-latest
Expand Down
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ __pycache__
libcdk_ffi*
cdk_ffi.py

# Kotlin bindings
.gradle/
!gradle/wrapper/gradle-wrapper.jar
local.properties
*.iml
*.ipr
*.iws
bin/
gen/
out/
bindings/kotlin/cdk-jvm/src/main/kotlin/uniffi/
bindings/kotlin/cdk-jvm/src/main/resources/*.so
bindings/kotlin/cdk-jvm/src/main/resources/*.dylib

8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"crates/*",
"bindings/dart/rust",
"bindings/swift/rust",
"bindings/kotlin/rust",
]
exclude = [
"fuzz",
Expand Down
50 changes: 0 additions & 50 deletions bindings/dart/generate-bindings.sh

This file was deleted.

29 changes: 0 additions & 29 deletions bindings/dart/rust/rust-toolchain.toml

This file was deleted.

3 changes: 3 additions & 0 deletions bindings/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm") version "1.9.24" apply false
}
57 changes: 57 additions & 0 deletions bindings/kotlin/cdk-jvm/build.gradle.kts
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different then the one we're already using for our bindings.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
plugins {
kotlin("jvm")
`java-library`
`maven-publish`
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}

kotlin {
jvmToolchain(17)
}

dependencies {
implementation("net.java.dev.jna:jna:5.14.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.24")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")

testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
}

sourceSets {
main {
kotlin.srcDirs("src/main/kotlin")
resources.srcDirs("src/main/resources")
}
}

tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
}
systemProperty("junit.jupiter.execution.timeout.default", "60s")
jvmArgs("-Djava.library.path=${project.projectDir}/src/main/resources")
}

tasks.processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.property("GROUP") as String
artifactId = "cdk-jvm"
version = project.property("VERSION_NAME") as String
from(components["java"])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.cashudevkit

import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

class WalletTest {

private lateinit var wallet: Wallet
private lateinit var dbFile: File

@BeforeEach
fun setUp() {
dbFile = File.createTempFile("cdk_test_", ".sqlite")
val mnemonic = generateMnemonic()
wallet = Wallet(
mintUrl = "https://testnut.cashudevkit.org",
unit = CurrencyUnit.Sat,
mnemonic = mnemonic,
store = WalletStore.Sqlite(path = dbFile.absolutePath),
config = WalletConfig(targetProofCount = null),
)
}

@AfterEach
fun tearDown() {
wallet.close()
dbFile.delete()
}

@Test
fun `initial balance is zero`() = runBlocking {
val balance = wallet.totalBalance()
assertEquals(0UL, balance.value)
}

@Test
fun `mint flow`() = runBlocking {
val quote = wallet.mintQuote(
paymentMethod = PaymentMethod.Bolt11,
amount = Amount(value = 100UL),
description = null,
extra = null,
)

assertTrue(quote.id.isNotEmpty())
assertTrue(quote.request.isNotEmpty())

// testnut pays quotes automatically, wait for payment to settle
kotlinx.coroutines.delay(3000)

val proofs = wallet.mint(
quoteId = quote.id,
amountSplitTarget = SplitTarget.None,
spendingConditions = null,
)

assertTrue(proofs.isNotEmpty())

val balance = wallet.totalBalance()
assertEquals(100UL, balance.value)
}
}
7 changes: 7 additions & 0 deletions bindings/kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=true
kotlin.code.style=official

GROUP=org.cashudevkit
VERSION_NAME=0.16.0-rc.2
Binary file added bindings/kotlin/gradle/wrapper/gradle-wrapper.jar
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we gitignore this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like its also committed in cdk-kotlin so maybe we need it.

Binary file not shown.
7 changes: 7 additions & 0 deletions bindings/kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading