formatting, import

This commit is contained in:
Florian Dold 2020-09-04 12:04:11 +05:30
parent c7a2abedba
commit 3c57820df0
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
15 changed files with 110 additions and 81 deletions

View File

@ -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,

View File

@ -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,57 +315,59 @@ 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>;
// Set up order. instance?: string;
},
): Promise<void> {
// Set up order.
const { wallet, merchant } = args; const { wallet, merchant } = args;
const instance = args.instance ?? "default"; const instance = args.instance ?? "default";
const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, { const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, {
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "unpaid");
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet.preparePay({ const preparePayResult = await wallet.preparePay({
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
const r2 = await wallet.confirmPay({ const r2 = await wallet.confirmPay({
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
t.assertTrue(r2.type === ConfirmPayResultType.Done); t.assertTrue(r2.type === ConfirmPayResultType.Done);
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
orderId: orderResp.order_id, orderId: orderResp.order_id,
instance, instance,
}); });
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
} }

View File

@ -17,10 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { import { runTest, GlobalTestState } from "./harness";
runTest,
GlobalTestState,
} from "./harness";
import { import {
createSimpleTestkudosEnvironment, createSimpleTestkudosEnvironment,
withdrawViaBank, withdrawViaBank,

View File

@ -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();

View File

@ -64,4 +64,4 @@ export * from "./types/talerTypes";
export * from "./types/walletTypes"; export * from "./types/walletTypes";
export * from "./types/notifications"; export * from "./types/notifications";
export * from "./types/transactions"; export * from "./types/transactions";
export * from "./types/pending"; export * from "./types/pending";

View File

@ -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;
} }
} }
}); });

View File

@ -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;
} }

View File

@ -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,

View File

@ -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";

View File

@ -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);
} }

View File

@ -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(

View File

@ -657,14 +657,13 @@ export interface ExchangeRecord {
/** /**
* Next time that we should check if coins need to be refreshed. * Next time that we should check if coins need to be refreshed.
* *
* Updated whenever the exchange's denominations are updated or when * Updated whenever the exchange's denominations are updated or when
* the refresh check has been done. * the refresh check has been done.
*/ */
nextRefreshCheck?: Timestamp; nextRefreshCheck?: Timestamp;
} }
/** /**
* A coin that isn't yet signed by an exchange. * A coin that isn't yet signed by an exchange.
*/ */

View File

@ -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.

View File

@ -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");

View File

@ -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;
@ -148,7 +148,7 @@ export function durationMul(d: Duration, n: number): Duration {
if (d.d_ms === "forever") { if (d.d_ms === "forever") {
return { d_ms: "forever" }; return { d_ms: "forever" };
} }
return { d_ms: Math.round( d.d_ms * n) }; return { d_ms: Math.round(d.d_ms * n) };
} }
export function timestampCmp(t1: Timestamp, t2: Timestamp): number { export function timestampCmp(t1: Timestamp, t2: Timestamp): number {