diff --git a/bindings/bdk-kotlin/jvm/build.gradle b/bindings/bdk-kotlin/jvm/build.gradle index 94f7927..58eefc8 100644 --- a/bindings/bdk-kotlin/jvm/build.gradle +++ b/bindings/bdk-kotlin/jvm/build.gradle @@ -4,6 +4,11 @@ plugins { id 'maven-publish' } +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + test { testLogging { events "PASSED", "SKIPPED", "FAILED", "STANDARD_OUT", "STANDARD_ERROR" @@ -18,7 +23,7 @@ dependencies { api "org.slf4j:slf4j-api:1.7.30" testImplementation "ch.qos.logback:logback-classic:1.2.3" testImplementation "ch.qos.logback:logback-core:1.2.3" - //testImplementation(project(':test-fixtures')) + testImplementation(project(':test-fixtures')) } publishing { @@ -32,8 +37,3 @@ publishing { } } } - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} diff --git a/bindings/bdk-kotlin/jvm/src/test/kotlin/org/bitcoindevkit/bdk/JvmLibTest.kt b/bindings/bdk-kotlin/jvm/src/test/kotlin/org/bitcoindevkit/bdk/JvmLibTest.kt new file mode 100644 index 0000000..ceea526 --- /dev/null +++ b/bindings/bdk-kotlin/jvm/src/test/kotlin/org/bitcoindevkit/bdk/JvmLibTest.kt @@ -0,0 +1,16 @@ +package org.bitcoindevkit.bdk + +import java.nio.file.Files + +/** + * Library test, which will execute on linux host. + * + */ +class JvmLibTest : LibTest() { + + override fun getTestDataDir(): String { + return Files.createTempDirectory("bdk-test").toString() + //return Paths.get(System.getProperty("java.io.tmpdir"), "bdk-test").toString() + } + +} diff --git a/bindings/bdk-kotlin/settings.gradle b/bindings/bdk-kotlin/settings.gradle index ac610be..4c3c912 100644 --- a/bindings/bdk-kotlin/settings.gradle +++ b/bindings/bdk-kotlin/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'bdk-kotlin' -include ':jvm', ':demo' //, ':android', ':test-fixtures' +include ':jvm',':demo',':test-fixtures',':android' diff --git a/bindings/bdk-kotlin/test-fixtures/build.gradle b/bindings/bdk-kotlin/test-fixtures/build.gradle new file mode 100644 index 0000000..44f2c40 --- /dev/null +++ b/bindings/bdk-kotlin/test-fixtures/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id 'java-library' +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +dependencies { + implementation platform('org.jetbrains.kotlin:kotlin-bom') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + + implementation(project(':jvm')) + implementation "junit:junit:4.13.2" + api "org.slf4j:slf4j-api:1.7.30" +} diff --git a/bindings/bdk-kotlin/jvm/src/test/kotlin/uniffi/bdk/LibTest.kt b/bindings/bdk-kotlin/test-fixtures/src/main/kotlin/org/bitcoindevkit/bdk/LibTest.kt similarity index 70% rename from bindings/bdk-kotlin/jvm/src/test/kotlin/uniffi/bdk/LibTest.kt rename to bindings/bdk-kotlin/test-fixtures/src/main/kotlin/org/bitcoindevkit/bdk/LibTest.kt index 6e8c7b1..1ac682f 100644 --- a/bindings/bdk-kotlin/jvm/src/test/kotlin/uniffi/bdk/LibTest.kt +++ b/bindings/bdk-kotlin/test-fixtures/src/main/kotlin/org/bitcoindevkit/bdk/LibTest.kt @@ -1,19 +1,24 @@ -package uniffi.bdk +package org.bitcoindevkit.bdk -import uniffi.bdk.OfflineWallet import org.junit.Assert.* import org.junit.Test - -class LogProgress: BdkProgress { - override fun update(progress: Float, message: String? ) { - println("progress: $progress, message: $message") - } -} +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import uniffi.bdk.* +import java.io.File /** * Library tests which will execute for jvm and android modules. */ -class LibTest { +abstract class LibTest { + + abstract fun getTestDataDir(): String + + fun cleanupTestDataDir(testDataDir: String) { + File(testDataDir).deleteRecursively() + } + + val log: Logger = LoggerFactory.getLogger(LibTest::class.java) val desc = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)" @@ -27,7 +32,7 @@ class LibTest { assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs") } - @Test(expected=BdkException.Descriptor::class) + @Test(expected= BdkException.Descriptor::class) fun invalidDescriptorExceptionIsThrown() { val config = DatabaseConfig.Memory("") OfflineWallet("invalid-descriptor", Network.REGTEST, config) @@ -35,11 +40,13 @@ class LibTest { @Test fun sledWalletNewAddress() { - val config = DatabaseConfig.Sled(SledDbConfiguration("/tmp/testdb", "testdb")) + val testDataDir = getTestDataDir() + val config = DatabaseConfig.Sled(SledDbConfiguration(testDataDir, "testdb")) val wallet = OfflineWallet(desc, Network.REGTEST, config) val address = wallet.getNewAddress() assertNotNull(address) assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs") + cleanupTestDataDir(testDataDir) } @Test @@ -52,6 +59,14 @@ class LibTest { assertEquals(network, Network.TESTNET) } + class LogProgress: BdkProgress { + val log: Logger = LoggerFactory.getLogger(LibTest::class.java) + + override fun update(progress: Float, message: String?) { + log.debug("Syncing...") + } + } + @Test fun onlineWalletSyncGetBalance() { val db = DatabaseConfig.Memory("")