Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Nov 23, 2021
1 parent 97e1726 commit 69e27a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/masternodes/rpc_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_loan_estimatecollateral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 69e27a1

Please sign in to comment.