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 | |
parent | 5d23eb36354d07508a015531f298b3e261bbafce (diff) |
wallet: more time format fixes
12 files changed, 182 insertions, 129 deletions
diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts index 43cb7ad4d..344bc0f74 100644 --- a/packages/taler-util/src/time.ts +++ b/packages/taler-util/src/time.ts @@ -101,6 +101,9 @@ export namespace Duration { export function getForever(): Duration { return { d_ms: "forever" }; } + export function getZero(): Duration { + return { d_ms: 0 }; + } export function fromTalerProtocolDuration( d: TalerProtocolDuration, ): Duration { @@ -113,6 +116,16 @@ export namespace Duration { d_ms: d.d_us / 1000, }; } + export function toTalerProtocolDuration(d: Duration): TalerProtocolDuration { + if (d.d_ms === "forever") { + return { + d_us: "forever", + }; + } + return { + d_us: d.d_ms * 1000, + }; + } } export namespace AbsoluteTime { 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 diff --git a/packages/taler-wallet-cli/src/integrationtests/test-clause-schnorr.ts b/packages/taler-wallet-cli/src/integrationtests/test-clause-schnorr.ts index c8b4176d5..5a84866ac 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-clause-schnorr.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-clause-schnorr.ts @@ -53,12 +53,8 @@ export async function runClauseSchnorrTest(t: GlobalTestState) { name: "rsa_dummy", }); - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t, coinConfig); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t, coinConfig); // Withdraw digital cash into the wallet. @@ -98,3 +94,4 @@ export async function runClauseSchnorrTest(t: GlobalTestState) { } runClauseSchnorrTest.suites = ["wallet"]; +runClauseSchnorrTest.excludeByDefault = true; diff --git a/packages/taler-wallet-cli/src/integrationtests/test-libeufin-basic.ts b/packages/taler-wallet-cli/src/integrationtests/test-libeufin-basic.ts index 8f7d77712..aa5d4c9c0 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-libeufin-basic.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-libeufin-basic.ts @@ -20,6 +20,8 @@ import { AbsoluteTime, ContractTerms, + Duration, + durationFromSpec, } from "@gnu-taler/taler-util"; import { WalletApiOperation, @@ -209,7 +211,9 @@ export async function createLibeufinTestEnvironment( id: "default", name: "Default Instance", paytoUris: [`payto://iban/${merchantIban}?receiver-name=Merchant`], - defaultWireTransferDelay: { d_ms: 0 }, + defaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.getZero(), + ), }); console.log("setup done!"); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances-urls.ts b/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances-urls.ts index 6f76e2325..f72189014 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances-urls.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances-urls.ts @@ -17,6 +17,7 @@ /** * Imports. */ +import { Duration } from "@gnu-taler/taler-util"; import axios from "axios"; import { ExchangeService, @@ -24,7 +25,7 @@ import { MerchantApiClient, MerchantService, setupDb, - getPayto + getPayto, } from "../harness/harness.js"; /** @@ -67,9 +68,13 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) { address: {}, default_max_deposit_fee: "TESTKUDOS:1", default_max_wire_fee: "TESTKUDOS:1", - default_pay_delay: { d_ms: 60000 }, + default_pay_delay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ seconds: 60 }), + ), default_wire_fee_amortization: 1, - default_wire_transfer_delay: { d_ms: 60000 }, + default_wire_transfer_delay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ seconds: 60 }), + ), jurisdiction: {}, name: "My Default Instance", payto_uris: [getPayto("bar")], @@ -84,9 +89,13 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) { address: {}, default_max_deposit_fee: "TESTKUDOS:1", default_max_wire_fee: "TESTKUDOS:1", - default_pay_delay: { d_ms: 60000 }, + default_pay_delay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ seconds: 60 }), + ), default_wire_fee_amortization: 1, - default_wire_transfer_delay: { d_ms: 60000 }, + default_wire_transfer_delay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ seconds: 60 }), + ), jurisdiction: {}, name: "My Second Instance", payto_uris: [getPayto("bar")], diff --git a/packages/taler-wallet-cli/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-wallet-cli/src/integrationtests/test-merchant-refund-api.ts index a9dbeef9a..539904f1c 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-merchant-refund-api.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-merchant-refund-api.ts @@ -32,6 +32,7 @@ import { URL, durationFromSpec, PreparePayResultType, + Duration, } from "@gnu-taler/taler-util"; import axios from "axios"; import { @@ -57,7 +58,9 @@ async function testRefundApiWithFulfillmentUrl( amount: "TESTKUDOS:5", fulfillment_url: "https://example.com/fulfillment", }, - refund_delay: durationFromSpec({ minutes: 5 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 5 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { @@ -171,7 +174,9 @@ async function testRefundApiWithFulfillmentMessage( amount: "TESTKUDOS:5", fulfillment_message: "Thank you for buying foobar", }, - refund_delay: durationFromSpec({ minutes: 5 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 5 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { diff --git a/packages/taler-wallet-cli/src/integrationtests/test-refund-auto.ts b/packages/taler-wallet-cli/src/integrationtests/test-refund-auto.ts index 574177c8c..4c2a2f94a 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-refund-auto.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-refund-auto.ts @@ -22,7 +22,7 @@ import { createSimpleTestkudosEnvironment, withdrawViaBank, } from "../harness/helpers.js"; -import { durationFromSpec } from "@gnu-taler/taler-util"; +import { Duration, durationFromSpec } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; /** @@ -48,7 +48,9 @@ export async function runRefundAutoTest(t: GlobalTestState) { d_us: 3000 * 1000, }, }, - refund_delay: durationFromSpec({ minutes: 5 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 5 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { diff --git a/packages/taler-wallet-cli/src/integrationtests/test-refund-gone.ts b/packages/taler-wallet-cli/src/integrationtests/test-refund-gone.ts index 24600384b..b6cefda86 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-refund-gone.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-refund-gone.ts @@ -25,6 +25,7 @@ import { } from "../harness/helpers.js"; import { AbsoluteTime, + Duration, durationFromSpec, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -35,12 +36,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; export async function runRefundGoneTest(t: GlobalTestState) { // Set up test environment - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t); // Withdraw digital cash into the wallet. @@ -62,7 +59,9 @@ export async function runRefundGoneTest(t: GlobalTestState) { ), ), }, - refund_delay: durationFromSpec({ minutes: 1 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 1 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { diff --git a/packages/taler-wallet-cli/src/integrationtests/test-refund-incremental.ts b/packages/taler-wallet-cli/src/integrationtests/test-refund-incremental.ts index 47c2293e2..e4e96a180 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-refund-incremental.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-refund-incremental.ts @@ -17,12 +17,20 @@ /** * Imports. */ -import { GlobalTestState, delayMs, MerchantPrivateApi } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js"; +import { + GlobalTestState, + delayMs, + MerchantPrivateApi, +} from "../harness/harness.js"; +import { + createSimpleTestkudosEnvironment, + withdrawViaBank, +} from "../harness/helpers.js"; import { TransactionType, Amounts, durationFromSpec, + Duration, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -32,12 +40,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; export async function runRefundIncrementalTest(t: GlobalTestState) { // Set up test environment - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t); // Withdraw digital cash into the wallet. @@ -51,7 +55,9 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { amount: "TESTKUDOS:10", fulfillment_url: "taler://fulfillment-success/thx", }, - refund_delay: durationFromSpec({ minutes: 5 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 5 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { diff --git a/packages/taler-wallet-cli/src/integrationtests/test-refund.ts b/packages/taler-wallet-cli/src/integrationtests/test-refund.ts index f11771922..b63dad590 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-refund.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-refund.ts @@ -17,10 +17,13 @@ /** * Imports. */ -import { durationFromSpec } from "@gnu-taler/taler-util"; +import { Duration, durationFromSpec } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js"; +import { + createSimpleTestkudosEnvironment, + withdrawViaBank, +} from "../harness/helpers.js"; /** * Run test for basic, bank-integrated withdrawal. @@ -28,12 +31,8 @@ import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/he export async function runRefundTest(t: GlobalTestState) { // Set up test environment - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t); // Withdraw digital cash into the wallet. @@ -47,7 +46,9 @@ export async function runRefundTest(t: GlobalTestState) { amount: "TESTKUDOS:5", fulfillment_url: "taler://fulfillment-success/thx", }, - refund_delay: durationFromSpec({ minutes: 5 }), + refund_delay: Duration.toTalerProtocolDuration( + durationFromSpec({ minutes: 5 }), + ), }); let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { |