wallet: more time format fixes
This commit is contained in:
parent
5d23eb3635
commit
739c2f9337
@ -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 {
|
||||
|
@ -24,26 +24,23 @@
|
||||
/**
|
||||
* 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";
|
||||
AmountJson,
|
||||
Amounts,
|
||||
AmountString,
|
||||
Configuration,
|
||||
CoreApiResponse,
|
||||
createEddsaKeyPair,
|
||||
Duration,
|
||||
eddsaGetPublic,
|
||||
EddsaKeyPair,
|
||||
encodeCrock,
|
||||
hash,
|
||||
j2s,
|
||||
parsePaytoUri,
|
||||
stringToBytes,
|
||||
TalerProtocolDuration,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import {
|
||||
BankServiceHandle,
|
||||
HarnessExchangeBankAccount,
|
||||
@ -52,28 +49,28 @@ import {
|
||||
TalerError,
|
||||
WalletCoreApiClient,
|
||||
} from "@gnu-taler/taler-wallet-core";
|
||||
import {
|
||||
AmountJson,
|
||||
Amounts,
|
||||
Configuration,
|
||||
AmountString,
|
||||
Codec,
|
||||
buildCodecForObject,
|
||||
codecForString,
|
||||
Duration,
|
||||
parsePaytoUri,
|
||||
CoreApiResponse,
|
||||
createEddsaKeyPair,
|
||||
eddsaGetPublic,
|
||||
EddsaKeyPair,
|
||||
encodeCrock,
|
||||
getRandomBytes,
|
||||
hash,
|
||||
stringToBytes,
|
||||
j2s,
|
||||
} from "@gnu-taler/taler-util";
|
||||
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.toTalerProtocolDuration(
|
||||
Duration.fromSpec({
|
||||
days: 1,
|
||||
}),
|
||||
default_pay_delay: instanceConfig.defaultPayDelay ?? { d_ms: "forever" },
|
||||
});
|
||||
),
|
||||
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";
|
||||
|
@ -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!");
|
||||
|
@ -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,7 +80,8 @@ export const codecForPostOrderResponse = (): Codec<PostOrderResponse> =>
|
||||
.property("token", codecOptional(codecForString()))
|
||||
.build("PostOrderResponse");
|
||||
|
||||
export const codecForCheckPaymentPaidResponse = (): Codec<CheckPaymentPaidResponse> =>
|
||||
export const codecForCheckPaymentPaidResponse =
|
||||
(): Codec<CheckPaymentPaidResponse> =>
|
||||
buildCodecForObject<CheckPaymentPaidResponse>()
|
||||
.property("order_status_url", codecForString())
|
||||
.property("order_status", codecForConstString("paid"))
|
||||
@ -96,7 +98,8 @@ export const codecForCheckPaymentPaidResponse = (): Codec<CheckPaymentPaidRespon
|
||||
.property("refund_details", codecForAny())
|
||||
.build("CheckPaymentPaidResponse");
|
||||
|
||||
export const codecForCheckPaymentUnpaidResponse = (): Codec<CheckPaymentUnpaidResponse> =>
|
||||
export const codecForCheckPaymentUnpaidResponse =
|
||||
(): Codec<CheckPaymentUnpaidResponse> =>
|
||||
buildCodecForObject<CheckPaymentUnpaidResponse>()
|
||||
.property("order_status", codecForConstString("unpaid"))
|
||||
.property("taler_pay_uri", codecForString())
|
||||
@ -104,13 +107,15 @@ export const codecForCheckPaymentUnpaidResponse = (): Codec<CheckPaymentUnpaidRe
|
||||
.property("already_paid_order_id", codecOptional(codecForString()))
|
||||
.build("CheckPaymentPaidResponse");
|
||||
|
||||
export const codecForCheckPaymentClaimedResponse = (): Codec<CheckPaymentClaimedResponse> =>
|
||||
export const codecForCheckPaymentClaimedResponse =
|
||||
(): Codec<CheckPaymentClaimedResponse> =>
|
||||
buildCodecForObject<CheckPaymentClaimedResponse>()
|
||||
.property("order_status", codecForConstString("claimed"))
|
||||
.property("contract_terms", codecForContractTerms())
|
||||
.build("CheckPaymentClaimedResponse");
|
||||
|
||||
export const codecForMerchantOrderPrivateStatusResponse = (): Codec<MerchantOrderPrivateStatusResponse> =>
|
||||
export const codecForMerchantOrderPrivateStatusResponse =
|
||||
(): Codec<MerchantOrderPrivateStatusResponse> =>
|
||||
buildCodecForUnion<MerchantOrderPrivateStatusResponse>()
|
||||
.discriminateOn("order_status")
|
||||
.alternative("paid", codecForCheckPaymentPaidResponse())
|
||||
|
@ -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;
|
||||
|
@ -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!");
|
||||
|
@ -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")],
|
||||
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
Loading…
Reference in New Issue
Block a user