formatting, import
This commit is contained in:
parent
c7a2abedba
commit
3c57820df0
@ -378,10 +378,7 @@ export class GlobalTestState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertAmountLeq(
|
assertAmountLeq(a: string | AmountJson, b: string | AmountJson): void {
|
||||||
a: string | AmountJson,
|
|
||||||
b: string | AmountJson,
|
|
||||||
): void {
|
|
||||||
if (Amounts.cmp(a, b) > 0) {
|
if (Amounts.cmp(a, b) > 0) {
|
||||||
throw Error(
|
throw Error(
|
||||||
`test assertion failed: expected ${Amounts.stringify(
|
`test assertion failed: expected ${Amounts.stringify(
|
||||||
@ -1089,7 +1086,8 @@ export class ExchangeService implements ExchangeServiceInterface {
|
|||||||
"exchange-keyup",
|
"exchange-keyup",
|
||||||
"taler-exchange-keyup",
|
"taler-exchange-keyup",
|
||||||
[
|
[
|
||||||
"-c", this.configFilename,
|
"-c",
|
||||||
|
this.configFilename,
|
||||||
...this.timetravelArgArr,
|
...this.timetravelArgArr,
|
||||||
"--revoke",
|
"--revoke",
|
||||||
denomPubHash,
|
denomPubHash,
|
||||||
|
@ -38,7 +38,13 @@ import {
|
|||||||
BankAccessApi,
|
BankAccessApi,
|
||||||
MerchantPrivateApi,
|
MerchantPrivateApi,
|
||||||
} from "./harness";
|
} from "./harness";
|
||||||
import { AmountString, Duration, PreparePayResultType, ConfirmPayResultType, ContractTerms } from "taler-wallet-core";
|
import {
|
||||||
|
AmountString,
|
||||||
|
Duration,
|
||||||
|
PreparePayResultType,
|
||||||
|
ConfirmPayResultType,
|
||||||
|
ContractTerms,
|
||||||
|
} from "taler-wallet-core";
|
||||||
import { FaultInjectedMerchantService } from "./faultInjection";
|
import { FaultInjectedMerchantService } from "./faultInjection";
|
||||||
|
|
||||||
export interface SimpleTestEnvironment {
|
export interface SimpleTestEnvironment {
|
||||||
@ -309,16 +315,18 @@ export async function applyTimeTravel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a simple payment and check that it succeeded.
|
* Make a simple payment and check that it succeeded.
|
||||||
*/
|
*/
|
||||||
export async function makeTestPayment(t: GlobalTestState, args: {
|
export async function makeTestPayment(
|
||||||
merchant: MerchantServiceInterface,
|
t: GlobalTestState,
|
||||||
wallet: WalletCli,
|
args: {
|
||||||
order: Partial<ContractTerms>,
|
merchant: MerchantServiceInterface;
|
||||||
instance?: string
|
wallet: WalletCli;
|
||||||
}): Promise<void> {
|
order: Partial<ContractTerms>;
|
||||||
|
instance?: string;
|
||||||
|
},
|
||||||
|
): Promise<void> {
|
||||||
// Set up order.
|
// Set up order.
|
||||||
|
|
||||||
const { wallet, merchant } = args;
|
const { wallet, merchant } = args;
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import { runTest, GlobalTestState } from "./harness";
|
||||||
runTest,
|
|
||||||
GlobalTestState,
|
|
||||||
} from "./harness";
|
|
||||||
import {
|
import {
|
||||||
createSimpleTestkudosEnvironment,
|
createSimpleTestkudosEnvironment,
|
||||||
withdrawViaBank,
|
withdrawViaBank,
|
||||||
|
@ -33,9 +33,9 @@ import {
|
|||||||
import { CoinDumpJson } from "taler-wallet-core";
|
import { CoinDumpJson } from "taler-wallet-core";
|
||||||
|
|
||||||
async function revokeAllWalletCoins(req: {
|
async function revokeAllWalletCoins(req: {
|
||||||
wallet: WalletCli,
|
wallet: WalletCli;
|
||||||
exchange: ExchangeService,
|
exchange: ExchangeService;
|
||||||
merchant: MerchantService,
|
merchant: MerchantService;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { wallet, exchange, merchant } = req;
|
const { wallet, exchange, merchant } = req;
|
||||||
const coinDump = await wallet.dumpCoins();
|
const coinDump = await wallet.dumpCoins();
|
||||||
|
@ -90,10 +90,16 @@ export async function getBalancesInsideTransaction(
|
|||||||
const b = initBalance(session.amountRefreshOutput.currency);
|
const b = initBalance(session.amountRefreshOutput.currency);
|
||||||
// We are always assuming the refresh will succeed, thus we
|
// We are always assuming the refresh will succeed, thus we
|
||||||
// report the output as available balance.
|
// report the output as available balance.
|
||||||
b.available = Amounts.add(b.available, session.amountRefreshOutput).amount;
|
b.available = Amounts.add(
|
||||||
|
b.available,
|
||||||
|
session.amountRefreshOutput,
|
||||||
|
).amount;
|
||||||
} else {
|
} else {
|
||||||
const b = initBalance(r.inputPerCoin[i].currency);
|
const b = initBalance(r.inputPerCoin[i].currency);
|
||||||
b.available = Amounts.add(b.available, r.estimatedOutputPerCoin[i]).amount;
|
b.available = Amounts.add(
|
||||||
|
b.available,
|
||||||
|
r.estimatedOutputPerCoin[i],
|
||||||
|
).amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -288,7 +288,10 @@ export function selectPayCoins(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isSpendableCoin(coin: CoinRecord, denom: DenominationRecord): boolean {
|
export function isSpendableCoin(
|
||||||
|
coin: CoinRecord,
|
||||||
|
denom: DenominationRecord,
|
||||||
|
): boolean {
|
||||||
if (coin.suspended) {
|
if (coin.suspended) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,8 @@ async function gatherExchangePending(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const keysUpdateRequired = e.details && e.details.nextUpdateTime.t_ms < now.t_ms;
|
const keysUpdateRequired =
|
||||||
|
e.details && e.details.nextUpdateTime.t_ms < now.t_ms;
|
||||||
if (keysUpdateRequired) {
|
if (keysUpdateRequired) {
|
||||||
resp.pendingOperations.push({
|
resp.pendingOperations.push({
|
||||||
type: PendingOperationType.ExchangeUpdate,
|
type: PendingOperationType.ExchangeUpdate,
|
||||||
@ -103,7 +104,10 @@ async function gatherExchangePending(
|
|||||||
reason: "scheduled",
|
reason: "scheduled",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (e.details && (!e.nextRefreshCheck || e.nextRefreshCheck.t_ms < now.t_ms)) {
|
if (
|
||||||
|
e.details &&
|
||||||
|
(!e.nextRefreshCheck || e.nextRefreshCheck.t_ms < now.t_ms)
|
||||||
|
) {
|
||||||
resp.pendingOperations.push({
|
resp.pendingOperations.push({
|
||||||
type: PendingOperationType.ExchangeCheckRefresh,
|
type: PendingOperationType.ExchangeCheckRefresh,
|
||||||
exchangeBaseUrl: e.baseUrl,
|
exchangeBaseUrl: e.baseUrl,
|
||||||
|
@ -40,7 +40,11 @@ import {
|
|||||||
|
|
||||||
import { codecForRecoupConfirmation } from "../types/talerTypes";
|
import { codecForRecoupConfirmation } from "../types/talerTypes";
|
||||||
import { NotificationType } from "../types/notifications";
|
import { NotificationType } from "../types/notifications";
|
||||||
import { forceQueryReserve, getReserveRequestTimeout, processReserve } from "./reserves";
|
import {
|
||||||
|
forceQueryReserve,
|
||||||
|
getReserveRequestTimeout,
|
||||||
|
processReserve,
|
||||||
|
} from "./reserves";
|
||||||
|
|
||||||
import { Amounts } from "../util/amounts";
|
import { Amounts } from "../util/amounts";
|
||||||
import { createRefreshGroup, processRefreshGroup } from "./refresh";
|
import { createRefreshGroup, processRefreshGroup } from "./refresh";
|
||||||
|
@ -654,7 +654,10 @@ export async function createRefreshGroup(
|
|||||||
* Timestamp after which the wallet would do the next check for an auto-refresh.
|
* Timestamp after which the wallet would do the next check for an auto-refresh.
|
||||||
*/
|
*/
|
||||||
function getAutoRefreshCheckThreshold(d: DenominationRecord): Timestamp {
|
function getAutoRefreshCheckThreshold(d: DenominationRecord): Timestamp {
|
||||||
const delta = timestampDifference(d.stampExpireWithdraw, d.stampExpireDeposit);
|
const delta = timestampDifference(
|
||||||
|
d.stampExpireWithdraw,
|
||||||
|
d.stampExpireDeposit,
|
||||||
|
);
|
||||||
const deltaDiv = durationMul(delta, 0.75);
|
const deltaDiv = durationMul(delta, 0.75);
|
||||||
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
||||||
}
|
}
|
||||||
@ -663,7 +666,10 @@ function getAutoRefreshCheckThreshold(d: DenominationRecord): Timestamp {
|
|||||||
* Timestamp after which the wallet would do an auto-refresh.
|
* Timestamp after which the wallet would do an auto-refresh.
|
||||||
*/
|
*/
|
||||||
function getAutoRefreshExecuteThreshold(d: DenominationRecord): Timestamp {
|
function getAutoRefreshExecuteThreshold(d: DenominationRecord): Timestamp {
|
||||||
const delta = timestampDifference(d.stampExpireWithdraw, d.stampExpireDeposit);
|
const delta = timestampDifference(
|
||||||
|
d.stampExpireWithdraw,
|
||||||
|
d.stampExpireDeposit,
|
||||||
|
);
|
||||||
const deltaDiv = durationMul(delta, 0.5);
|
const deltaDiv = durationMul(delta, 0.5);
|
||||||
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import {
|
|||||||
ReserveRecordStatus,
|
ReserveRecordStatus,
|
||||||
} from "../types/dbTypes";
|
} from "../types/dbTypes";
|
||||||
import { Amounts, AmountJson } from "../util/amounts";
|
import { Amounts, AmountJson } from "../util/amounts";
|
||||||
import { timestampCmp, Timestamp } from "../util/time";
|
import { timestampCmp } from "../util/time";
|
||||||
import {
|
import {
|
||||||
TransactionsRequest,
|
TransactionsRequest,
|
||||||
TransactionsResponse,
|
TransactionsResponse,
|
||||||
@ -281,10 +281,10 @@ export async function getTransactions(
|
|||||||
groupKey,
|
groupKey,
|
||||||
);
|
);
|
||||||
let r0: WalletRefundItem | undefined;
|
let r0: WalletRefundItem | undefined;
|
||||||
let amountRaw = Amounts.getZero(
|
let amountRaw = Amounts.getZero(pr.contractData.amount.currency);
|
||||||
|
let amountEffective = Amounts.getZero(
|
||||||
pr.contractData.amount.currency,
|
pr.contractData.amount.currency,
|
||||||
);
|
);
|
||||||
let amountEffective = Amounts.getZero(pr.contractData.amount.currency);
|
|
||||||
for (const rk of Object.keys(pr.refunds)) {
|
for (const rk of Object.keys(pr.refunds)) {
|
||||||
const refund = pr.refunds[rk];
|
const refund = pr.refunds[rk];
|
||||||
const myGroupKey = `${refund.executionTime.t_ms}`;
|
const myGroupKey = `${refund.executionTime.t_ms}`;
|
||||||
@ -296,10 +296,7 @@ export async function getTransactions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (refund.type === RefundState.Applied) {
|
if (refund.type === RefundState.Applied) {
|
||||||
amountRaw = Amounts.add(
|
amountRaw = Amounts.add(amountRaw, refund.refundAmount).amount;
|
||||||
amountRaw,
|
|
||||||
refund.refundAmount,
|
|
||||||
).amount;
|
|
||||||
amountEffective = Amounts.add(
|
amountEffective = Amounts.add(
|
||||||
amountEffective,
|
amountEffective,
|
||||||
Amounts.sub(
|
Amounts.sub(
|
||||||
|
@ -664,7 +664,6 @@ export interface ExchangeRecord {
|
|||||||
nextRefreshCheck?: Timestamp;
|
nextRefreshCheck?: Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A coin that isn't yet signed by an exchange.
|
* A coin that isn't yet signed by an exchange.
|
||||||
*/
|
*/
|
||||||
|
@ -302,8 +302,8 @@ export function codecForBoolean(): Codec<boolean> {
|
|||||||
`expected boolean at ${renderContext(c)} but got ${typeof x}`,
|
`expected boolean at ${renderContext(c)} but got ${typeof x}`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a codec for a value that must be a string.
|
* Return a codec for a value that must be a string.
|
||||||
|
@ -26,7 +26,14 @@ import { Codec } from "./codec";
|
|||||||
import { OperationFailedError, makeErrorDetails } from "../operations/errors";
|
import { OperationFailedError, makeErrorDetails } from "../operations/errors";
|
||||||
import { TalerErrorCode } from "../TalerErrorCode";
|
import { TalerErrorCode } from "../TalerErrorCode";
|
||||||
import { Logger } from "./logging";
|
import { Logger } from "./logging";
|
||||||
import { Duration, Timestamp, getTimestampNow, timestampAddDuration, timestampMin, timestampMax } from "./time";
|
import {
|
||||||
|
Duration,
|
||||||
|
Timestamp,
|
||||||
|
getTimestampNow,
|
||||||
|
timestampAddDuration,
|
||||||
|
timestampMin,
|
||||||
|
timestampMax,
|
||||||
|
} from "./time";
|
||||||
|
|
||||||
const logger = new Logger("http.ts");
|
const logger = new Logger("http.ts");
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ export function timestampMax(t1: Timestamp, t2: Timestamp): Timestamp {
|
|||||||
return { t_ms: Math.max(t1.t_ms, t2.t_ms) };
|
return { t_ms: Math.max(t1.t_ms, t2.t_ms) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000;
|
||||||
const MINUTES = SECONDS * 60;
|
const MINUTES = SECONDS * 60;
|
||||||
const HOURS = MINUTES * 60;
|
const HOURS = MINUTES * 60;
|
||||||
const DAYS = HOURS * 24;
|
const DAYS = HOURS * 24;
|
||||||
@ -94,12 +94,12 @@ const MONTHS = DAYS * 30;
|
|||||||
const YEARS = DAYS * 365;
|
const YEARS = DAYS * 365;
|
||||||
|
|
||||||
export function durationFromSpec(spec: {
|
export function durationFromSpec(spec: {
|
||||||
seconds?: number,
|
seconds?: number;
|
||||||
minutes?: number,
|
minutes?: number;
|
||||||
hours?: number,
|
hours?: number;
|
||||||
days?: number,
|
days?: number;
|
||||||
months?: number,
|
months?: number;
|
||||||
years?: number,
|
years?: number;
|
||||||
}): Duration {
|
}): Duration {
|
||||||
let d_ms = 0;
|
let d_ms = 0;
|
||||||
d_ms += (spec.seconds ?? 0) * SECONDS;
|
d_ms += (spec.seconds ?? 0) * SECONDS;
|
||||||
|
Loading…
Reference in New Issue
Block a user