mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
Fix SpendingInfoDAO.findOutputsReceived() bug (#4090)
This commit is contained in:
parent
4d85b7a3d7
commit
dc47c070a2
3 changed files with 16 additions and 7 deletions
|
@ -266,7 +266,7 @@ object WalletTestUtil {
|
|||
def insertLegacyUTXO(daos: WalletDAOs, state: TxoState)(implicit
|
||||
ec: ExecutionContext): Future[LegacySpendingInfo] = {
|
||||
for {
|
||||
account <- daos.accountDAO.create(WalletTestUtil.firstAccountDb)
|
||||
account <- daos.accountDAO.upsert(WalletTestUtil.firstAccountDb)
|
||||
addr <- daos.addressDAO.create(getAddressDb(account))
|
||||
utxo = sampleLegacyUTXO(addr.scriptPubKey, state)
|
||||
_ <- insertDummyIncomingTransaction(daos, utxo)
|
||||
|
|
|
@ -182,14 +182,21 @@ class SpendingInfoDAOTest extends WalletDAOFixture {
|
|||
} yield assert(unspent.isEmpty)
|
||||
}
|
||||
|
||||
it must "insert a TXO and read it back with through a TXID " in { daos =>
|
||||
it must "insert a TXO that is received and find it" in { daos =>
|
||||
val spendingInfoDAO = daos.utxoDAO
|
||||
|
||||
for {
|
||||
utxo <- WalletTestUtil.insertLegacyUTXO(daos,
|
||||
state = TxoState.DoesNotExist)
|
||||
foundTxos <- spendingInfoDAO.findOutputsReceived(Vector(utxo.txid))
|
||||
} yield assert(foundTxos.contains(utxo))
|
||||
utxo <- WalletTestUtil.insertLegacyUTXO(
|
||||
daos,
|
||||
state = TxoState.PendingConfirmationsReceived)
|
||||
utxo2 <- WalletTestUtil.insertLegacyUTXO(daos,
|
||||
state = TxoState.BroadcastSpent)
|
||||
foundTxos <- spendingInfoDAO.findOutputsReceived(
|
||||
Vector(utxo.txid, utxo2.txid))
|
||||
} yield {
|
||||
assert(foundTxos.length == 1)
|
||||
assert(foundTxos.contains(utxo))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -308,7 +308,9 @@ case class SpendingInfoDAO()(implicit
|
|||
*/
|
||||
def findOutputsReceived(
|
||||
txids: Vector[DoubleSha256DigestBE]): Future[Vector[SpendingInfoDb]] = {
|
||||
val filtered = spkJoinQuery.filter(_._1.txid.inSet(txids))
|
||||
val filtered = spkJoinQuery
|
||||
.filter(_._1.state.inSet(TxoState.receivedStates))
|
||||
.filter(_._1.txid.inSet(txids))
|
||||
safeDatabase
|
||||
.runVec(filtered.result)
|
||||
.map(res =>
|
||||
|
|
Loading…
Add table
Reference in a new issue