adapt to corebank API change, minor refactoring
This commit is contained in:
parent
6b63ecc49e
commit
bdd906c887
@ -592,7 +592,9 @@ export async function withdrawViaBankV2(
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
|
||||
return {
|
||||
withdrawalFinishedCond,
|
||||
|
@ -331,7 +331,9 @@ export async function runKycTest(t: GlobalTestState) {
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
|
||||
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
|
||||
if (
|
||||
|
@ -153,7 +153,9 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
|
||||
await wallet.runUntilDone();
|
||||
|
||||
|
@ -161,7 +161,9 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
|
||||
await withdrawalFinishedReceivedPromise;
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
|
||||
await withdrawalBankConfirmedCond;
|
||||
|
||||
|
@ -152,7 +152,9 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) {
|
||||
|
||||
// Confirm it
|
||||
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop);
|
||||
await bankAccessApiClient.confirmWithdrawalOperation(user.username, {
|
||||
withdrawalOperationId: wop.withdrawal_id,
|
||||
});
|
||||
await wallet.runUntilDone();
|
||||
|
||||
// Check balance
|
||||
|
@ -223,6 +223,10 @@ export interface AccountData {
|
||||
cashout_payto_uri?: string;
|
||||
}
|
||||
|
||||
export interface ConfirmWithdrawalArgs {
|
||||
withdrawalOperationId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client for the Taler corebank API.
|
||||
*/
|
||||
@ -356,10 +360,10 @@ export class TalerCorebankApiClient {
|
||||
|
||||
async confirmWithdrawalOperation(
|
||||
username: string,
|
||||
wopi: WithdrawalOperationInfo,
|
||||
wopi: ConfirmWithdrawalArgs,
|
||||
): Promise<void> {
|
||||
const url = new URL(
|
||||
`accounts/${username}/withdrawals/${wopi.withdrawal_id}/confirm`,
|
||||
`withdrawals/${wopi.withdrawalOperationId}/confirm`,
|
||||
this.baseUrl,
|
||||
);
|
||||
logger.info(`confirming withdrawal operation via ${url.href}`);
|
||||
|
@ -142,7 +142,9 @@ export async function topupReserveWithDemobank(
|
||||
httpResp,
|
||||
codecForBankWithdrawalOperationPostResponse(),
|
||||
);
|
||||
await bankClient.confirmWithdrawalOperation(bankUser.username, wopi);
|
||||
await bankClient.confirmWithdrawalOperation(bankUser.username, {
|
||||
withdrawalOperationId: wopi.withdrawal_id,
|
||||
});
|
||||
}
|
||||
|
||||
export async function withdrawCoin(args: {
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
NotificationType,
|
||||
RegisterAccountRequest,
|
||||
stringToBytes,
|
||||
TalerCorebankApiClient,
|
||||
TestPayResult,
|
||||
TransactionMajorState,
|
||||
TransactionMinorState,
|
||||
@ -74,16 +75,6 @@ import { getTransactionById, getTransactions } from "./transactions.js";
|
||||
|
||||
const logger = new Logger("operations/testing.ts");
|
||||
|
||||
interface BankUser {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface BankWithdrawalResponse {
|
||||
taler_withdraw_uri: string;
|
||||
withdrawal_id: string;
|
||||
}
|
||||
|
||||
interface MerchantBackendInfo {
|
||||
baseUrl: string;
|
||||
authToken?: string;
|
||||
@ -103,16 +94,6 @@ function makeId(length: number): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate the "Authorization" HTTP header.
|
||||
* FIXME: redundant, put in taler-util
|
||||
*/
|
||||
function makeBasicAuthHeader(username: string, password: string): string {
|
||||
const auth = `${username}:${password}`;
|
||||
const authEncoded: string = base64FromArrayBuffer(stringToBytes(auth));
|
||||
return `Basic ${authEncoded}`;
|
||||
}
|
||||
|
||||
export async function withdrawTestBalance(
|
||||
ws: InternalWalletState,
|
||||
req: WithdrawTestBalanceRequest,
|
||||
@ -122,15 +103,18 @@ export async function withdrawTestBalance(
|
||||
const bankAccessApiBaseUrl = req.bankAccessApiBaseUrl;
|
||||
|
||||
logger.trace(
|
||||
`Registered bank user, bank access base url ${bankAccessApiBaseUrl}`,
|
||||
`Registering bank user, bank access base url ${bankAccessApiBaseUrl}`,
|
||||
);
|
||||
const bankUser = await registerRandomBankUser(ws.http, bankAccessApiBaseUrl);
|
||||
|
||||
const corebankClient = new TalerCorebankApiClient(bankAccessApiBaseUrl);
|
||||
|
||||
const bankUser = await corebankClient.createRandomBankUser();
|
||||
logger.trace(`Registered bank user ${JSON.stringify(bankUser)}`);
|
||||
|
||||
const wresp = await createDemoBankWithdrawalUri(
|
||||
ws.http,
|
||||
bankAccessApiBaseUrl,
|
||||
bankUser,
|
||||
corebankClient.setAuth(bankUser);
|
||||
|
||||
const wresp = await corebankClient.createWithdrawalOperation(
|
||||
bankUser.username,
|
||||
amount,
|
||||
);
|
||||
|
||||
@ -140,14 +124,14 @@ export async function withdrawTestBalance(
|
||||
forcedDenomSel: req.forcedDenomSel,
|
||||
});
|
||||
|
||||
await confirmBankWithdrawalUri(
|
||||
ws.http,
|
||||
bankAccessApiBaseUrl,
|
||||
bankUser,
|
||||
wresp.withdrawal_id,
|
||||
);
|
||||
await corebankClient.confirmWithdrawalOperation(bankUser.username, {
|
||||
withdrawalOperationId: wresp.withdrawal_id,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: User MerchantApiClient instead.
|
||||
*/
|
||||
function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> {
|
||||
if (m.authToken) {
|
||||
return {
|
||||
@ -158,88 +142,8 @@ function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the testing API of a demobank to create a taler://withdraw URI
|
||||
* that the wallet can then use to make a withdrawal.
|
||||
* FIXME: User MerchantApiClient instead.
|
||||
*/
|
||||
export async function createDemoBankWithdrawalUri(
|
||||
http: HttpRequestLibrary,
|
||||
bankAccessApiBaseUrl: string,
|
||||
bankUser: BankUser,
|
||||
amount: AmountString,
|
||||
): Promise<BankWithdrawalResponse> {
|
||||
const reqUrl = new URL(
|
||||
`accounts/${bankUser.username}/withdrawals`,
|
||||
bankAccessApiBaseUrl,
|
||||
).href;
|
||||
const resp = await http.postJson(
|
||||
reqUrl,
|
||||
{
|
||||
amount,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: makeBasicAuthHeader(
|
||||
bankUser.username,
|
||||
bankUser.password,
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
||||
return respJson;
|
||||
}
|
||||
|
||||
async function confirmBankWithdrawalUri(
|
||||
http: HttpRequestLibrary,
|
||||
bankAccessApiBaseUrl: string,
|
||||
bankUser: BankUser,
|
||||
withdrawalId: string,
|
||||
): Promise<void> {
|
||||
const reqUrl = new URL(
|
||||
`accounts/${bankUser.username}/withdrawals/${withdrawalId}/confirm`,
|
||||
bankAccessApiBaseUrl,
|
||||
).href;
|
||||
const resp = await http.postJson(
|
||||
reqUrl,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: makeBasicAuthHeader(
|
||||
bankUser.username,
|
||||
bankUser.password,
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
||||
return;
|
||||
}
|
||||
|
||||
async function registerRandomBankUser(
|
||||
http: HttpRequestLibrary,
|
||||
corebankApiBaseUrl: string,
|
||||
): Promise<BankUser> {
|
||||
const reqUrl = new URL("accounts", corebankApiBaseUrl).href;
|
||||
const randId = makeId(8);
|
||||
const username = `testuser-${randId.toLowerCase()}`;
|
||||
const password = `testpw-${randId}`;
|
||||
|
||||
const bankUser: BankUser = {
|
||||
username,
|
||||
password,
|
||||
};
|
||||
|
||||
const userReq: RegisterAccountRequest = {
|
||||
username,
|
||||
password,
|
||||
name: username,
|
||||
};
|
||||
|
||||
const resp = await http.fetch(reqUrl, { method: "POST", body: userReq });
|
||||
await checkSuccessResponseOrThrow(resp);
|
||||
return bankUser;
|
||||
}
|
||||
|
||||
async function refund(
|
||||
http: HttpRequestLibrary,
|
||||
merchantBackend: MerchantBackendInfo,
|
||||
@ -267,6 +171,9 @@ async function refund(
|
||||
return refundUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: User MerchantApiClient instead.
|
||||
*/
|
||||
async function createOrder(
|
||||
http: HttpRequestLibrary,
|
||||
merchantBackend: MerchantBackendInfo,
|
||||
@ -296,6 +203,9 @@ async function createOrder(
|
||||
return { orderId };
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: User MerchantApiClient instead.
|
||||
*/
|
||||
async function checkPayment(
|
||||
http: HttpRequestLibrary,
|
||||
merchantBackend: MerchantBackendInfo,
|
||||
@ -309,16 +219,6 @@ async function checkPayment(
|
||||
return readSuccessResponseJsonOrThrow(resp, codecForCheckPaymentResponse());
|
||||
}
|
||||
|
||||
interface BankUser {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface BankWithdrawalResponse {
|
||||
taler_withdraw_uri: string;
|
||||
withdrawal_id: string;
|
||||
}
|
||||
|
||||
async function makePayment(
|
||||
ws: InternalWalletState,
|
||||
merchant: MerchantBackendInfo,
|
||||
|
Loading…
Reference in New Issue
Block a user