wallet-core: test insufficient balance response, also use it for deposit groups
This commit is contained in:
parent
db1b824818
commit
80639429a2
@ -17,7 +17,7 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import { Duration, PreparePayResultType } from "@gnu-taler/taler-util";
|
||||
import { Amounts, Duration, PreparePayResultType } from "@gnu-taler/taler-util";
|
||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||
import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js";
|
||||
import {
|
||||
@ -133,11 +133,23 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
|
||||
},
|
||||
);
|
||||
|
||||
t.assertTrue(
|
||||
preparePayResult.status === PreparePayResultType.InsufficientBalance,
|
||||
);
|
||||
|
||||
t.assertDeepEqual(
|
||||
preparePayResult.status,
|
||||
PreparePayResultType.InsufficientBalance,
|
||||
);
|
||||
|
||||
t.assertTrue(
|
||||
Amounts.isNonZero(preparePayResult.balanceDetails.balanceMerchantAcceptable),
|
||||
);
|
||||
|
||||
t.assertTrue(
|
||||
Amounts.isZero(preparePayResult.balanceDetails.balanceMerchantDepositable),
|
||||
);
|
||||
|
||||
await wallet.runUntilDone();
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,8 @@ export class Amounts {
|
||||
/**
|
||||
* Check if an amount is non-zero.
|
||||
*/
|
||||
static isNonZero(a: AmountJson): boolean {
|
||||
static isNonZero(a: AmountLike): boolean {
|
||||
a = Amounts.jsonifyAmount(a);
|
||||
return a.value > 0 || a.fraction > 0;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2141,4 +2141,6 @@ const codecForPayMerchantInsufficientBalanceDetails =
|
||||
.property("balanceMerchantAcceptable", codecForAmountString())
|
||||
.property("balanceMerchantDepositable", codecForAmountString())
|
||||
.property("feeGapEstimate", codecForAmountString())
|
||||
.build("PayMerchantInsufficientBalanceDetails");
|
||||
.build("PayMerchantInsufficientBalanceDetails");
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
* Imports.
|
||||
*/
|
||||
import {
|
||||
PayMerchantInsufficientBalanceDetails,
|
||||
TalerErrorCode,
|
||||
TalerErrorDetail,
|
||||
TransactionType,
|
||||
@ -83,6 +84,9 @@ export interface DetailsMap {
|
||||
[TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED]: {
|
||||
// FIXME!
|
||||
};
|
||||
[TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE]: {
|
||||
insufficientBalanceDetails: PayMerchantInsufficientBalanceDetails;
|
||||
};
|
||||
}
|
||||
|
||||
type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : never;
|
||||
|
@ -45,12 +45,14 @@ import {
|
||||
TrackDepositGroupResponse,
|
||||
TransactionType,
|
||||
URL,
|
||||
TalerErrorCode,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import {
|
||||
DenominationRecord,
|
||||
DepositGroupRecord,
|
||||
OperationStatus,
|
||||
} from "../db.js";
|
||||
import { TalerError } from "../errors.js";
|
||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||
import { readSuccessResponseJsonOrThrow } from "../util/http.js";
|
||||
import { OperationAttemptResult } from "../util/retries.js";
|
||||
@ -269,7 +271,12 @@ export async function getFeeForDeposit(
|
||||
});
|
||||
|
||||
if (payCoinSel.type !== "success") {
|
||||
throw Error("insufficient funds");
|
||||
throw TalerError.fromDetail(
|
||||
TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE,
|
||||
{
|
||||
insufficientBalanceDetails: payCoinSel.insufficientBalanceDetails,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return await getTotalFeesForDepositAmount(
|
||||
@ -356,7 +363,12 @@ export async function prepareDepositGroup(
|
||||
});
|
||||
|
||||
if (payCoinSel.type !== "success") {
|
||||
throw Error("insufficient funds");
|
||||
throw TalerError.fromDetail(
|
||||
TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE,
|
||||
{
|
||||
insufficientBalanceDetails: payCoinSel.insufficientBalanceDetails,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const totalDepositCost = await getTotalPaymentCost(ws, payCoinSel.coinSel);
|
||||
@ -453,7 +465,12 @@ export async function createDepositGroup(
|
||||
});
|
||||
|
||||
if (payCoinSel.type !== "success") {
|
||||
throw Error("insufficient funds");
|
||||
throw TalerError.fromDetail(
|
||||
TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE,
|
||||
{
|
||||
insufficientBalanceDetails: payCoinSel.insufficientBalanceDetails,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const totalDepositCost = await getTotalPaymentCost(ws, payCoinSel.coinSel);
|
||||
|
Loading…
Reference in New Issue
Block a user