-
Notifications
You must be signed in to change notification settings - Fork 69
Testing the new potential kyoto client #965
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| plugins { | ||
| id("com.android.library").version("8.13.2").apply(false) | ||
| id("org.jetbrains.kotlin.android").version("2.1.10").apply(false) | ||
| id("org.jetbrains.kotlin.android").version("2.3.0").apply(false) | ||
| id("org.jetbrains.dokka").version("2.1.0").apply(false) | ||
| id("com.vanniktech.maven.publish").version("0.36.0").apply(false) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.bitcoindevkit | ||
|
|
||
| import kotlin.test.Test | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import kotlinx.coroutines.delay | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.runner.RunWith | ||
| // import org.kotlinbitcointools.regtesttoolbox.regenv.RegEnv | ||
| import java.io.File | ||
| import kotlin.time.Duration.Companion.seconds | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class CbfSyncTest { | ||
| private val conn: Persister = Persister.newInMemory() | ||
|
|
||
| private val kyotoDataDir: String by lazy { | ||
| val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
| val dir = File(context.filesDir, "kyoto_test_data") | ||
| dir.mkdirs() | ||
| dir.absolutePath | ||
| } | ||
|
|
||
| @Test | ||
| fun syncWithKyotoClient() { | ||
| runBlocking { | ||
| // println("Hello, Compact Block Filters!") | ||
| // val regtestEnv = RegEnv.connectTo(walletName = "faucet", username = "regtest", password = "password") | ||
|
|
||
| val wallet: Wallet = Wallet.createSingle( | ||
| descriptor = BIP86_DESCRIPTOR, | ||
| network = Network.REGTEST, | ||
| persister = conn | ||
| ) | ||
| val newAddress = wallet.revealNextAddress(KeychainKind.EXTERNAL).address | ||
| println("New address: $newAddress") | ||
| delay(2.seconds) | ||
|
|
||
| // regtestEnv.send(newAddress.toString(), 0.12345678, 2.0) | ||
| // regtestEnv.mine(2) | ||
|
|
||
| val ip: IpAddress = IpAddress.fromIpv4(10u, 0u, 2u, 2u) | ||
| val peer1: Peer = Peer(ip, 18444u, false) | ||
| val peers: List<Peer> = listOf(peer1) | ||
| val node = CbfBuilder() | ||
| .peers(peers) | ||
| .connections(1u) | ||
| .scanType(ScanType.Sync) | ||
| .dataDir(kyotoDataDir) | ||
| .build(wallet) | ||
|
|
||
| println("Test is complete") | ||
| val client = node.start() | ||
|
|
||
| val warningJob = launch { | ||
| try { | ||
| while (true) println("Warning: ${client.nextWarning()}") | ||
| } catch (e: CbfException) { println("Warning channel closed: $e") } | ||
| } | ||
| val infoJob = launch { | ||
| try { | ||
| while (true) println("Info: ${client.nextInfo()}") | ||
| } catch (e: CbfException) { println("Info channel closed: $e") } | ||
| } | ||
|
|
||
| val update: Update = client.update() | ||
| delay(8.seconds) | ||
| wallet.applyUpdate(update) | ||
|
|
||
| val balance = wallet.balance().total.toSat() | ||
| assert(balance > 0uL) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use a real test assertion and reenable the funding/mine steps, I think the wallet is never funded and the final assert(...) may be skipped so the test can pass without validating Kyoto sync? Maybe im wrong though |
||
|
|
||
| warningJob.cancel() | ||
| infoJob.cancel() | ||
| client.shutdown() | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use a regtest descriptor here? wondering because from what I see BIP86_DESCRIPTOR is created with Network.TESTNET but the wallet is initialized with Network.REGTEST