formatting, import
This commit is contained in:
parent
c7a2abedba
commit
3c57820df0
@ -378,10 +378,7 @@ export class GlobalTestState {
|
||||
}
|
||||
}
|
||||
|
||||
assertAmountLeq(
|
||||
a: string | AmountJson,
|
||||
b: string | AmountJson,
|
||||
): void {
|
||||
assertAmountLeq(a: string | AmountJson, b: string | AmountJson): void {
|
||||
if (Amounts.cmp(a, b) > 0) {
|
||||
throw Error(
|
||||
`test assertion failed: expected ${Amounts.stringify(
|
||||
@ -1089,7 +1086,8 @@ export class ExchangeService implements ExchangeServiceInterface {
|
||||
"exchange-keyup",
|
||||
"taler-exchange-keyup",
|
||||
[
|
||||
"-c", this.configFilename,
|
||||
"-c",
|
||||
this.configFilename,
|
||||
...this.timetravelArgArr,
|
||||
"--revoke",
|
||||
denomPubHash,
|
||||
|
@ -38,7 +38,13 @@ import {
|
||||
BankAccessApi,
|
||||
MerchantPrivateApi,
|
||||
} 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";
|
||||
|
||||
export interface SimpleTestEnvironment {
|
||||
@ -309,57 +315,59 @@ export async function applyTimeTravel(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a simple payment and check that it succeeded.
|
||||
*/
|
||||
export async function makeTestPayment(t: GlobalTestState, args: {
|
||||
merchant: MerchantServiceInterface,
|
||||
wallet: WalletCli,
|
||||
order: Partial<ContractTerms>,
|
||||
instance?: string
|
||||
}): Promise<void> {
|
||||
// Set up order.
|
||||
export async function makeTestPayment(
|
||||
t: GlobalTestState,
|
||||
args: {
|
||||
merchant: MerchantServiceInterface;
|
||||
wallet: WalletCli;
|
||||
order: Partial<ContractTerms>;
|
||||
instance?: string;
|
||||
},
|
||||
): Promise<void> {
|
||||
// Set up order.
|
||||
|
||||
const { wallet, merchant } = args;
|
||||
const instance = args.instance ?? "default";
|
||||
const { wallet, merchant } = args;
|
||||
const instance = args.instance ?? "default";
|
||||
|
||||
const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, {
|
||||
order: {
|
||||
summary: "Buy me!",
|
||||
amount: "TESTKUDOS:5",
|
||||
fulfillment_url: "taler://fulfillment-success/thx",
|
||||
},
|
||||
});
|
||||
const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, {
|
||||
order: {
|
||||
summary: "Buy me!",
|
||||
amount: "TESTKUDOS:5",
|
||||
fulfillment_url: "taler://fulfillment-success/thx",
|
||||
},
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
orderId: orderResp.order_id,
|
||||
});
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
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({
|
||||
talerPayUri: orderStatus.taler_pay_uri,
|
||||
});
|
||||
const preparePayResult = await wallet.preparePay({
|
||||
talerPayUri: orderStatus.taler_pay_uri,
|
||||
});
|
||||
|
||||
t.assertTrue(
|
||||
preparePayResult.status === PreparePayResultType.PaymentPossible,
|
||||
);
|
||||
t.assertTrue(
|
||||
preparePayResult.status === PreparePayResultType.PaymentPossible,
|
||||
);
|
||||
|
||||
const r2 = await wallet.confirmPay({
|
||||
proposalId: preparePayResult.proposalId,
|
||||
});
|
||||
const r2 = await wallet.confirmPay({
|
||||
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, {
|
||||
orderId: orderResp.order_id,
|
||||
instance,
|
||||
});
|
||||
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
orderId: orderResp.order_id,
|
||||
instance,
|
||||
});
|
||||
|
||||
t.assertTrue(orderStatus.order_status === "paid");
|
||||
}
|
||||
t.assertTrue(orderStatus.order_status === "paid");
|
||||
}
|
||||
|
@ -17,10 +17,7 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import {
|
||||
runTest,
|
||||
GlobalTestState,
|
||||
} from "./harness";
|
||||
import { runTest, GlobalTestState } from "./harness";
|
||||
import {
|
||||
createSimpleTestkudosEnvironment,
|
||||
withdrawViaBank,
|
||||
|
@ -33,9 +33,9 @@ import {
|
||||
import { CoinDumpJson } from "taler-wallet-core";
|
||||
|
||||
async function revokeAllWalletCoins(req: {
|
||||
wallet: WalletCli,
|
||||
exchange: ExchangeService,
|
||||
merchant: MerchantService,
|
||||
wallet: WalletCli;
|
||||
exchange: ExchangeService;
|
||||
merchant: MerchantService;
|
||||
}): Promise<void> {
|
||||
const { wallet, exchange, merchant } = req;
|
||||
const coinDump = await wallet.dumpCoins();
|
||||
|
@ -64,4 +64,4 @@ export * from "./types/talerTypes";
|
||||
export * from "./types/walletTypes";
|
||||
export * from "./types/notifications";
|
||||
export * from "./types/transactions";
|
||||
export * from "./types/pending";
|
||||
export * from "./types/pending";
|
||||
|
@ -90,10 +90,16 @@ export async function getBalancesInsideTransaction(
|
||||
const b = initBalance(session.amountRefreshOutput.currency);
|
||||
// We are always assuming the refresh will succeed, thus we
|
||||
// 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 {
|
||||
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;
|
||||
}
|
||||
|
||||
export function isSpendableCoin(coin: CoinRecord, denom: DenominationRecord): boolean {
|
||||
export function isSpendableCoin(
|
||||
coin: CoinRecord,
|
||||
denom: DenominationRecord,
|
||||
): boolean {
|
||||
if (coin.suspended) {
|
||||
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) {
|
||||
resp.pendingOperations.push({
|
||||
type: PendingOperationType.ExchangeUpdate,
|
||||
@ -103,7 +104,10 @@ async function gatherExchangePending(
|
||||
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({
|
||||
type: PendingOperationType.ExchangeCheckRefresh,
|
||||
exchangeBaseUrl: e.baseUrl,
|
||||
|
@ -40,7 +40,11 @@ import {
|
||||
|
||||
import { codecForRecoupConfirmation } from "../types/talerTypes";
|
||||
import { NotificationType } from "../types/notifications";
|
||||
import { forceQueryReserve, getReserveRequestTimeout, processReserve } from "./reserves";
|
||||
import {
|
||||
forceQueryReserve,
|
||||
getReserveRequestTimeout,
|
||||
processReserve,
|
||||
} from "./reserves";
|
||||
|
||||
import { Amounts } from "../util/amounts";
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
||||
}
|
||||
@ -663,7 +666,10 @@ function getAutoRefreshCheckThreshold(d: DenominationRecord): Timestamp {
|
||||
* Timestamp after which the wallet would do an auto-refresh.
|
||||
*/
|
||||
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);
|
||||
return timestampAddDuration(d.stampExpireWithdraw, deltaDiv);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
ReserveRecordStatus,
|
||||
} from "../types/dbTypes";
|
||||
import { Amounts, AmountJson } from "../util/amounts";
|
||||
import { timestampCmp, Timestamp } from "../util/time";
|
||||
import { timestampCmp } from "../util/time";
|
||||
import {
|
||||
TransactionsRequest,
|
||||
TransactionsResponse,
|
||||
@ -281,10 +281,10 @@ export async function getTransactions(
|
||||
groupKey,
|
||||
);
|
||||
let r0: WalletRefundItem | undefined;
|
||||
let amountRaw = Amounts.getZero(
|
||||
let amountRaw = Amounts.getZero(pr.contractData.amount.currency);
|
||||
let amountEffective = Amounts.getZero(
|
||||
pr.contractData.amount.currency,
|
||||
);
|
||||
let amountEffective = Amounts.getZero(pr.contractData.amount.currency);
|
||||
for (const rk of Object.keys(pr.refunds)) {
|
||||
const refund = pr.refunds[rk];
|
||||
const myGroupKey = `${refund.executionTime.t_ms}`;
|
||||
@ -296,10 +296,7 @@ export async function getTransactions(
|
||||
}
|
||||
|
||||
if (refund.type === RefundState.Applied) {
|
||||
amountRaw = Amounts.add(
|
||||
amountRaw,
|
||||
refund.refundAmount,
|
||||
).amount;
|
||||
amountRaw = Amounts.add(amountRaw, refund.refundAmount).amount;
|
||||
amountEffective = Amounts.add(
|
||||
amountEffective,
|
||||
Amounts.sub(
|
||||
|
@ -657,14 +657,13 @@ export interface ExchangeRecord {
|
||||
|
||||
/**
|
||||
* Next time that we should check if coins need to be refreshed.
|
||||
*
|
||||
*
|
||||
* Updated whenever the exchange's denominations are updated or when
|
||||
* the refresh check has been done.
|
||||
*/
|
||||
nextRefreshCheck?: Timestamp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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}`,
|
||||
);
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 { TalerErrorCode } from "../TalerErrorCode";
|
||||
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");
|
||||
|
||||
|
@ -86,7 +86,7 @@ export function timestampMax(t1: Timestamp, t2: Timestamp): Timestamp {
|
||||
return { t_ms: Math.max(t1.t_ms, t2.t_ms) };
|
||||
}
|
||||
|
||||
const SECONDS = 1000
|
||||
const SECONDS = 1000;
|
||||
const MINUTES = SECONDS * 60;
|
||||
const HOURS = MINUTES * 60;
|
||||
const DAYS = HOURS * 24;
|
||||
@ -94,12 +94,12 @@ const MONTHS = DAYS * 30;
|
||||
const YEARS = DAYS * 365;
|
||||
|
||||
export function durationFromSpec(spec: {
|
||||
seconds?: number,
|
||||
minutes?: number,
|
||||
hours?: number,
|
||||
days?: number,
|
||||
months?: number,
|
||||
years?: number,
|
||||
seconds?: number;
|
||||
minutes?: number;
|
||||
hours?: number;
|
||||
days?: number;
|
||||
months?: number;
|
||||
years?: number;
|
||||
}): Duration {
|
||||
let d_ms = 0;
|
||||
d_ms += (spec.seconds ?? 0) * SECONDS;
|
||||
@ -148,7 +148,7 @@ export function durationMul(d: Duration, n: number): Duration {
|
||||
if (d.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user