Add test of sync callbacks#1022
Conversation
|
Just putting this here to remember: our current implementation of the callback for sync is not perfect, because if you just want to know how many scripts are being synced, you need to do a bit of workaround to do it instead of just pulling the data out of the type. This is not an issue at the ffi layer but the Rust layer. Issue here: bitcoindevkit/bdk#2220. Currently logging the number of scripts being synced for Tatooine with this (works but is clearly not great). class SyncCallback : SyncScriptInspector {
private val logger = KotlinLogging.logger {}
var totalSynced = 0
// On the first run of the callback, log the number of scripts that will be inspected.
override fun inspect(script: Script, total: ULong) {
if (totalSynced == 0) logger.info { "Syncing $total scripts in this sync" }
totalSynced++
}
}Note that this triggers only once the sync is started, and so the number of scripts is unknown until the sync starts. |
1a9f569 to
11bb5e5
Compare
| .inspectSpks(SyncCallback()) | ||
| .build() | ||
|
|
||
| electrumClient.sync( |
There was a problem hiding this comment.
Can we retain the callback instance and assert what it observed after sync/fullScan? Right now these tests pass even if the callback is never called.
There was a problem hiding this comment.
Yeah it occured to me after I pushed that this is not actually testing anything yet so I'll add at least an assertion or two on those.
11bb5e5 to
b547637
Compare
b547637 to
83c5866
Compare
This PR adds 2 tests showcasing the use of the sync and full_scan inspector callbacks.
Documentation
bdk_walletbitcoinuniffiChangelog
No changelog.
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*label