From 69e27a13cfe06240f9ecfb355373ff2c4d6e85d6 Mon Sep 17 00:00:00 2001 From: jouzo Date: Tue, 23 Nov 2021 17:51:33 +0100 Subject: [PATCH] Improve error messages --- src/masternodes/rpc_vault.cpp | 6 +++--- test/functional/feature_loan_estimatecollateral.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/masternodes/rpc_vault.cpp b/src/masternodes/rpc_vault.cpp index d808ccbebd..d926ac8762 100644 --- a/src/masternodes/rpc_vault.cpp +++ b/src/masternodes/rpc_vault.cpp @@ -1189,7 +1189,7 @@ UniValue estimatecollateral(const JSONRPCRequest& request) { for (const auto& [tokenId, tokenAmount] : loanAmounts.balances) { auto loanToken = pcustomcsview->GetLoanTokenByID(tokenId); if (!loanToken) { - throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%s) is not a loan token!", tokenId.v)); + throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%d) is not a loan token!", tokenId.v)); } auto priceFeed = pcustomcsview->GetFixedIntervalPrice(loanToken->fixedIntervalPriceId); @@ -1199,7 +1199,7 @@ UniValue estimatecollateral(const JSONRPCRequest& request) { auto price = priceFeed.val->priceRecord[0]; if (!priceFeed.val->isLive(pcustomcsview->GetPriceDeviation())) { - throw JSONRPCError(RPC_MISC_ERROR, strprintf("No live fixed price for %s", tokenId.v)); + throw JSONRPCError(RPC_MISC_ERROR, strprintf("No live fixed price for %s", loanToken->symbol)); } totalLoanValue += MultiplyAmounts(tokenAmount, price); } @@ -1239,7 +1239,7 @@ UniValue estimatecollateral(const JSONRPCRequest& request) { totalSplit += split; } if (totalSplit != COIN) { - throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between collateral tokens = %d vs expected %d", totalSplit, COIN)); + throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between collateral tokens = %s vs expected %s", GetDecimaleString(totalSplit), GetDecimaleString(COIN))); } return AmountsToJSON(collateralBalances.balances); diff --git a/test/functional/feature_loan_estimatecollateral.py b/test/functional/feature_loan_estimatecollateral.py index f587c79ad0..78c2e33583 100644 --- a/test/functional/feature_loan_estimatecollateral.py +++ b/test/functional/feature_loan_estimatecollateral.py @@ -116,7 +116,7 @@ def run_test(self): self.nodes[0].estimatecollateral("10@TSLA", 200) except JSONRPCException as e: errorString = e.error['message'] - assert("No live fixed price" in errorString) + assert("No live fixed price for TSLA" in errorString) oracle1_prices = [ {"currency": "USD", "tokenAmount": "1@DFI"}, @@ -147,7 +147,7 @@ def run_test(self): self.nodes[0].estimatecollateral("10@TSLA", 200, {"DFI": 0.8}) except JSONRPCException as e: errorString = e.error['message'] - assert("total split between collateral tokens = 80000000 vs expected 100000000" in errorString) + assert("total split between collateral tokens = 0.80000000 vs expected 1.00000000" in errorString) estimatecollateral = self.nodes[0].estimatecollateral("10@TSLA", 200)