From f180d0580457e1e9bd502293df327dfe138dd422 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 12 Aug 2020 12:41:00 +0530 Subject: remove excessive namespacing, format --- .../taler-integrationtests/src/faultInjection.ts | 2 +- packages/taler-integrationtests/src/harness.ts | 52 ++++++------ packages/taler-integrationtests/src/helpers.ts | 21 +++-- .../taler-integrationtests/src/merchantApiTypes.ts | 98 +++++++++++----------- .../src/scenario-prompt-payment.ts | 2 +- .../src/test-payment-fault.ts | 15 +++- .../src/test-payment-multiple.ts | 19 +++-- .../taler-integrationtests/src/test-payment.ts | 2 +- .../src/test-refund-incremental.ts | 2 +- packages/taler-integrationtests/src/test-refund.ts | 2 +- .../src/test-withdrawal-bank-integrated.ts | 7 +- .../src/test-withdrawal-manual.ts | 14 ++-- 12 files changed, 132 insertions(+), 104 deletions(-) (limited to 'packages/taler-integrationtests/src') diff --git a/packages/taler-integrationtests/src/faultInjection.ts b/packages/taler-integrationtests/src/faultInjection.ts index a9c249fd0..26bfeee53 100644 --- a/packages/taler-integrationtests/src/faultInjection.ts +++ b/packages/taler-integrationtests/src/faultInjection.ts @@ -144,7 +144,7 @@ export class FaultProxy { statusCode: proxyResp.statusCode!!, }; for (const faultSpec of this.currentFaultSpecs) { - const modResponse = faultSpec.modifyResponse; + const modResponse = faultSpec.modifyResponse; if (modResponse) { modResponse(faultRespContext); } diff --git a/packages/taler-integrationtests/src/harness.ts b/packages/taler-integrationtests/src/harness.ts index 2507d12f7..80cd1d906 100644 --- a/packages/taler-integrationtests/src/harness.ts +++ b/packages/taler-integrationtests/src/harness.ts @@ -32,21 +32,29 @@ import * as http from "http"; import { ChildProcess, spawn } from "child_process"; import { Configuration, - walletCoreApi, - codec, AmountJson, Amounts, + Codec, + makeCodecForObject, + codecForString, + Duration, + CoreApiResponse, } from "taler-wallet-core"; import { URL } from "url"; import axios from "axios"; -import { talerCrypto, time } from "taler-wallet-core"; import { codecForMerchantOrderPrivateStatusResponse, codecForPostOrderResponse, PostOrderRequest, PostOrderResponse, } from "./merchantApiTypes"; -import { EddsaKeyPair } from "taler-wallet-core/lib/crypto/talerCrypto"; +import { + EddsaKeyPair, + getRandomBytes, + encodeCrock, + eddsaGetPublic, + createEddsaKeyPair, +} from "taler-wallet-core/lib/crypto/talerCrypto"; const exec = util.promisify(require("child_process").exec); @@ -540,11 +548,10 @@ export class BankService { } async createRandomBankUser(): Promise { - const username = - "user-" + talerCrypto.encodeCrock(talerCrypto.getRandomBytes(10)); + const username = "user-" + encodeCrock(getRandomBytes(10)); const bankUser: BankUser = { username, - password: "pw-" + talerCrypto.encodeCrock(talerCrypto.getRandomBytes(10)), + password: "pw-" + encodeCrock(getRandomBytes(10)), accountPaytoUri: `payto://x-taler-bank/localhost/${username}`, }; await this.createAccount(bankUser.username, bankUser.password); @@ -617,13 +624,10 @@ export interface WithdrawalOperationInfo { taler_withdraw_uri: string; } -const codecForWithdrawalOperationInfo = (): codec.Codec< - WithdrawalOperationInfo -> => - codec - .makeCodecForObject() - .property("withdrawal_id", codec.codecForString) - .property("taler_withdraw_uri", codec.codecForString) +const codecForWithdrawalOperationInfo = (): Codec => + makeCodecForObject() + .property("withdrawal_id", codecForString) + .property("taler_withdraw_uri", codecForString) .build("WithdrawalOperationInfo"); export const defaultCoinConfig = [ @@ -666,7 +670,7 @@ export class ExchangeService implements ExchangeServiceInterface { const eddsaPriv = fs.readFileSync(privFile); const keyPair: EddsaKeyPair = { eddsaPriv, - eddsaPub: talerCrypto.eddsaGetPublic(eddsaPriv), + eddsaPub: eddsaGetPublic(eddsaPriv), }; return new ExchangeService(gc, ec, cfgFilename, keyPair); } @@ -728,12 +732,12 @@ export class ExchangeService implements ExchangeServiceInterface { config.setString("exchangedb-postgres", "config", e.database); - const exchangeMasterKey = talerCrypto.createEddsaKeyPair(); + const exchangeMasterKey = createEddsaKeyPair(); config.setString( "exchange", "master_public_key", - talerCrypto.encodeCrock(exchangeMasterKey.eddsaPub), + encodeCrock(exchangeMasterKey.eddsaPub), ); const masterPrivFile = config @@ -758,7 +762,7 @@ export class ExchangeService implements ExchangeServiceInterface { } get masterPub() { - return talerCrypto.encodeCrock(this.keyPair.eddsaPub); + return encodeCrock(this.keyPair.eddsaPub); } get port() { @@ -812,7 +816,7 @@ export class ExchangeService implements ExchangeServiceInterface { private globalState: GlobalTestState, private exchangeConfig: ExchangeConfig, private configFilename: string, - private keyPair: talerCrypto.EddsaKeyPair, + private keyPair: EddsaKeyPair, ) {} get name() { @@ -983,7 +987,7 @@ export class MerchantService { }); return { talerRefundUri: resp.data.taler_refund_uri, - } + }; } async createOrder( @@ -1015,8 +1019,8 @@ export interface MerchantInstanceConfig { defaultMaxWireFee?: string; defaultMaxDepositFee?: string; defaultWireFeeAmortization?: number; - defaultWireTransferDelay?: time.Duration; - defaultPayDelay?: time.Duration; + defaultWireTransferDelay?: Duration; + defaultPayDelay?: Duration; } /** @@ -1106,7 +1110,7 @@ export class WalletCli { async apiRequest( request: string, payload: Record, - ): Promise { + ): Promise { const wdb = this.globalTestState.testDir + "/walletdb.json"; const resp = await sh( this.globalTestState, @@ -1116,7 +1120,7 @@ export class WalletCli { )}`, ); console.log(resp); - return JSON.parse(resp) as walletCoreApi.CoreApiResponse; + return JSON.parse(resp) as CoreApiResponse; } async runUntilDone(): Promise { diff --git a/packages/taler-integrationtests/src/helpers.ts b/packages/taler-integrationtests/src/helpers.ts index 41cd39d77..b37b6b96c 100644 --- a/packages/taler-integrationtests/src/helpers.ts +++ b/packages/taler-integrationtests/src/helpers.ts @@ -75,7 +75,10 @@ export async function createSimpleTestkudosEnvironment( database: db.connStr, }); - const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x"); + const exchangeBankAccount = await bank.createExchangeAccount( + "MyExchange", + "x", + ); exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); @@ -123,13 +126,15 @@ export async function createSimpleTestkudosEnvironment( /** * Withdraw balance. */ -export async function withdrawViaBank(t: GlobalTestState, p: { - wallet: WalletCli; - bank: BankService; - exchange: ExchangeService; - amount: AmountString; -}): Promise { - +export async function withdrawViaBank( + t: GlobalTestState, + p: { + wallet: WalletCli; + bank: BankService; + exchange: ExchangeService; + amount: AmountString; + }, +): Promise { const { wallet, bank, exchange, amount } = p; const user = await bank.createRandomBankUser(); diff --git a/packages/taler-integrationtests/src/merchantApiTypes.ts b/packages/taler-integrationtests/src/merchantApiTypes.ts index fe70c356c..3c0965813 100644 --- a/packages/taler-integrationtests/src/merchantApiTypes.ts +++ b/packages/taler-integrationtests/src/merchantApiTypes.ts @@ -22,23 +22,34 @@ */ /** - * Imports + * Imports. */ import { - codec, - talerTypes, - time, + ContractTerms, + Duration, + Codec, + makeCodecForObject, + codecForString, + makeCodecOptional, + makeCodecForConstString, + codecForBoolean, + codecForNumber, + codecForContractTerms, + codecForAny, + makeCodecForUnion, + AmountString, + Timestamp, + CoinPublicKeyString, } from "taler-wallet-core"; - export interface PostOrderRequest { // The order must at least contain the minimal // order detail, but can override all - order: Partial; + order: Partial; // if set, the backend will then set the refund deadline to the current // time plus the specified delay. - refund_delay?: time.Duration; + refund_delay?: Duration; // specifies the payment target preferred by the client. Can be used // to select among the various (active) wire methods supported by the instance. @@ -60,51 +71,44 @@ export interface PostOrderResponse { token?: ClaimToken; } -export const codecForPostOrderResponse = (): codec.Codec => - codec - .makeCodecForObject() - .property("order_id", codec.codecForString) - .property("token", codec.makeCodecOptional(codec.codecForString)) +export const codecForPostOrderResponse = (): Codec => + makeCodecForObject() + .property("order_id", codecForString) + .property("token", makeCodecOptional(codecForString)) .build("PostOrderResponse"); -export const codecForCheckPaymentPaidResponse = (): codec.Codec< +export const codecForCheckPaymentPaidResponse = (): Codec< CheckPaymentPaidResponse > => - codec - .makeCodecForObject() - .property("order_status", codec.makeCodecForConstString("paid")) - .property("refunded", codec.codecForBoolean) - .property("wired", codec.codecForBoolean) - .property("deposit_total", codec.codecForString) - .property("exchange_ec", codec.codecForNumber) - .property("exchange_hc", codec.codecForNumber) - .property("refund_amount", codec.codecForString) - .property("contract_terms", talerTypes.codecForContractTerms()) + makeCodecForObject() + .property("order_status", makeCodecForConstString("paid")) + .property("refunded", codecForBoolean) + .property("wired", codecForBoolean) + .property("deposit_total", codecForString) + .property("exchange_ec", codecForNumber) + .property("exchange_hc", codecForNumber) + .property("refund_amount", codecForString) + .property("contract_terms", codecForContractTerms()) // FIXME: specify - .property("wire_details", codec.codecForAny) - .property("wire_reports", codec.codecForAny) - .property("refund_details", codec.codecForAny) + .property("wire_details", codecForAny) + .property("wire_reports", codecForAny) + .property("refund_details", codecForAny) .build("CheckPaymentPaidResponse"); -export const codecForCheckPaymentUnpaidResponse = (): codec.Codec< +export const codecForCheckPaymentUnpaidResponse = (): Codec< CheckPaymentUnpaidResponse > => - codec - .makeCodecForObject() - .property("order_status", codec.makeCodecForConstString("unpaid")) - .property("taler_pay_uri", codec.codecForString) - .property("order_status_url", codec.codecForString) - .property( - "already_paid_order_id", - codec.makeCodecOptional(codec.codecForString), - ) + makeCodecForObject() + .property("order_status", makeCodecForConstString("unpaid")) + .property("taler_pay_uri", codecForString) + .property("order_status_url", codecForString) + .property("already_paid_order_id", makeCodecOptional(codecForString)) .build("CheckPaymentPaidResponse"); -export const codecForMerchantOrderPrivateStatusResponse = (): codec.Codec< +export const codecForMerchantOrderPrivateStatusResponse = (): Codec< MerchantOrderPrivateStatusResponse > => - codec - .makeCodecForUnion() + makeCodecForUnion() .discriminateOn("order_status") .alternative("paid", codecForCheckPaymentPaidResponse()) .alternative("unpaid", codecForCheckPaymentUnpaidResponse()) @@ -126,7 +130,7 @@ export interface CheckPaymentPaidResponse { // Total amount the exchange deposited into our bank account // for this contract, excluding fees. - deposit_total: talerTypes.AmountString; + deposit_total: AmountString; // Numeric error code indicating errors the exchange // encountered tracking the wire transfer for this purchase (before @@ -140,10 +144,10 @@ export interface CheckPaymentPaidResponse { exchange_hc: number; // Total amount that was refunded, 0 if refunded is false. - refund_amount: talerTypes.AmountString; + refund_amount: AmountString; // Contract terms - contract_terms: talerTypes.ContractTerms; + contract_terms: ContractTerms; // Ihe wire transfer status from the exchange for this order if available, otherwise empty array wire_details: TransactionWireTransfer[]; @@ -177,10 +181,10 @@ export interface RefundDetails { reason: string; // when was the refund approved - timestamp: time.Timestamp; + timestamp: Timestamp; // Total amount that was refunded (minus a refund fee). - amount: talerTypes.AmountString; + amount: AmountString; } export interface TransactionWireTransfer { @@ -191,11 +195,11 @@ export interface TransactionWireTransfer { wtid: string; // execution time of the wire transfer - execution_time: time.Timestamp; + execution_time: Timestamp; // Total amount that has been wire transfered // to the merchant - amount: talerTypes.AmountString; + amount: AmountString; // Was this transfer confirmed by the merchant via the // POST /transfers API, or is it merely claimed by the exchange? @@ -216,5 +220,5 @@ export interface TransactionWireReport { exchange_hc: number; // Public key of the coin for which we got the exchange error. - coin_pub: talerTypes.CoinPublicKeyString; + coin_pub: CoinPublicKeyString; } diff --git a/packages/taler-integrationtests/src/scenario-prompt-payment.ts b/packages/taler-integrationtests/src/scenario-prompt-payment.ts index 615ed5778..f60c6704d 100644 --- a/packages/taler-integrationtests/src/scenario-prompt-payment.ts +++ b/packages/taler-integrationtests/src/scenario-prompt-payment.ts @@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => { orderResp.order_id, ); - t.assertTrue(orderStatus.order_status === "unpaid") + t.assertTrue(orderStatus.order_status === "unpaid"); console.log(orderStatus); diff --git a/packages/taler-integrationtests/src/test-payment-fault.ts b/packages/taler-integrationtests/src/test-payment-fault.ts index 0db6770bf..2ee5c7055 100644 --- a/packages/taler-integrationtests/src/test-payment-fault.ts +++ b/packages/taler-integrationtests/src/test-payment-fault.ts @@ -31,7 +31,11 @@ import { WalletCli, defaultCoinConfig, } from "./harness"; -import { FaultInjectedExchangeService, FaultInjectionRequestContext, FaultInjectionResponseContext } from "./faultInjection"; +import { + FaultInjectedExchangeService, + FaultInjectionRequestContext, + FaultInjectionResponseContext, +} from "./faultInjection"; import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler"; /** @@ -56,7 +60,10 @@ runTest(async (t: GlobalTestState) => { database: db.connStr, }); - const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x"); + const exchangeBankAccount = await bank.createExchangeAccount( + "MyExchange", + "x", + ); bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); @@ -79,7 +86,7 @@ runTest(async (t: GlobalTestState) => { }, modifyResponse(ctx: FaultInjectionResponseContext) { console.log("got response", ctx); - } + }, }); const merchant = await MerchantService.create(t, { @@ -174,7 +181,7 @@ runTest(async (t: GlobalTestState) => { faultCount++; ctx.dropResponse = true; } - } + }, }); // confirmPay won't work, as the exchange is unreachable diff --git a/packages/taler-integrationtests/src/test-payment-multiple.ts b/packages/taler-integrationtests/src/test-payment-multiple.ts index 5bbeecbd9..80092a9a3 100644 --- a/packages/taler-integrationtests/src/test-payment-multiple.ts +++ b/packages/taler-integrationtests/src/test-payment-multiple.ts @@ -30,10 +30,12 @@ import { } from "./harness"; import { withdrawViaBank } from "./helpers"; -async function setupTest(t: GlobalTestState): Promise<{ - merchant: MerchantService, - exchange: ExchangeService, - bank: BankService, +async function setupTest( + t: GlobalTestState, +): Promise<{ + merchant: MerchantService; + exchange: ExchangeService; + bank: BankService; }> { const db = await setupDb(t); @@ -51,7 +53,10 @@ async function setupTest(t: GlobalTestState): Promise<{ database: db.connStr, }); - const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x"); + const exchangeBankAccount = await bank.createExchangeAccount( + "MyExchange", + "x", + ); exchange.addOfferedCoins([coin_ct10, coin_u1]); @@ -96,12 +101,12 @@ async function setupTest(t: GlobalTestState): Promise<{ merchant, bank, exchange, - } + }; } /** * Run test. - * + * * This test uses a very sub-optimal denomination structure. */ runTest(async (t: GlobalTestState) => { diff --git a/packages/taler-integrationtests/src/test-payment.ts b/packages/taler-integrationtests/src/test-payment.ts index cfe65a6f8..3fd879580 100644 --- a/packages/taler-integrationtests/src/test-payment.ts +++ b/packages/taler-integrationtests/src/test-payment.ts @@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => { orderResp.order_id, ); - t.assertTrue(orderStatus.order_status === "unpaid") + t.assertTrue(orderStatus.order_status === "unpaid"); // Make wallet pay for the order diff --git a/packages/taler-integrationtests/src/test-refund-incremental.ts b/packages/taler-integrationtests/src/test-refund-incremental.ts index 29685dd3e..0667b10d8 100644 --- a/packages/taler-integrationtests/src/test-refund-incremental.ts +++ b/packages/taler-integrationtests/src/test-refund-incremental.ts @@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => { orderResp.order_id, ); - t.assertTrue(orderStatus.order_status === "unpaid") + t.assertTrue(orderStatus.order_status === "unpaid"); // Make wallet pay for the order diff --git a/packages/taler-integrationtests/src/test-refund.ts b/packages/taler-integrationtests/src/test-refund.ts index c2f152f53..e1fdbfc50 100644 --- a/packages/taler-integrationtests/src/test-refund.ts +++ b/packages/taler-integrationtests/src/test-refund.ts @@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => { orderResp.order_id, ); - t.assertTrue(orderStatus.order_status === "unpaid") + t.assertTrue(orderStatus.order_status === "unpaid"); // Make wallet pay for the order diff --git a/packages/taler-integrationtests/src/test-withdrawal-bank-integrated.ts b/packages/taler-integrationtests/src/test-withdrawal-bank-integrated.ts index a856560dc..46ccdaaed 100644 --- a/packages/taler-integrationtests/src/test-withdrawal-bank-integrated.ts +++ b/packages/taler-integrationtests/src/test-withdrawal-bank-integrated.ts @@ -19,13 +19,12 @@ */ import { runTest, GlobalTestState } from "./harness"; import { createSimpleTestkudosEnvironment } from "./helpers"; -import { walletTypes } from "taler-wallet-core"; +import { codecForBalancesResponse } from "taler-wallet-core"; /** * Run test for basic, bank-integrated withdrawal. */ runTest(async (t: GlobalTestState) => { - // Set up test environment const { wallet, bank, exchange } = await createSimpleTestkudosEnvironment(t); @@ -61,8 +60,8 @@ runTest(async (t: GlobalTestState) => { const balApiResp = await wallet.apiRequest("getBalances", {}); t.assertTrue(balApiResp.type === "response"); - const balResp = walletTypes.codecForBalancesResponse().decode(balApiResp.result); - t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available) + const balResp = codecForBalancesResponse().decode(balApiResp.result); + t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available); await t.shutdown(); }); diff --git a/packages/taler-integrationtests/src/test-withdrawal-manual.ts b/packages/taler-integrationtests/src/test-withdrawal-manual.ts index afaf41e63..0d09c3e5c 100644 --- a/packages/taler-integrationtests/src/test-withdrawal-manual.ts +++ b/packages/taler-integrationtests/src/test-withdrawal-manual.ts @@ -19,17 +19,21 @@ */ import { runTest, GlobalTestState } from "./harness"; import { createSimpleTestkudosEnvironment } from "./helpers"; -import { walletTypes } from "taler-wallet-core"; import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler"; +import { codecForBalancesResponse } from "taler-wallet-core"; /** * Run test for basic, bank-integrated withdrawal. */ runTest(async (t: GlobalTestState) => { - // Set up test environment - const { wallet, bank, exchange, exchangeBankAccount } = await createSimpleTestkudosEnvironment(t); + const { + wallet, + bank, + exchange, + exchangeBankAccount, + } = await createSimpleTestkudosEnvironment(t); // Create a withdrawal operation @@ -67,8 +71,8 @@ runTest(async (t: GlobalTestState) => { const balApiResp = await wallet.apiRequest("getBalances", {}); t.assertTrue(balApiResp.type === "response"); - const balResp = walletTypes.codecForBalancesResponse().decode(balApiResp.result); - t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available) + const balResp = codecForBalancesResponse().decode(balApiResp.result); + t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available); await t.shutdown(); }); -- cgit v1.2.3