mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 22:36:34 +01:00
Actually validate master xpub on startup (#3719)
* Fix bug where we didn't validate the master xpub on oracle server startup * Add test for WalletAppConfig and seeds * Remove comments * Fix scalafmt
This commit is contained in:
parent
3852a885e1
commit
ea375f9c55
5 changed files with 64 additions and 4 deletions
2
.github/workflows/native.yml
vendored
2
.github/workflows/native.yml
vendored
|
@ -64,4 +64,4 @@ jobs:
|
|||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ${{ matrix.local_path }}
|
||||
asset_name: ${{ matrix.uploaded_filename }}
|
||||
asset_content_type: application/zip
|
||||
asset_content_type: application/zip
|
|
@ -43,8 +43,8 @@
|
|||
<!-- inspect resolved DB connection -->
|
||||
<logger name="org.bitcoins.db.SafeDatabase" level="WARN"/>
|
||||
|
||||
<logger name="org.bitcoins.dlc.oracle.config" level="WARN"/>
|
||||
<logger name="org.bitcoins.dlc.oracle.storage" level="WARN"/>
|
||||
<logger name="org.bitcoins.dlc.oracle.config" level="INFO"/>
|
||||
<logger name="org.bitcoins.dlc.oracle.storage" level="INFO"/>
|
||||
|
||||
|
||||
<!-- ╔═══════════════════════════╗ -->
|
||||
|
|
|
@ -74,4 +74,33 @@ class DLCOracleAppConfigTest extends DLCOracleAppConfigFixture {
|
|||
assert(pubKey1 == pubKey2)
|
||||
}
|
||||
}
|
||||
|
||||
it must "fail to start the oracle app config if we have different seeds" in {
|
||||
dlcOracleAppConfig: DLCOracleAppConfig =>
|
||||
val seedFile = dlcOracleAppConfig.seedPath
|
||||
val startedF = dlcOracleAppConfig.start()
|
||||
|
||||
//stop old oracle
|
||||
val stoppedF = for {
|
||||
_ <- startedF
|
||||
_ <- dlcOracleAppConfig.stop()
|
||||
} yield ()
|
||||
|
||||
val deletedF = for {
|
||||
_ <- stoppedF
|
||||
} yield {
|
||||
//delete the seed so we start with a new seed
|
||||
Files.delete(seedFile)
|
||||
}
|
||||
|
||||
val start2F = for {
|
||||
_ <- deletedF
|
||||
_ <- dlcOracleAppConfig.start()
|
||||
} yield ()
|
||||
|
||||
//start it again and except an exception
|
||||
recoverToSucceededIf[RuntimeException] {
|
||||
start2F
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.bitcoins.crypto.AesPassword
|
|||
import org.bitcoins.db.DatabaseDriver.{PostgreSQL, SQLite}
|
||||
import org.bitcoins.db._
|
||||
import org.bitcoins.db.models.MasterXPubDAO
|
||||
import org.bitcoins.db.util.DBMasterXPubApi
|
||||
import org.bitcoins.db.util.{DBMasterXPubApi, MasterXPubUtil}
|
||||
import org.bitcoins.dlc.oracle.DLCOracle
|
||||
import org.bitcoins.dlc.oracle.storage._
|
||||
import org.bitcoins.keymanager.bip39.BIP39KeyManager
|
||||
|
@ -100,6 +100,8 @@ case class DLCOracleAppConfig(
|
|||
val initializeF = initializeKeyManager()
|
||||
for {
|
||||
_ <- initializeF
|
||||
oracle = new DLCOracle()(this)
|
||||
_ <- MasterXPubUtil.checkMasterXPub(oracle.getRootXpub, masterXPubDAO)
|
||||
_ <- migrationWorkAroundF
|
||||
} yield {
|
||||
if (isHikariLoggingEnabled) {
|
||||
|
@ -154,6 +156,7 @@ case class DLCOracleAppConfig(
|
|||
.map(_ => ())
|
||||
}
|
||||
} else {
|
||||
logger.info(s"Not initializing key manager, seed already exists")
|
||||
Future.unit
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,4 +96,32 @@ class WalletAppConfigTest extends BitcoinSAsyncTest {
|
|||
assert(appConfig.datadir == tempDir.resolve("testnet3"))
|
||||
assert(appConfig.network == TestNet3)
|
||||
}
|
||||
|
||||
it must "fail to start the wallet app config if we have different seeds" in {
|
||||
val seedFile = config.seedPath
|
||||
val startedF = config.start()
|
||||
|
||||
//stop old oracle
|
||||
val stoppedF = for {
|
||||
_ <- startedF
|
||||
_ <- config.stop()
|
||||
} yield ()
|
||||
|
||||
val deletedF = for {
|
||||
_ <- stoppedF
|
||||
} yield {
|
||||
//delete the seed so we start with a new seed
|
||||
Files.delete(seedFile)
|
||||
}
|
||||
|
||||
val start2F = for {
|
||||
_ <- deletedF
|
||||
_ <- config.start()
|
||||
} yield ()
|
||||
|
||||
//start it again and except an exception
|
||||
recoverToSucceededIf[RuntimeException] {
|
||||
start2F
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue