From 5bc6483fc4a7ff769c418cdee174669a36e7aa54 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 26 Jun 2024 16:02:05 -0400 Subject: [PATCH] test: add offline tests for wallet new_or_load method --- .../bitcoindevkit/OfflinePersistenceTest.kt | 44 ++++++++++++++++++ ...re_existing_wallet_persistence_test.sqlite | Bin 0 -> 57344 bytes .../OfflinePersistenceTests.swift | 41 ++++++++++++++++ ...re_existing_wallet_persistence_test.sqlite | Bin 0 -> 57344 bytes 4 files changed, 85 insertions(+) create mode 100644 bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt create mode 100644 bdk-jvm/lib/src/test/resources/pre_existing_wallet_persistence_test.sqlite create mode 100644 bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift create mode 100644 bdk-swift/pre_existing_wallet_persistence_test.sqlite diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt new file mode 100644 index 00000000..dd156beb --- /dev/null +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt @@ -0,0 +1,44 @@ +package org.bitcoindevkit + +import kotlin.test.Test +import kotlin.test.assertEquals + +class OfflinePersistenceTest { + private val persistenceFilePath = run { + val currentDirectory = System.getProperty("user.dir") + val dbFileName = "pre_existing_wallet_persistence_test.sqlite" + "$currentDirectory/src/test/resources/$dbFileName" + } + private val descriptor: Descriptor = Descriptor( + "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", + Network.SIGNET + ) + private val changeDescriptor: Descriptor = Descriptor( + "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + Network.SIGNET + ) + + @Test + fun testPersistence() { + val sqliteStore: SqliteStore = SqliteStore(persistenceFilePath) + val initialChangeSet: ChangeSet? = sqliteStore.read() + assert(initialChangeSet != null) { "ChangeSet should not be null after loading a valid database" } + val wallet: Wallet = Wallet.newOrLoad( + descriptor, + changeDescriptor, + initialChangeSet, + Network.SIGNET, + ) + val addressInfo: AddressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL) + println("Address: $addressInfo") + + assertEquals( + expected = 7u, + actual = addressInfo.index, + ) + assertEquals( + expected = "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2", + actual = addressInfo.address.toString(), + ) + } +} diff --git a/bdk-jvm/lib/src/test/resources/pre_existing_wallet_persistence_test.sqlite b/bdk-jvm/lib/src/test/resources/pre_existing_wallet_persistence_test.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..f4eef74526dce7dd2e3499e08149ea7dbaae1442 GIT binary patch literal 57344 zcmeI(%}?8A90zba(7XUnK-y$g6nLagBU#fXP9QIbN(*2hY8q$=D=NmZ*IHceVjlXln+yG}h;LaNkFnl#OEULZhLq#d@lsgrT z%(e0-oaH{l^$U#UYm3ct$2@2LgWES>;)c0T2j&J2`h|g4I(;1V5P$##AOHafKmY;| z_>Tpu?+zIFu`%{Tiz3CdRLaSzd@-g}S_N)8A_k%&i3X-ZB5739M6~dOda0yfqGNhJUis?h+HUld*cO*T9dAuzL=sg z!-@&bl7302=ZA;c548MpRN2lKGmTSETXu~~HMyL$LF*wm9?<5nXbE5K(er`fPEjDppxRI0HwOU(zYIqW#~a;)V~M*YJE0SG_< z0uX=z1Rwwb2tWV=5P-n>6X;=etg$}-f6iE*pT7i=5d36s`hNv|Dg>)e{xSc5xkm)DhX4d1009U<00Izz00bZaf%7O}>bYpD&;L1# zkI`}W81A0Aa2_*7P7r_q1Rwwb2tWV=5P$##x=f%t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