Fix SpendingInfoDAO.findOutputsReceived() bug (#4090)

This commit is contained in:
Chris Stewart 2022-02-14 10:11:23 -06:00 committed by GitHub
parent 4d85b7a3d7
commit dc47c070a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -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)

View file

@ -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))
}
}

View file

@ -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 =>