-fix test-exchange-deposit

This commit is contained in:
Florian Dold 2023-04-22 22:17:08 +02:00
parent 15a1b8d096
commit 321252040e
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 96 additions and 49 deletions

View File

@ -17,7 +17,11 @@
/**
* Imports.
*/
import { BankApi, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import {
BankApi,
WalletApiOperation,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
import { defaultCoinConfig } from "../harness/denomStructures.js";
import {
getWireMethodForTest,
@ -158,10 +162,15 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
exchangeBankAccount.accountPaytoUri,
);
await BankApi.adminAddIncoming(bank, {
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
});
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",
debitAccountPayto: mbu.accountPaytoUri,
exchangeBankAccount,
reservePub: tipReserveResp.reserve_pub,
});

View File

@ -32,6 +32,7 @@ import {
BankApi,
BankAccessApi,
CreditDebitIndicator,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
/**
@ -121,10 +122,15 @@ export async function runBankApiTest(t: GlobalTestState) {
const res = createEddsaKeyPair();
await BankApi.adminAddIncoming(bank, {
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
});
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:115",
debitAccountPayto: bankUser.accountPaytoUri,
exchangeBankAccount: exchangeBankAccount,
reservePub: encodeCrock(res.eddsaPub),
});

View File

@ -59,14 +59,13 @@ export async function runExchangeDepositTest(t: GlobalTestState) {
const reserveKeyPair = await cryptoApi.createEddsaKeypair({});
await topupReserveWithDemobank(
await topupReserveWithDemobank({
http,
reserveKeyPair.pub,
bank.baseUrl,
bank.bankAccessApiBaseUrl,
amount: "TESTKUDOS:10",
bankAccessApiBaseUrl: bank.bankAccessApiBaseUrl,
exchangeInfo,
"TESTKUDOS:10",
);
reservePub: reserveKeyPair.pub,
});
await exchange.runWirewatchOnce();
@ -126,7 +125,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) {
});
} catch (e) {
if (e instanceof TalerError && e.errorDetail.code === 7005) {
if (e.errorDetail.httpStatusCode === 400) {
if (e.errorDetail.httpStatusCode === 409) {
console.log("got expected error response from exchange");
console.log(e);
console.log(j2s(e.errorDetail));

View File

@ -17,7 +17,11 @@
/**
* Imports.
*/
import { WalletApiOperation, BankApi } from "@gnu-taler/taler-wallet-core";
import {
WalletApiOperation,
BankApi,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
import {
GlobalTestState,
MerchantPrivateApi,
@ -53,10 +57,15 @@ export async function runTippingTest(t: GlobalTestState) {
exchangeBankAccount.accountPaytoUri,
);
await BankApi.adminAddIncoming(bank, {
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
});
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",
debitAccountPayto: mbu.accountPaytoUri,
exchangeBankAccount,
reservePub: tipReserveResp.reserve_pub,
});

View File

@ -19,7 +19,11 @@
*/
import { GlobalTestState } from "../harness/harness.js";
import { createSimpleTestkudosEnvironment } from "../harness/helpers.js";
import { WalletApiOperation, BankApi } from "@gnu-taler/taler-wallet-core";
import {
WalletApiOperation,
BankApi,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
import { AbsoluteTime, j2s, Logger } from "@gnu-taler/taler-util";
const logger = new Logger("test-withdrawal-manual.ts");
@ -65,8 +69,13 @@ export async function runWithdrawalManualTest(t: GlobalTestState) {
const reservePub: string = wres.reservePub;
await BankApi.adminAddIncoming(bank, {
exchangeBankAccount,
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
});
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",
debitAccountPayto: user.accountPaytoUri,
reservePub: reservePub,

View File

@ -37,6 +37,7 @@ import {
TalerErrorCode,
} from "@gnu-taler/taler-util";
import {
checkSuccessResponseOrThrow,
createPlatformHttpLib,
HttpRequestLibrary,
readSuccessResponseJsonOrThrow,
@ -97,6 +98,9 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
.property("taler_withdraw_uri", codecForString())
.build("WithdrawalOperationInfo");
/**
* @deprecated Use BankAccessApiClient or WireGatewayApi
*/
export namespace BankApi {
// FIXME: Move to BankAccessApi?!
export async function registerAccount(
@ -142,37 +146,6 @@ export namespace BankApi {
return await registerAccount(bank, username, password);
}
export async function adminAddIncoming(
bank: BankServiceHandle,
params: {
exchangeBankAccount: HarnessExchangeBankAccount;
amount: string;
reservePub: string;
debitAccountPayto: string;
},
) {
let url = new URL(
`taler-wire-gateway/${params.exchangeBankAccount.accountName}/admin/add-incoming`,
bank.bankAccessApiBaseUrl,
);
await bank.http.postJson(
url.href,
{
amount: params.amount,
reserve_pub: params.reservePub,
debit_account: params.debitAccountPayto,
},
{
headers: {
Authorization: makeBasicAuthHeader(
params.exchangeBankAccount.accountName,
params.exchangeBankAccount.accountPassword,
),
},
},
);
}
export async function confirmWithdrawalOperation(
bank: BankServiceHandle,
bankUser: BankUser,
@ -227,6 +200,9 @@ export namespace BankApi {
}
}
/**
* @deprecated use BankAccessApiClient
*/
export namespace BankAccessApi {
export async function getAccountBalance(
bank: BankServiceHandle,
@ -288,6 +264,45 @@ export interface BankAccessApiCreateTransactionRequest {
paytoUri: string;
}
export class WireGatewayApiClientArgs {
accountName: string;
accountPassword: string;
wireGatewayApiBaseUrl: string;
}
export class WireGatewayApiClient {
httpLib = createPlatformHttpLib();
constructor(private args: WireGatewayApiClientArgs) {}
async adminAddIncoming(params: {
amount: string;
reservePub: string;
debitAccountPayto: string;
}): Promise<void> {
let url = new URL(
`admin/add-incoming`,
this.args.wireGatewayApiBaseUrl,
);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",
body: {
amount: params.amount,
reserve_pub: params.reservePub,
debit_account: params.debitAccountPayto,
},
headers: {
Authorization: makeBasicAuthHeader(
this.args.accountName,
this.args.accountPassword,
),
},
});
logger.info(`add-incoming response status: ${resp.status}`);
await checkSuccessResponseOrThrow(resp);
}
}
export class BankAccessApiClient {
httpLib = createPlatformHttpLib();