diff options
author | Florian Dold <florian@dold.me> | 2022-03-22 23:03:41 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-22 23:03:41 +0100 |
commit | 739c2f933770206b173a9b3cbafa79ee6048ff9d (patch) | |
tree | aaae15f5f22a0fe1a8449494a50477ca9ed3a0a5 /packages/taler-wallet-cli/src/harness | |
parent | 5d23eb36354d07508a015531f298b3e261bbafce (diff) | |
download | wallet-core-739c2f933770206b173a9b3cbafa79ee6048ff9d.tar.xz |
wallet: more time format fixes
Diffstat (limited to 'packages/taler-wallet-cli/src/harness')
-rw-r--r-- | packages/taler-wallet-cli/src/harness/harness.ts | 95 | ||||
-rw-r--r-- | packages/taler-wallet-cli/src/harness/helpers.ts | 15 | ||||
-rw-r--r-- | packages/taler-wallet-cli/src/harness/merchantApiTypes.ts | 83 |
3 files changed, 105 insertions, 88 deletions
diff --git a/packages/taler-wallet-cli/src/harness/harness.ts b/packages/taler-wallet-cli/src/harness/harness.ts index 46ddd0ed2..30503e488 100644 --- a/packages/taler-wallet-cli/src/harness/harness.ts +++ b/packages/taler-wallet-cli/src/harness/harness.ts @@ -24,56 +24,53 @@ /** * Imports */ -import * as util from "util"; -import * as fs from "fs"; -import * as path from "path"; -import * as http from "http"; -import * as readline from "readline"; -import { deepStrictEqual } from "assert"; -import { ChildProcess, spawn } from "child_process"; -import { URL } from "url"; -import axios, { AxiosError } from "axios"; -import { - codecForMerchantOrderPrivateStatusResponse, - codecForPostOrderResponse, - PostOrderRequest, - PostOrderResponse, - MerchantOrderPrivateStatusResponse, - TippingReserveStatus, - TipCreateConfirmation, - TipCreateRequest, - MerchantInstancesResponse, -} from "./merchantApiTypes"; -import { - BankServiceHandle, - HarnessExchangeBankAccount, - NodeHttpLib, - openPromise, - TalerError, - WalletCoreApiClient, -} from "@gnu-taler/taler-wallet-core"; import { AmountJson, Amounts, - Configuration, AmountString, - Codec, - buildCodecForObject, - codecForString, - Duration, - parsePaytoUri, + Configuration, CoreApiResponse, createEddsaKeyPair, + Duration, eddsaGetPublic, EddsaKeyPair, encodeCrock, - getRandomBytes, hash, - stringToBytes, j2s, + parsePaytoUri, + stringToBytes, + TalerProtocolDuration, } from "@gnu-taler/taler-util"; +import { + BankServiceHandle, + HarnessExchangeBankAccount, + NodeHttpLib, + openPromise, + TalerError, + WalletCoreApiClient, +} from "@gnu-taler/taler-wallet-core"; +import { deepStrictEqual } from "assert"; +import axios, { AxiosError } from "axios"; +import { ChildProcess, spawn } from "child_process"; +import * as fs from "fs"; +import * as http from "http"; +import * as path from "path"; +import * as readline from "readline"; +import { URL } from "url"; +import * as util from "util"; import { CoinConfig } from "./denomStructures.js"; import { LibeufinNexusApi, LibeufinSandboxApi } from "./libeufin-apis.js"; +import { + codecForMerchantOrderPrivateStatusResponse, + codecForPostOrderResponse, + MerchantInstancesResponse, + MerchantOrderPrivateStatusResponse, + PostOrderRequest, + PostOrderResponse, + TipCreateConfirmation, + TipCreateRequest, + TippingReserveStatus, +} from "./merchantApiTypes"; const exec = util.promisify(require("child_process").exec); @@ -1712,7 +1709,8 @@ export class MerchantService implements MerchantServiceInterface { console.log("adding instance"); const url = `http://localhost:${this.merchantConfig.httpPort}/management/instances`; const auth = instanceConfig.auth ?? { method: "external" }; - await axios.post(url, { + + const body: MerchantInstanceConfig = { auth, payto_uris: instanceConfig.paytoUris, id: instanceConfig.id, @@ -1729,11 +1727,16 @@ export class MerchantService implements MerchantServiceInterface { `${this.merchantConfig.currency}:1.0`, default_wire_transfer_delay: instanceConfig.defaultWireTransferDelay ?? - Duration.fromSpec({ - days: 1, - }), - default_pay_delay: instanceConfig.defaultPayDelay ?? { d_ms: "forever" }, - }); + Duration.toTalerProtocolDuration( + Duration.fromSpec({ + days: 1, + }), + ), + default_pay_delay: + instanceConfig.defaultPayDelay ?? + Duration.toTalerProtocolDuration(Duration.getForever()), + }; + await axios.post(url, body); } makeInstanceBaseUrl(instanceName?: string): string { @@ -1765,8 +1768,8 @@ export interface PartialMerchantInstanceConfig { defaultMaxWireFee?: string; defaultMaxDepositFee?: string; defaultWireFeeAmortization?: number; - defaultWireTransferDelay?: Duration; - defaultPayDelay?: Duration; + defaultWireTransferDelay?: TalerProtocolDuration; + defaultPayDelay?: TalerProtocolDuration; } export interface MerchantInstanceConfig { @@ -1779,8 +1782,8 @@ export interface MerchantInstanceConfig { default_max_wire_fee: string; default_max_deposit_fee: string; default_wire_fee_amortization: number; - default_wire_transfer_delay: Duration; - default_pay_delay: Duration; + default_wire_transfer_delay: TalerProtocolDuration; + default_pay_delay: TalerProtocolDuration; } type TestStatus = "pass" | "fail" | "skip"; diff --git a/packages/taler-wallet-cli/src/harness/helpers.ts b/packages/taler-wallet-cli/src/harness/helpers.ts index 117bcdcf8..3840dcf94 100644 --- a/packages/taler-wallet-cli/src/harness/helpers.ts +++ b/packages/taler-wallet-cli/src/harness/helpers.ts @@ -30,7 +30,12 @@ import { Duration, PreparePayResultType, } from "@gnu-taler/taler-util"; -import { BankAccessApi, BankApi, HarnessExchangeBankAccount, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { + BankAccessApi, + BankApi, + HarnessExchangeBankAccount, + WalletApiOperation, +} from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "./denomStructures.js"; import { FaultInjectedExchangeService, @@ -117,14 +122,18 @@ export async function createSimpleTestkudosEnvironment( id: "default", name: "Default Instance", paytoUris: [getPayto("merchant-default")], - defaultWireTransferDelay: Duration.fromSpec({ minutes: 1 }), + defaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 1 }), + ), }); await merchant.addInstance({ id: "minst1", name: "minst1", paytoUris: [getPayto("minst1")], - defaultWireTransferDelay: Duration.fromSpec({ minutes: 1 }), + defaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 1 }), + ), }); console.log("setup done!"); diff --git a/packages/taler-wallet-cli/src/harness/merchantApiTypes.ts b/packages/taler-wallet-cli/src/harness/merchantApiTypes.ts index dcb1a2b42..35062b579 100644 --- a/packages/taler-wallet-cli/src/harness/merchantApiTypes.ts +++ b/packages/taler-wallet-cli/src/harness/merchantApiTypes.ts @@ -42,6 +42,7 @@ import { CoinPublicKeyString, EddsaPublicKeyString, codecForAmountString, + TalerProtocolDuration, } from "@gnu-taler/taler-util"; export interface PostOrderRequest { @@ -51,7 +52,7 @@ export interface PostOrderRequest { // if set, the backend will then set the refund deadline to the current // time plus the specified delay. - refund_delay?: Duration; + refund_delay?: TalerProtocolDuration; // specifies the payment target preferred by the client. Can be used // to select among the various (active) wire methods supported by the instance. @@ -79,44 +80,48 @@ export const codecForPostOrderResponse = (): Codec<PostOrderResponse> => .property("token", codecOptional(codecForString())) .build("PostOrderResponse"); -export const codecForCheckPaymentPaidResponse = (): Codec<CheckPaymentPaidResponse> => - buildCodecForObject<CheckPaymentPaidResponse>() - .property("order_status_url", codecForString()) - .property("order_status", codecForConstString("paid")) - .property("refunded", codecForBoolean()) - .property("wired", codecForBoolean()) - .property("deposit_total", codecForAmountString()) - .property("exchange_ec", codecForNumber()) - .property("exchange_hc", codecForNumber()) - .property("refund_amount", codecForAmountString()) - .property("contract_terms", codecForContractTerms()) - // FIXME: specify - .property("wire_details", codecForAny()) - .property("wire_reports", codecForAny()) - .property("refund_details", codecForAny()) - .build("CheckPaymentPaidResponse"); - -export const codecForCheckPaymentUnpaidResponse = (): Codec<CheckPaymentUnpaidResponse> => - buildCodecForObject<CheckPaymentUnpaidResponse>() - .property("order_status", codecForConstString("unpaid")) - .property("taler_pay_uri", codecForString()) - .property("order_status_url", codecForString()) - .property("already_paid_order_id", codecOptional(codecForString())) - .build("CheckPaymentPaidResponse"); - -export const codecForCheckPaymentClaimedResponse = (): Codec<CheckPaymentClaimedResponse> => - buildCodecForObject<CheckPaymentClaimedResponse>() - .property("order_status", codecForConstString("claimed")) - .property("contract_terms", codecForContractTerms()) - .build("CheckPaymentClaimedResponse"); - -export const codecForMerchantOrderPrivateStatusResponse = (): Codec<MerchantOrderPrivateStatusResponse> => - buildCodecForUnion<MerchantOrderPrivateStatusResponse>() - .discriminateOn("order_status") - .alternative("paid", codecForCheckPaymentPaidResponse()) - .alternative("unpaid", codecForCheckPaymentUnpaidResponse()) - .alternative("claimed", codecForCheckPaymentClaimedResponse()) - .build("MerchantOrderPrivateStatusResponse"); +export const codecForCheckPaymentPaidResponse = + (): Codec<CheckPaymentPaidResponse> => + buildCodecForObject<CheckPaymentPaidResponse>() + .property("order_status_url", codecForString()) + .property("order_status", codecForConstString("paid")) + .property("refunded", codecForBoolean()) + .property("wired", codecForBoolean()) + .property("deposit_total", codecForAmountString()) + .property("exchange_ec", codecForNumber()) + .property("exchange_hc", codecForNumber()) + .property("refund_amount", codecForAmountString()) + .property("contract_terms", codecForContractTerms()) + // FIXME: specify + .property("wire_details", codecForAny()) + .property("wire_reports", codecForAny()) + .property("refund_details", codecForAny()) + .build("CheckPaymentPaidResponse"); + +export const codecForCheckPaymentUnpaidResponse = + (): Codec<CheckPaymentUnpaidResponse> => + buildCodecForObject<CheckPaymentUnpaidResponse>() + .property("order_status", codecForConstString("unpaid")) + .property("taler_pay_uri", codecForString()) + .property("order_status_url", codecForString()) + .property("already_paid_order_id", codecOptional(codecForString())) + .build("CheckPaymentPaidResponse"); + +export const codecForCheckPaymentClaimedResponse = + (): Codec<CheckPaymentClaimedResponse> => + buildCodecForObject<CheckPaymentClaimedResponse>() + .property("order_status", codecForConstString("claimed")) + .property("contract_terms", codecForContractTerms()) + .build("CheckPaymentClaimedResponse"); + +export const codecForMerchantOrderPrivateStatusResponse = + (): Codec<MerchantOrderPrivateStatusResponse> => + buildCodecForUnion<MerchantOrderPrivateStatusResponse>() + .discriminateOn("order_status") + .alternative("paid", codecForCheckPaymentPaidResponse()) + .alternative("unpaid", codecForCheckPaymentUnpaidResponse()) + .alternative("claimed", codecForCheckPaymentClaimedResponse()) + .build("MerchantOrderPrivateStatusResponse"); export type MerchantOrderPrivateStatusResponse = | CheckPaymentPaidResponse |