Fix bug where getbalances was always retruning sats (#3750)

This commit is contained in:
Chris Stewart 2021-10-13 14:51:13 -05:00 committed by GitHub
parent 94e219befd
commit 80d498d288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -355,6 +355,31 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
spendingTxIdOpt = Some(DoubleSha256DigestBE.empty)
)
"return the wallet's balances in bitcoin" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
.expects()
.returning(Future.successful(Bitcoins(50)))
(mockWalletApi.getUnconfirmedBalance: () => Future[CurrencyUnit])
.expects()
.returning(Future.successful(Bitcoins(50)))
(mockWalletApi
.listUtxos(_: TxoState))
.expects(TxoState.Reserved)
.returning(Future.successful(Vector(spendingInfoDb)))
val route =
walletRoutes.handleCommand(
ServerCommand("getbalances", Arr(Bool(false))))
Get() ~> route ~> check {
assert(contentType == `application/json`)
assert(
responseAs[String] == """{"result":{"confirmed":50,"unconfirmed":50,"reserved":-1.0E-8,"total":99.99999999},"error":null}""")
}
}
"return the wallet's balances in sats" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
.expects()

View File

@ -856,7 +856,7 @@ case class WalletRoutes(wallet: AnyDLCHDWalletApi)(implicit
if (isSats) {
currencyUnit.satoshis.toBigDecimal.toDouble
} else {
currencyUnit.toBigDecimal.toDouble
Bitcoins(currencyUnit.satoshis).toBigDecimal.toDouble
}
}
}