commit 9d2d254e7d0bbfc6112544ea3079621cb6d7a647
parent 12bec720a24426658e6daee9dee3196946c09c34
Author: Florian Dold <florian@dold.me>
Date: Mon, 28 Oct 2024 12:18:01 +0100
harness: fix wallet-balance test by using updated merchant API
Diffstat:
2 files changed, 171 insertions(+), 16 deletions(-)
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
@@ -1387,6 +1387,18 @@ export class ExchangeService implements ExchangeServiceInterface {
}
/**
+ * Directly enable an account.
+ */
+ async enableAccount(paytoUri: string): Promise<void> {
+ await runCommand(
+ this.globalState,
+ "exchange-offline",
+ "taler-exchange-offline",
+ ["-c", this.configFilename, "enable-account", paytoUri, "upload"],
+ );
+ }
+
+ /**
* Update keys signing the keys generated by the security module
* with the offline signing key.
*/
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts
@@ -20,16 +20,167 @@
import {
Amounts,
Duration,
+ j2s,
MerchantApiClient,
PreparePayResultType,
+ TalerCorebankApiClient,
TalerMerchantApi,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { GlobalTestState } from "../harness/harness.js";
+import { defaultCoinConfig } from "../harness/denomStructures.js";
import {
- createSimpleTestkudosEnvironmentV3,
+ createWalletDaemonWithClient,
withdrawViaBankV3,
} from "../harness/environments.js";
+import {
+ BankService,
+ DbInfo,
+ ExchangeService,
+ FakebankService,
+ getTestHarnessPaytoForLabel,
+ GlobalTestState,
+ HarnessExchangeBankAccount,
+ MerchantService,
+ setupDb,
+ WalletClient,
+ WalletService,
+} from "../harness/harness.js";
+
+interface MyTestEnvironment {
+ commonDb: DbInfo;
+ bank: BankService;
+ bankClient: TalerCorebankApiClient;
+ exchange: ExchangeService;
+ exchangeBankAccount: HarnessExchangeBankAccount;
+ merchant: MerchantService;
+ walletClient: WalletClient;
+ walletService: WalletService;
+}
+
+async function createMyEnvironment(
+ t: GlobalTestState,
+): Promise<MyTestEnvironment> {
+ const db = await setupDb(t);
+
+ const db2 = await setupDb(t, {
+ nameSuffix: "dbtwo",
+ });
+
+ const bc = {
+ allowRegistrations: true,
+ currency: "TESTKUDOS",
+ database: db.connStr,
+ httpPort: 8082,
+ };
+
+ const bank: BankService = await FakebankService.create(t, bc);
+
+ const exchange = ExchangeService.create(t, {
+ name: "testexchange-1",
+ currency: "TESTKUDOS",
+ httpPort: 8081,
+ database: db.connStr,
+ });
+
+ const merchant = await MerchantService.create(t, {
+ name: "testmerchant-1",
+ currency: "TESTKUDOS",
+ httpPort: 8083,
+ database: db.connStr,
+ });
+
+ const receiverName = "Exchange";
+ const exchangeBankUsername = "exchange";
+ const exchangeBankPassword = "mypw-password";
+ const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername);
+ const wireGatewayApiBaseUrl = new URL(
+ `accounts/${exchangeBankUsername}/taler-wire-gateway/`,
+ bank.corebankApiBaseUrl,
+ ).href;
+
+ const exchangeBankAccount: HarnessExchangeBankAccount = {
+ wireGatewayApiBaseUrl,
+ accountName: exchangeBankUsername,
+ accountPassword: exchangeBankPassword,
+ accountPaytoUri: exchangePaytoUri,
+ };
+
+ await exchange.addBankAccount("1", exchangeBankAccount);
+
+ bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
+
+ await bank.start();
+
+ await bank.pingUntilAvailable();
+
+ const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, {
+ auth: {
+ username: "admin",
+ password: "admin-password",
+ },
+ });
+
+ await bankClient.registerAccountExtended({
+ name: receiverName,
+ password: exchangeBankPassword,
+ username: exchangeBankUsername,
+ is_taler_exchange: true,
+ payto_uri: exchangePaytoUri,
+ });
+
+ exchange.addOfferedCoins(defaultCoinConfig);
+
+ await exchange.start();
+
+ const exchange2 = ExchangeService.create(t, {
+ currency: "TESTKUDOS",
+ database: db2.connStr,
+ httpPort: 9080,
+ name: "exchangetwo",
+ });
+
+ exchange2.addOfferedCoins(defaultCoinConfig);
+
+ await exchange.enableAccount("payto://void/foo");
+
+ await exchange2.start();
+
+ merchant.addExchange(exchange);
+ merchant.addExchange(exchange2);
+ await merchant.start();
+ await merchant.pingUntilAvailable();
+
+ await merchant.addInstanceWithWireAccount({
+ id: "default",
+ name: "Default Instance",
+ //paytoUris: [getTestHarnessPaytoForLabel("merchant-default")],
+ paytoUris: [`payto://void/merchant-default`],
+ defaultWireTransferDelay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 1 }),
+ ),
+ });
+
+ const { walletClient, walletService } = await createWalletDaemonWithClient(
+ t,
+ {
+ name: "wallet",
+ persistent: true,
+ },
+ );
+
+ console.log("setup done!");
+
+ return {
+ commonDb: db,
+ exchange,
+ merchant,
+ walletClient,
+ walletService,
+ bank,
+ bankClient,
+ exchangeBankAccount,
+ };
+}
/**
* Test wallet:
@@ -42,21 +193,10 @@ import {
export async function runWalletBalanceTest(t: GlobalTestState) {
// Set up test environment
- const { merchant, walletClient, exchange, bankClient } =
- await createSimpleTestkudosEnvironmentV3(t);
-
- await merchant.addInstanceWithWireAccount({
- id: "myinst",
- name: "My Instance",
- paytoUris: ["payto://void/foo"],
- defaultWireTransferDelay: Duration.toTalerProtocolDuration(
- Duration.fromSpec({ minutes: 1 }),
- ),
- });
+ const { merchant, walletClient, exchange, bankClient, bank } =
+ await createMyEnvironment(t);
- const merchantClient = new MerchantApiClient(
- merchant.makeInstanceBaseUrl("myinst"),
- );
+ const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet.
@@ -81,6 +221,7 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
const orderResp = await merchantClient.createOrder({
order,
+ payment_target: "void",
});
console.log("created order with merchant");
@@ -102,6 +243,8 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
},
);
+ console.log(j2s(preparePayResult));
+
t.assertTrue(
preparePayResult.status === PreparePayResultType.InsufficientBalance,
);