problem: returns nothing instead of 0 if no unspents
This commit is contained in:
@@ -140,6 +140,9 @@ class TrackBitcoinAddress(
|
|||||||
.map { unspent ->
|
.map { unspent ->
|
||||||
totalUnspent(address, includeUtxo, unspent)
|
totalUnspent(address, includeUtxo, unspent)
|
||||||
}
|
}
|
||||||
|
.switchIfEmpty(Mono.just(0).map {
|
||||||
|
AddressBalance(address, BigInteger.ZERO)
|
||||||
|
})
|
||||||
.onErrorResume { t ->
|
.onErrorResume { t ->
|
||||||
log.error("Failed to get unspent", t)
|
log.error("Failed to get unspent", t)
|
||||||
Mono.empty()
|
Mono.empty()
|
||||||
|
|||||||
@@ -83,6 +83,40 @@ class TrackBitcoinAddressSpec extends Specification {
|
|||||||
total.utxo.isEmpty()
|
total.utxo.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "Correct sum for none"() {
|
||||||
|
setup:
|
||||||
|
def unspents = []
|
||||||
|
TrackBitcoinAddress track = new TrackBitcoinAddress(Stub(MultistreamHolder))
|
||||||
|
def address = new TrackBitcoinAddress.Address(
|
||||||
|
Chain.BITCOIN, "1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK"
|
||||||
|
)
|
||||||
|
when:
|
||||||
|
def total = track.totalUnspent(address, false, unspents)
|
||||||
|
|
||||||
|
then:
|
||||||
|
total.balance == 0
|
||||||
|
total.utxo.isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
def "Correct sum for none read"() {
|
||||||
|
setup:
|
||||||
|
TrackBitcoinAddress track = new TrackBitcoinAddress(Stub(MultistreamHolder))
|
||||||
|
def address = new TrackBitcoinAddress.Address(
|
||||||
|
Chain.BITCOIN, "1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK"
|
||||||
|
)
|
||||||
|
def api = Mock(BitcoinMultistream) {
|
||||||
|
1 * getReader() >> Mock(BitcoinReader) {
|
||||||
|
1 * listUnspent(_) >> Mono.empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
when:
|
||||||
|
def total = track.balanceForAddress(api, address, false).block()
|
||||||
|
|
||||||
|
then:
|
||||||
|
total.balance == 0
|
||||||
|
total.utxo.isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
def "Correct sum for few with utxo"() {
|
def "Correct sum for few with utxo"() {
|
||||||
setup:
|
setup:
|
||||||
def unspents = [
|
def unspents = [
|
||||||
|
|||||||
Reference in New Issue
Block a user